2012-09-25 63 views
1

以下代碼的工作和我想要做什麼,但我想使用生成的鏈接蛋糕的方式

<td><a href="/<?php echo $examples['somemodel']['slug'];?>"><?php echo $examples['somemodel'][slug'];?> </a></td> 

當我這樣做的URL名稱不同 ,但超鏈接不改變

<?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> 

正如你所看到的網址名稱不同 但超鏈接不變

//router.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> 

缺少什麼我還是在這裏沒有得到

回答

1

也許是因爲使用'+'作爲文本附加操作符。你需要使用'。'代替。

例子:

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

+0

謝謝你的工作。在本書中,它引用了這個<?php $ this-> Html-> link('View','/ posts/view /'+ $ id);我想我想念它 – user1698137

+0

不客氣。如果沒有問題,請記住標記爲答案。 – t3b4n

+0

對於愚蠢的問題感到抱歉如何將它標記爲答案?我嘗試點擊答案按鈕,但它說沒有足夠的代表這樣做呢 – user1698137

相關問題