将url参数传递给主页


cakepassing url params to the homepage

我试图建立一个链接到我的主页,其中包括一个参数在url

我尝试的方式是

echo '<a href="'.$this->webroot.'cat:garden'">Garden</a>';

但是如果我这样做,我得到一个错误"你没有权限访问请求的对象。"

我知道我能做到

echo '<a href="'.$this->webroot.'pages/home/cat:garden'">Garden</a>';
包含"pages/home"的

,但当您将鼠标悬停在链接或访问页面时,它看起来不那么好。如果只是www.whatever.com/cat:garden

就更好了

任何想法?

用CakePHP的方式做-

In your view:

echo $this->Html->link('Garden', array(
    'controller' => 'pages',
    'action' => 'home',
    $value)
);

将生成www.example.com/pages/home/garden

现在的魔法路由器

在你的routes.php:

将这些行添加到routes.php文件的中间-

Router::connect('/pages/home/*', array(
    'controller' => 'pages',
    'action' => 'home')
);

添加新路由后,刷新页面。现在$this->Html->链接将生成www.example.com/garden