Phalcon\Mvc\User\Logic
拥有方法:getActionName($params = NULL)
、getActionParams($params = NULL)
、setContent($content)
、getContent()
以及静态方法:call($actonName = NULL, $actionParams = NULL)
通过设定 $dispatcher->setLogicBinding(true);
既可以通过设置控制方法的参数来实例化逻辑类。
class LogicController extends Phalcon\Mvc\Controller
{
public function indexAction(\MyLogic $logic)
{
return $logic;
}
}
class MyLogic extends Phalcon\Mvc\User\Logic
{
public $num = 0;
// 覆盖方法 call
public static function call($action = NULL, $params = NULL)
{
$logic = new MyLogic($action, $params);
$logic->num = 1;
return $logic;
}
}
$di = new \Phalcon\DI();
$dispatcher = new \Phalcon\Mvc\Dispatcher();
$dispatcher->setDI($di);
$dispatcher->setLogicBinding(true);
$dispatcher->setControllerName('Logic');
$dispatcher->setActionName('index');
$dispatcher->dispatch();
$logic = $dispatcher->getReturnedValue();