Controllers

Control every request, process data and return views with data to show.

Create a controller with BoosterCLI

PHP Booster have a very useful CLI tool to create a file in the path that it is necessary to be and with conventions that promote, so in location of your project directory, open your console/cmd/poweshell/gitbash or any other console tool, and write:

$ php BoosterCLI make:controller "TheNameOfYourController"

It creates a controller file with all the boilerplate code to just write your methods.

So go to :

app/controllers/

And you will find your Controller file with some Conventions, its not necessary but its strongly recommended to add the prefix "Controller" to all the controllers files, but again its not obligatory.

You will find a file like this:

<?php
use Libs\BoosterORM\BoosterORM;
class Users
{
    public function index()
    {

    }

    public function create()
    {

    }

    public function store()
    {

    }

    public function search()
    { 

        //access to search with $_REQUEST['search']
        //example of query:  where column = 1 AND otherColumn LIKE '%$_REQUEST['search']%'
        //for filter more where (column = 1 AND otherColumn LIKE '%$_REQUEST['search']%') OR (column = 1 AND otherOneColumn LIKE '%$_REQUEST['search']%')
    }

    public function edit($id=null)
    {

    }

    public function update($id=null)
    {

    }

    public function show($id=null)
    {

    }

    public function destroy($id=null)
    {
    
    }

}
?>

That is the boilerplate so just add your code to execute in any route that match with it, for example I am going to set a index view in users folder inside Views folder to return the a view when someone go to:

www.localhost/your-project/users

So lets add a view helper to index method:

<?php
use Libs\BoosterORM\BoosterORM;
class Users
{
    public function index()
    {
        return view('modules.users.index');
    }

view() helper use params string that represent the directory inside Views folder, so you could create your own folders or stay using modules and subfolders as a convention like I did.

Now if you go to:

www.localhost/your-project/users

There is going to display screen error because we return a view that does not exist already, so we are going to create it in Views section.

Last updated