共计 619 个字符,预计需要花费 2 分钟才能阅读完成。
如原始网址为:http://example.com/admin/products/show-latest-products。
例如,您希望将 show-latest-products 指定 ShowLatestProducts 的 action,则需要以下代码
<?php
use Phalcon\Text;
use Phalcon\Mvc\Dispatcher as MvcDispatcher;
use Phalcon\Events\Event;
use Phalcon\Events\Manager as EventsManager;
$di->set(
'dispatcher',
function () {
// Create an EventsManager
$eventsManager = new EventsManager();
// Camelize actions
$eventsManager->attach(
'dispatch:beforeDispatchLoop',
function (Event $event, $dispatcher) {$dispatcher->setActionName(Text::camelize($dispatcher->getActionName())
);
}
);
$dispatcher = new MvcDispatcher();
$dispatcher->setEventsManager($eventsManager);
return $dispatcher;
}
);
正文完