【问题标题】:cakephp $this->html->link not changing locationcakephp $this->html->链接不改变位置
【发布时间】: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


    【解决方案1】:

    可能是因为使用了“+”作为文本追加操作符。您需要使用“。”而是。

    例子:

    $this-&gt;Html-&gt;link($examples['model']['somename'], '/controllername/slug/'.$examples['model']['slug']);

    【讨论】:

    • 谢谢你的工作。在书中它引用了这个 Html->link('View', '/posts/view/' + $id);我想我想念它
    • 抱歉这个愚蠢的问题我如何将其标记为答案?我试着点击回答按钮,但它说还没有足够的代表来做这个
    猜你喜欢
    • 2012-01-25
    • 1970-01-01
    • 1970-01-01
    • 2011-03-17
    • 2010-12-25
    • 1970-01-01
    • 2017-02-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多