1

私はcakephp 2.2を使用しています

かわいいURLを持つようにルーターを構成しています

html リンクが変更されず、最初の結果で動かなくなる

以下のコードは機能し、私が望むことを行いますが、リンクを生成する方法を使用しようとしています

<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”&gt;example1 </a> 
<a href =”/example1 ”&gt;example2 </a> 
<a href =”/example1 ”&gt;example3 </a> 
<a href =”/example1”&gt;example4 </a> 

私がやりたいことの代わりに

<a href =”/example1”&gt;example1 </a> 
<a href =”/example2”&gt;example2 </a> 
<a href =”/example3”&gt;example3 </a> 

ご覧のとおり、URL 名は異なりますが、ハイパーリンクは変わりません

//router.php Router::connect(

"/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']);
 ?>

結果 example1 example2 example3 example4

それ以外の

   <a href =”/example1”&gt;example1 </a> 
 <a href =”/example2”&gt;example2 </a> 
<a href =”/example3”&gt;example3 </a> 

私が見逃しているもの、またはここに到達していないもの

4

1 に答える 1

1

おそらく、テキスト追加演算子として「+」を使用しているためです。「.」を使用する必要があります。代わりは。

例:

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

于 2012-09-25T21:02:43.100 に答える