Controllers and actions
Example controller app/home/controller/index.php:
php
<?php
namespace home\controller;
class index{
function hi(){
echo 'Hi, PhpTide!';
}
}The home\index class is the Index controller in the home module; hi is a public action method.
Visiting http://serverName/index.php/home/index/hi prints:
php
Hi, PhpTide!Defining controllers
Controllers may extend the framework Controller base class. Example:
php
<?php
namespace home\controller;
class index{
function hi(){
echo 'hi';
}
function tide(){
echo 'tide';
}
}Use PascalCase for controller class names. The file lives at home/controller/index.php.
The hi and tide methods are actions. These URLs map to them:
http://serverName/index.php/home/index/hihttp://serverName/index.php/home/index/tide
Outputs:
php
hiphp
tideActions must be public; non-public methods cannot be invoked as actions. In the example below only hi is reachable:
php
<?php
namespace home\controller;
class index{
public function hi(){
echo 'hi';
}
private function tide(){
echo 'tide';
}
}