controller
implements a MVC controller class. This is where the majority of your code that responds to the requests coming into your iPinga web application will be stored. Typically, you would create one method to handle each request. A request is nothing more than the URL the user went to. ie: http://example.com/user/get/1 might be the request that your application needs to respond to. In this example, this would typically invoke the user
controller’s get
method and pass as the first parameter the value 1
. But, how you setup your routes
is really up to you.
In your controller, you should handle any business logic and then create an array of values (sometimes referred to as a model
) and pass that to the template
object to render for your web application user.
All controllers
should extend the controller
class and must be stored in the filesystem folder defined in the path.controlllers
setting. All controllers should be named in the format of file.controller.php where “file” is the first part of the class name. Class names should be in the format of “fileController” and must extend the \ipinga\controller
class. All controllers must implement a index
method even if you don’t intend to use it in your code.
Example: …\public_html\controllers\index.controller.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<?php Class indexController extends \ipinga\controller { public function index() { echo 'Hello World!'; } public function sample() { $this->template->somekey = 'Whatever you want here'; // this makes $somekey available inside the template itself $this->template->show('my_view'); // .../public_html/views/my_view.view.php } public function withparams( $a, $b ) { echo '$a = '. $a. '<br/>'; echo '$b = '. $b. '<br/>'; } } ?> |
…/public_html/index.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<?php $iPinga = new \ipinga\ipinga(); $iPinga->addRoute('mytest/$1/$2','index','withparams'); $iPinga->run(); ?> Output: If the user goes to http://example.com/mytest/Vern/Six, your controller (above) would output $a = Vern $b = Six |
Parent Class
None
Public Properties
template
object, used to work with your view.Data Type: \ipinga\template
Default Value: Empty
Public Methods
None