1

Can anyone provide either a method of using the following code that doesn't result in HTML special characters being used in place of the single quotes, or an alternative way to produce the intended result?

<?php echo $this->Html->link(
                         'View', 
                         $row['view'], 
                         $options = array(
                              'onMouseOver'=>'setHelp(\''.$row['id'].'\')'
                               )
                         );
?>

The result looks like:

 <li>
     <a href="--url--" onMouseOver="setHelp(&#039;--js_param--&#039;)">
 </li>

Clearly I am doing this wrong. But the Cake API seems to suggest that HtmlHelper's link() method is the go-to for javascript-ready links. Help?

3
  • Shouldn't it still work though? Commented Dec 22, 2011 at 19:03
  • 2
    ween a framework takes more time to acomplish a task than doing it on rambo's way, something is really wrong... Commented Dec 22, 2011 at 19:06
  • 3
    @Ark what you don't get from the context of the question is that CakePHP has a powerful routing system that one can take advantage of with this syntax. You do not HAVE to use it as a developer if it's quicker to write html (which is probably the case here). But, when you know how to use the framework properly with routes, then this is easy as pie and helps making links to controller actions a snap. Commented Dec 22, 2011 at 20:26

3 Answers 3

2
<?php echo $this->Html->link(
                     'View', 
                     $row['view'], 
                     array(
                          'onMouseOver'=>'setHelp(\''.$row['id'].'\')',
                          'escape' => false
                     )
               );
?>
Sign up to request clarification or add additional context in comments.

Comments

1

I think your code should work, but you can force Cake not to escape the output:

echo $this->Html->link(
  'View', 
  $row['view'],
  array(
    'onMouseOver'=>'alert(\''.$row['id'].'\');',
    'escape' => false
  )
); 

1 Comment

Moz Morris: Thankyou! To the people that suggested regular html: thanks, but I as Scott Harwell noted, there are reasons beyond cake convention to do it this way, and at a later phase in the development will be using an in-house js library wherein this sort of thing is going to be a constant nag.
0

How about using pure html?

   <li>
     <a></a>
  </li>

They really do suggest use always if possible cake tags and all(following the conventions), but sometimes is not wrong to use common html to surpass a prob...

1 Comment

The other two answers (which are the same) would achieve what you are trying to do within the scope of the question (and CakePHP). If you are doing any kind of routing in your App, use it. The "escape" parameter is well documented and is the fix to your issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.