I need to generate html tags like the below .. to be precise, i need to add a class to the anchor tag added to the list, but i dnt seem to get it to work ..
<li class="myLIPrevclass"></li>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li class="myLINextclass"></li>
The challenge is,
i cant seem to get a class across to the a tag in the next and the previous, i need to solve this
Even if i leave the a tag blank for the previous and next, CakePHP goes ahead and adds a '>' or '<' which in my case I do not need.
This is what I have tried ..
<?php
echo $this->Paginator->prev(
__(''),
array(
'tag' => 'li',
'class' => 'previous',
),
__(''),
array(
'tag' => 'li',
'class' => ''
)
);
echo $this->Paginator->numbers(
array(
'separator' => '',
'tag' => 'li',
'currentClass' => 'active',
'currentTag' => 'a'
)
);
echo $this->Paginator->next(
__(''),
array(
'tag' => 'li',
'class' => 'next',
),
__(''),
array(
'tag' => 'li',
'class' => ''
)
);
?>
For the disabled titles (for both previous and next) even if i pass in null, Cake add a '>' or '<', and I don't want that
I have checked
Creating Pagination With CakePHP For Custom Template Links
and
Add class to pagination links at CakePHP 2.2
My Cake Version is 2.4.x
I'll appreciate any pointers or help ..
Thanks
Related
I have the following link to generate the following link with helpers:
<a href="/rooms" class="ln-room">
<span class="room-icon cls-icon"></span>
<span class="lable">rooms</span>
</a>
I cannot supply the span tags inside $combine, as HtmlHelper::link() calls htmlspecialchars_decode(), thus converting all html to characters.
echo $this->Html->link($combine, array(
'controller' => 'rooms',
'action' => 'index'
),
array('class' => 'ln-room')
);
If the only way is to create a custom helper, how can it be done?
echo $this->Html->link($combine, array(
'controller' => 'rooms',
'action' => 'index'
),
array(
'class' => 'ln-room',
'escape' => false // <--- THIS
)
);
In Cake, we can add url in image() like this:
$this->Html->image('image src...', array('url' => 'some address...');
and output is:
<img src="image src..." />.
How to add class and others attributes to a tag?
echo $this->Html->link(
$this->Html->image($imageSrc, array(
'class'=>'class_of_image',
'height' => '50',
'width' => '100',
'alt' => 'awesome close-up of me eating pizza'
)),
array(
'controller' => 'your_controller',
'action' => 'the_action'
),
array(
'class' => 'class_of_anchor',
'escape' => false //to allow the image tag within the link
)
);
Feel free to make any/all parts of this into a single line - but for StackOverflow reasons, it's easier to read like this.
echo $this->Html->link(
'more',
array(
'controller'=>'posts',
'action'=>'view',
$post['Post']['id']
)
);
How can I assign an id and class for this anchor/link? I want to override its css rule.
HTML attributes can be specified in an array as the third parameter.
echo $this->Html->link(
'more',
array(
'controller'=>'posts',
'action'=>'view',
$post['Post']['id']
),
array(
'id' => 'myId',
'class' => 'myClass'
)
);
More info in the Cookbook 2.x for the 2.x version or Cookbook 1.3 for CakePHP 1.3.
I have two models, Category and Point. The associations are defined as:
Category hasMany Point
Point belongsTo Category
I would like, when adding Points to my database, to be able to select the category it belongs to from a <select> box, along with the rest of the form data.
Where would I need to set the category list and how could I do it? And how would I produce the select box?
I assume it could be done with
$form->input('categorieslist',array('type'=>'select')); //categorieslist needs
//setting somewhere.
Also to generalize a bit:
In a View with access to the Form helper
<?php
echo $form->input( 'dataKey', array(
'type' => 'select',
'options' => array(
'key1' => 'val1',
'key2' => 'val2',
),
));
?>
The above will render a select input with two options. You can also place an empty option as the first item. Passing a value of true will simply append an empty option with a blank value to the beginning of the options rendered in the HTML.
<?php
echo $form->input( 'dataKey', array(
'type' => 'select',
'options' => array(
'key1' => 'val1',
'key2' => 'val2',
),
'empty' => true,
));
?>
You can pass a string to the 'empty' key to have it display custom text as the key field for the empty option.
<?php
echo $form->input( 'dataKey', array(
'type' => 'select',
'options' => array(
'California' => 'CA',
'Oregon' => 'OR',
),
'empty' => 'choose a state',
));
?>
One last example, you can also pre-select an option with the selected key. The value should match the value of one of the select options, not the key.
<?php
echo $form->input( 'dataKey', array(
'type' => 'select',
'options' => array(
'California' => 'CA',
'Oregon' => 'OR',
),
'empty' => 'choose a state',
'selected' => 'California',
));
?>
From the Model
Model->find( 'list', array( ... )); will always return an array formatted for use with select box options. If you pass data to your view stored in a variable with a lowercase plural model name, that is, ( $this->set( 'categories', $categories );, then you will automagically generate drop downs for related models by using the form helper in the view and passing it a data index of the same model name in singular form suffixed with "_id".
Aziz's answer at #2 is the example of that automagic kicking in.
CakePHP 1.3 Form Helper
CakePHP1.2 Form Helper
In the controller:
$categories = $this->Point->Category->find('list');
$this->set(compact('categories'));
In the view:
$form->input('category_id',array('type'=>'select'));
How do you style the paginator with CSS used in CakePHP?
I can't find a way to attach a CSS class / ID to each of the "span" generated by the default pagination helper in CakePHP.
see: http://www.switchonthecode.com/tutorials/cakephp-part-6-pagination
and https://book.cakephp.org/3/en/views/helpers/paginator.html
What stands out here is that you can pass options to next(), prev(), and numbers()
what you want to do is pass the class option.
e.g.
$paginator->prev(
'<< Previous',
array(
'class' => 'PrevPg'
),
null,
array(
'class' => 'PrevPg DisabledPgLk'
)
).
$paginator->numbers(
array(
'class' => 'numbers'
)
).
$paginator->next(
'Next >>',
array(
'class' => 'NextPg'
),
null,
array(
'class' => 'NextPg DisabledPgLk'
)
),
array(
'style' => 'width: 100%;'
)