【发布时间】:2012-09-17 07:14:34
【问题描述】:
我正在使用 cakephp 2.2
我将路由器配置为具有漂亮的 url
html链接没有改变停留在第一个结果上
下面的代码可以正常工作,做我想做的事,但我正在尝试使用 cakes 方式生成链接
<td><a href="/<?php echo $examples['somemodel']['slug'];?>"><?php echo $examples['somemodel'][slug'];?> </a></td>
当我这样做时,网址名称不同 但超链接没有改变
<?php echo
$this->Html->link($examples['model']['somename'], '/controllername/slug/' + $examples['model']['slug']);
?>
我的结果是
<a href =”/example1”>example1 </a>
<a href =”/example1 ”>example2 </a>
<a href =”/example1 ”>example3 </a>
<a href =”/example1”>example4 </a>
而不是我想要它做的事情
<a href =”/example1”>example1 </a>
<a href =”/example2”>example2 </a>
<a href =”/example3”>example3 </a>
如您所见,网址名称不同 但超链接没有改变
//路由器.php 路由器::连接(
"/example/:slug",
array('controller' => 'differentname', 'action' => 'view'),
array(
'name'=>'[-A-Z0-9]+',
'pass' => array('slug')
)
);
Router::connectNamed(
array('/example/' => array('action' => 'view', 'controller' => 'different')),
array('default' => true, 'greedy' => true)
);
//'view.ctp
<?php
foreach ($example as $examples): ?>
<?php echo
$this->Html->link($examples['model']['somename'], '/controllername/slug/' + $examples['model']['slug']);
?>
结果 示例1 示例2 示例3 例子4
而不是
<a href =”/example1”>example1 </a>
<a href =”/example2”>example2 </a>
<a href =”/example3”>example3 </a>
我错过了什么或没有到达这里
【问题讨论】:
标签: php cakephp hyperlink routes