0

如何使用HtmlHelperCakePHP 2.2.1 中的类轻松生成 HTML 链接?

想象一下,我声明了一个路由/finest-perfumes-ever-2012Perfumes/IndexController/Action 的路由。

我需要这个生成的链接是:

somedomain.com/finest-perfumes-ever-2012  //Generate link HAS to obey Routes I've set.

代替:

somedomain.com/Perfumes/Index

文档似乎并没有很好地解释如何实现这一目标。

4

2 回答 2

1

不确定您是否2012偶然错过了,或者您的问题比我下面的回答更复杂。假设2012没关系:

Cake 使用了一个相当不错的特性——反向路由

如果您已正确设置所有内容,则以下内容应输出您想要的内容。

<?php
Router::connect(
    '/finest-perfumes-ever',
    array('controller' => 'perfumes', 'action' => 'index')
);

echo $this->Html->link('View Finest Perfumes!', array('controller'=>'perfumes', 
                                                         'action' => 'index')); 

提供您的 URL(使用 HTML 帮助程序创建时)具有与路由完全匹配的参数,反向路由将查找您想要的路由,并相应地输出链接。

如果这2012很重要,您可能可以通过传递参数来实现它 - 这里有一些示例

于 2012-07-22T15:08:50.423 回答
0

Define route configuration into your app/Config/routes.php at the last of all routing statements.

You can do the same by passing an argument to the action and define it in your routes.php file.

Kindly ask if it not worked for you.

于 2012-07-23T06:01:32.367 回答