0

I have a problem adding CSS classes to my HTML links in CakePHP: I tried the solution as posted in: How to call CSS class on a CakePHP Html->link?

If I put the links within the oldschool HTML div class 'my-class' it works.

If I use the code from the example it does not work:

echo $this->Html->link(__('Blogs', true), array('controller' => 'posts', 'action' => 'index'), array('class' => 'my-class')); 

What can be the reason for this?

3
  • 1
    Are you including the Html-Helper? Are there any errors? Have you set debug to 2 in core.php? What do you mean by "it does not work"? Only the class or the whole link? Commented Jul 7, 2011 at 7:05
  • works perfectly for me, i've copied your exact code and it outputs <a class="my-class" href="/posts">Blogs</a> you're gonna have to give us more info about your problem Commented Jul 7, 2011 at 10:51
  • Sorry, I cant include a code blok here at stackoverflow....very annoying to include html as your tab key is broken. Anyway, thanks for your help. I checked the output, exactly as it should be, the class is correctly mentioned. Also, the HTML helper is active as I can use other of its functions....only this link.. The link works, only the css style is not there. Commented Jul 7, 2011 at 11:21

1 Answer 1

0

By reading your comments, I understand that the link in outputted correctly, the same for the class. Only that the styles associated with that class are not rendered. Am I right?

If so, have you included the CSS file? You should $this->Html->css('style_name');, where style_name is a CSS file located in app/webroot/css/.

Sign up to request clarification or add additional context in comments.

1 Comment

The problem is not resolved. Sometimes it worked, then after an hour the css was gone. I have stopped using Elements started to implement the MenuBuilder helper. Thanks for all your help

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.