The Yaf_Controller_Abstract class

(Yaf >=1.0.0)

Introduction

Yaf_Controller_Abstract is the heart of Yaf's system. MVC stands for Model-View-Controller and is a design pattern targeted at separating application logic from display logic.

Every custom controller shall inherit Yaf_Controller_Abstract.

You will find that you can not define __construct function for your custom controller, thus, Yaf_Controller_Abstract provides a magic method: Yaf_Controller_Abstract::init().

If you have defined a init() method in your custom controller, it will be called as long as the controller was instantiated.

Action may have arguments, when a request coming, if there are the same name variable in the request parameters(see Yaf_Request_Abstract::getParam()) after routed, Yaf will pass them to the action method (see Yaf_Action_Abstract::execute()).

Note:

These arguments are directly fetched without filtering, it should be carefully processed before use them.

Class synopsis

abstractclassYaf_Controller_Abstract {
public$actions;
protected$_module;
protected$_name;
protected$_request;
protected$_response;
protected$_invoke_args;
protected$_view;
finalprivate__construct()
protecteddisplay(string$tpl, array$parameters = ?): bool
publicforward(string$action, array$paramters = ?): bool
publicgetInvokeArg(string$name): void
publicgetName(): string
publicinit(): void
publicinitView(array$options = ?): void
publicredirect(string$url): bool
protectedrender(string$tpl, array$parameters = ?): string
publicsetViewpath(string$view_directory): void
}

Properties

actions

You can also define an action method in a separate PHP script by using this property and Yaf_Action_Abstract.

Example #1 define action in a separate file

<?php
class IndexController extends Yaf_Controller_Abstract {
protected
$actions = array(

"dummy" => "actions/Dummy_action.php",
);


public function indexAction($name, $id) {

assert($name == $this->getRequest()->getParam("name"));
assert($id == $this->_request->getParam("id"));
}
}
?>

Example #2 Dummy_action.php

<?php
class DummyAction extends Yaf_Action_Abstract {

public function execute() {
}
}
?>
_module

module name

_name

controller name

_request

current request object

_response

current response object

_invoke_args

_view

view engine object

Table of Contents

To Top