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:
It creates a controller file with all the boilerplate code to just write your methods.
So go to :
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:
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:
So lets add a view helper to index method:
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:
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
Was this helpful?