Reputation: 11
I am using cakephp 2.2
I have routers configured to have pretty urls
html link not changing stuck on first result
the below code works and does what I want, but I am trying to use cakes way of generating links
<td><a href="/<?php echo $examples['somemodel']['slug'];?>"><?php echo $examples['somemodel'][slug'];?> </a></td>
when I do this the url name is different but the hyper link doesn't change
<?php echo
$this->Html->link($examples['model']['somename'], '/controllername/slug/' + $examples['model']['slug']);
?>
my results are
<a href =”/example1”>example1 </a>
<a href =”/example1 ”>example2 </a>
<a href =”/example1 ”>example3 </a>
<a href =”/example1”>example4 </a>
instead of what I want it to do
<a href =”/example1”>example1 </a>
<a href =”/example2”>example2 </a>
<a href =”/example3”>example3 </a>
as you can see the url name is different but the hyper link doesn't change
//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']);
?>
results example1 example2 example3 example4
instead of
<a href =”/example1”>example1 </a>
<a href =”/example2”>example2 </a>
<a href =”/example3”>example3 </a>
What am I missing or not getting here
Upvotes: 1
Views: 290
Reputation: 632
Maybe it's because the use of '+' as a text append operator. You need to use '.' instead.
Example:
$this->Html->link($examples['model']['somename'], '/controllername/slug/'.$examples['model']['slug']);
Upvotes: 1