【发布时间】:2013-02-05 12:23:24
【问题描述】:
如何创建一个可以使用像 Facebook 这样的 URL 的应用程序?
- app.dev/用户名
- app.dev/用户名/图片
- app.dev/用户名/信息
- app.dev/username/posts/post_333
- app.dev/username/posts/post_333/share
应用程序有其他具有不同 URL 的控制器
- app.dev/events
- app.dev/site/contact
- app.dev/site/terms
当控制器不存在时,重定向到配置文件控制器
在 application.ini 中
autoloaderNamespaces[] = "Plugins"
resources.frontController.plugins[] = "Plugins_Profiles"
在 Bootstrap.php 中
protected function _initProfiles()
{
$front = Zend_Controller_Front::getInstance();
$front->registerPlugin(new Plugins_Profiles());
}
在 /library/Plugin/Profiles.php 中
class Plugins_Profiles extends Zend_Controller_Plugin_Abstract
{
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
$dispatcher = Zend_Controller_Front::getInstance()->getDispatcher();
if (!$dispatcher->isDispatchable($request)) {
$url = $request->getControllerName();
$request->setModuleName('default');
$request->setControllerName('profiles');
$request->setActionName('url');
$request->setParam('url', $url);
/** Prevents infinite loop if you make a mistake in the new request **/
if ($dispatcher->isDispatchable($request)) {
$request->setDispatched(false);
}
}
}
}
但是我不能发送变量 例如:app.dev/username/posts/post_333/share
知道我应该如何进行吗?
PS。抱歉语法问题,我是巴西人,我会说葡萄牙语。
【问题讨论】:
标签: zend-framework redirect friendly-url restful-url