Pause for thought

That was a LOT of stuff very quickly. Let's take a breath and go back through some parts.

Escaping

If you've done web dev for more than a couple of months, you'll be concerned about sanitising outputs. After all, no-one wants to be the victim of an XSS (Cross-Site Scripting) attack, or SQL injection. Li3 does a lot to protect you from that. The <?= ?> output? That isn't just the regular PHP shorttag echo. That's actually a thing that the template engine in Li3 looks for and anything output through there is escaped. Now, there's more to learn about that but for now, this will suffice.

For more info, see the Li3 manual's section on auto-escaping.

About the controller

The controller at app/controllers/EmployeesController.php is pretty much the same as what was generated by li3, except we hacked it about slightly to get the routes working properly. Let's look at its methods.

Index

<?php
    // ...
    public function index() {
        $employees = Employees::all();
        return compact('Employees');
    }
    // ...

This pulls out ALL the Employee. Notice that it uses the Employee model and makes a static method call to all(). If you've tried Doctrine, Hibernate or another ORM (Object-Relational Mapper), you'll be a bit familiar with these concepts. Li3's model is quite straightforward - it's got static methods for all the data retrieval operations.

This particular one pulls out ALL the Employee. It's good enough for a simple system that doesn't require pagination.

The compact function is documented on PHP.Net. A lot of Li3 pros use it to send information to the view. Whatever array a controller returns is sent to the view, and so becomes available to be displayed in the template.

View

<?php
    // ...
    public function view($id) {
        $employee = Employees::first($this->request->id);
        return compact('Employee');
    }
    // ...

This is similar, except a single member of Employees is pulled out by ID. Li3 is smart enough to know the auto incremented primary key field "id" is the one to use. This member of Employees is returned and sent off to the view. We're not going to go into huge detail on the request lifecycle (this is more a "how to" than a "how does..."), but you can read more about this in the Li3 manual section on handling HTTP requests.

Edit

We haven't covered this one, but as an exercise to the reader, I challenge you to implement it! You should have enough information to go on based on what you've already accomplished. You can do it! I believe in you!

Delete

This one would require a delete form. We'll leave it alone for now.

All good?

OK, how are we doing? All caught up and making at least some loose semblance of sense? I hope so! If not, feel free to tinker around. Most of learning Li3 will come from reading the docs, trying things out, and experience. It won't happen overnight but don't worry, it'll come!

Let's crack on and become more pro!