Newbie Coder
Newbie Coder

Reputation: 10942

How to call CSS class on a CakePHP Html->link?

I am a complete noob to programming and CakePHP all together, so please be patient. How am I supposed to call the CSS on this Html->link:

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

Please help.

Upvotes: 11

Views: 27427

Answers (4)

Ho&#224;ng Kim
Ho&#224;ng Kim

Reputation: 11

I think this works:

<?php echo $this->Html->link('Add Task', array('action'=>'add'), array('class' => 'tac')); ?>

Upvotes: -1

Manvendra singh bhati
Manvendra singh bhati

Reputation: 11

Please try this CakePHP 3 in

<?php 
echo  $this->Html->link(__('Blogs'), ['controller' => 'posts', 'action' => 'index'], ['class' => 'mb-xs mt-xs mr-xs btn btn-warning']);
?> 

Upvotes: 1

MasterMind
MasterMind

Reputation: 522

Another Solution will be the inline style :

echo $this->Html->link(__('Blogs', true), array('controller' => 'posts', 'action' => 'index'), array('style' => 'color:red;font-size:20px;'));

Upvotes: 3

Dunhamzzz
Dunhamzzz

Reputation: 14798

Not sure what you mean by "call the css", I think you want to add a class to this link? IF that's the case you can just add another array as an argument and it will turn key =? value into HTML attributes. EG:

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

This is all explained in the CakePHP docs.

Upvotes: 32

Related Questions