zend-framework - Zend - 从模块/ Controller / View 逻辑生成语音 URL

标签 zend-framework seo routes

使用 Zend,您可以为更好的 URL 添加路由,例如像这样:

$oRouter->addRoute( 'imprintRoute', new Zend_Controller_Router_Route_Static( 'imprint/', array( 'module' => 'default', 'controller' => 'imprint', 'action' => 'index') );

是否有可能以相反的方式获取正确的 URL,例如什么时候在我的模板中使用模块/ Controller / Action 逻辑?

<a href="{$this->url(['module' => 'default', 'controller' => 'imprint', 'action' => 'index'])}">Imprint</a>

应打印为 example.com/imprint/

你有什么想法或例子吗?

亲切的问候, 网扎芬

最佳答案

url() 方法有四个参数:

  • array $urlOptions 传递给 Route 对象的 assemble 方法的选项。
  • mixed $name 要使用的路由名称。如果为空,它将使用当前路线
  • bool $reset 是否使用提供的路由重置默认值
  • bool $encode 是否编码

因此您可以将您的路线名称添加为第二个参数,如下所示:

<a href="{$this->url(['module' => 'default', 'controller' => 'imprint', 'action' => 'index'], 'imprintRoute', true)}">Imprint</a>

关于zend-framework - Zend - 从模块/ Controller / View 逻辑生成语音 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10092232/

相关文章:

php - Zend 框架操作堆栈替代方案

php - Zend Framework - 直接使用 SQL

php - 如何更改 PHP azure 网站的根目录?

javascript - JSONP 与 IFrame?

c# - 与 url 不同的操作名称

php - 方法 "getParam"不存在并且没有被困在 __call()

url - 如何重写具有多个参数的 URL

ruby-on-rails - 过滤中的查询字符串或绑定(bind)参数

iphone - 有离线 OpenStreetMaps 路线的解决方案吗?

linux - 如何在 proxmox 中为容器进行端口路由?