本文整理匯總了PHP中Phalcon\Mvc\Dispatcher::setModelBinding方法的典型用法代碼示例。如果您正苦於以下問題:PHP Dispatcher::setModelBinding方法的具體用法?PHP Dispatcher::setModelBinding怎麽用?PHP Dispatcher::setModelBinding使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Phalcon\Mvc\Dispatcher
的用法示例。
在下文中一共展示了Dispatcher::setModelBinding方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: boot
public function boot(Container $container)
{
// As of phalcon 3, definition will bind to di by default
$container->setShared('dispatcher', function () {
$eventsManager = $this->getShared('eventsManager');
$eventsManager->attach('dispatch', new \Pails\Plugins\CustomRender());
$dispatcher = new PhalconDispatcher();
$dispatcher->setEventsManager($eventsManager);
$dispatcher->setDefaultNamespace('App\\Controllers');
$dispatcher->setModelBinding(true);
return $dispatcher;
});
}
示例2: testModelBinding
public function testModelBinding(IntegrationTester $I)
{
$dispatcher = new Dispatcher();
$dispatcher->setModelBinding(true);
$dispatcher->setDI(Di::getDefault());
$I->assertInstanceOf('Phalcon\\Di', $dispatcher->getDI());
$I->haveServiceInDi('dispatcher', $dispatcher);
// Model to test with
$model = People::findFirst();
$dispatcher->setControllerName('test10');
$dispatcher->setActionName('view');
$dispatcher->setParams([$model->cedula]);
$dispatcher->dispatch();
$I->assertInstanceOf('Phalcon\\Test\\Models\\People', $dispatcher->getReturnedValue());
$I->assertEquals($model->cedula, $dispatcher->getReturnedValue()->cedula);
// Reset dispatcher
$dispatcher = new Dispatcher();
$dispatcher->setDI(Di::getDefault());
$I->assertInstanceOf('Phalcon\\Di', $dispatcher->getDI());
$I->haveServiceInDi('dispatcher', $dispatcher);
$dispatcher->setControllerName('test9');
$dispatcher->setActionName('view');
$dispatcher->setParams([$model->cedula]);
try {
$dispatcher->dispatch();
$I->assertTrue(false, 'Here must be the exception about passing non model to the controller action');
} catch (\Exception $e) {
// PHP 5.x
$I->assertEquals('Argument 1 passed to Test9Controller::viewAction() must be an instance of Phalcon\\Mvc\\Model, string given', $e->getMessage());
} catch (\TypeError $e) {
// PHP 7.x
$I->assertEquals('Argument 1 passed to Test9Controller::viewAction() must be an instance of Phalcon\\Mvc\\Model, string given', $e->getMessage());
}
$dispatcher->setModelBinding(true);
$dispatcher->dispatch();
$I->assertInstanceOf('Phalcon\\Test\\Models\\People', $dispatcher->getReturnedValue());
$I->assertEquals($dispatcher->getReturnedValue()->cedula, $model->cedula);
}