Controller - notihnio/mgr GitHub Wiki

A controller class exnteds \Mgr\Controller\Controller and sould be declaread as the example:

class ArticlesController extends \Mgr\Controller\Controller {}

A full examaple in :

https://github.com/notihnio/mgr-example-application/blob/master/Application/Module/Index/Controller/ArticlesController.php

To declare an action in a controller should be provided the name of the action (with the first letter Uppercase) with the keyword 'Action'

ex public function IndexAction()

Built in methods and properties

Every Controller class is provided with some built in methods and properties.

View

The view property is a viewObject instance than handles and finally renders the action view. Every action must have its own view php file, stored in /Application/Module/{Module Name}/View/{Controller Name}/{Action Name}.php directory.

To pass values from controller to view just assign properties to the view object.

e.x. in every action function:
$this->view->{Variable name} = {Variable Value}

on the view php file we can access that value with

$this->{Variable name} = {Variable Value}

Layout

If you want to use some templating logic you should use layouts. Layouts stored on the /Application/Module/{Module Name}/Layout/{Layout Name}.php and can be used on any controller or on any action. You can use layouts through layout object.

First you need to init the layout

e.x. in every action function:
$this->layout->__Name = {Layout Name}

if you want to pass some extra variables to a layout, just pass more attributes to the layout object.

e.x. $this->layout->{Attribute Name} = {Attibute Value}

you can access this property in the layout file:

e.x. $this->{Attribute Name}

####selectedRoute

In every controller you have access to the selected route from router via the selectedRoute property

$this->selectedRoute = array("controller" => "controllerName", "module" => "moduleName", "action"=>"actionName", "params"=>array())

####params

Params attribute returns an array with the selected route params array

####postParams

postParams attribute returns the post request parameters

####getParams

getParams attribute returns the get request parameters