Controllers

You can create a new controller with the Walrus CLI, or create it yourself using this basic syntax:


    namespace engine\controllers;

    use Walrus\core\WalrusController;

    class TestController extends WalrusController
    {

        public function run()
        {
            echo 'Hello World';
        }
    }
Set view

The set view function let you specify a template to load.

    public function run()
    {
        $this->setView('helloview');
        $this->setView('otherfolder/helloview');
    }
  • Line 3: load the view in www/templates/hello/helloview.?
  • Line 4: load the view in www/templates/otherfolder/helloview.?

You can also specified an ACL to a template:

    public function run()
    {
        $this->setView('helloview', 'admin');
    }
Skeleton

You can add a skeleton by using the following method, for more info about skeleton see Skeleton

    public function run()
    {
        $this->skeleton('some_skeleton');
    }
Register variables

To add a variable from your controller to your template, just use the register method, the variable can then been used in all included template.

    public function run()
    {
        $this->register('post', $_POST);
    }
Call a method from an other controller

To call a method from an other controller, use the controller method:

    public function run()
    {
        $this->controller('test')->methodOfTestController();
    }

The controller method return the controller class so you can directly call method from it

Call a method from a model

To call a mehtod from a model, use the model method:

    public function run()
    {
        $this->model('test')->methodOfTestModel();
    }

The model method return the model class so you can directly call method from it

Redirect

If you want to redirect your controller to an other web page, simply use the go method

    public function run()
    {
        $this->go('http://url-to-redirect.com');
    }
Reroute

Walrus provide a reroute method, everything on your controller after a reroute will not be executed. Reroute use a light routing version of Walrus to be processed really quickly

    public function run()
    {
        $this->reroute('controller', 'action', array('param' => 'hello'));
    }
Get (Hard)

The get hard method give you the content of a specified url (curl style)

    public function run()
    {
        $this->getHard('http://website-to-get-content.com');
    }
Get (Soft)

The get soft method is a unique method from Walrus framework, this method allow you to get the rendered content of a controller's action, it use the same light rerouting as the reroute method and catch all the front end rendering as a string, every interaction with the controller like setting view or registering variable are instantiated for a full compatibility between controllers.

    public function run()
    {
        $content = $this->getSoft('controller', 'action', array('hello' => $hello));
    }