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%;'
)
Related
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
Hi i have model logo with the following associations
var $belongsTo = array(
'Attachment' => array(
'className'=>'Attachment',
'foreignKey'=>'attachment_id'
),
'Employee' => array(
'className'=>'Employee',
'foreignKey'=>'employee_id'
)
);
var $hasMany = array(
'Voting' => array(
'className'=>'Voting',
'foreignKey'=>'program_id'
)
);
i wrote a query in the following way it throws error
$PrgCond['contain'] = array(
'Attachment',
'Voting' => array(
'fields' => array(
'logo_program_id',
'COUNT(employee_id) as noOfEmps'
),
'group' => array('LogoVoting.logo_program_id')
),
'Employee' => array(
'fields' => array('id', 'employee_number', 'first_name', 'last_name')
)
);
$logoPrgDatas = $this->Program->find('all',$PrgCond);
Thrown Error is
SQL Error: 1054: Unknown column 'LogoVoting.logo_program_id' in 'field list'
This is an old question but still comes up in Google results..
I had a similar issue and found out that you cannot use group in the Model find options when you have associations or either use containable behavior(which uses associations) in cakephp 1.* or 2.*.
However, this issue is fixed in cakephp 3.* by using query builder! :)
It's a good idea to reference the model in your fields. For example, when you are using a column in a condition or a fields array, you should call it Model.column_name.
Having said that, the problem you are having is most likely related to the group:
'group' => array('LogoVoting.logo_program_id')
There is no LogoVoting in your model. It should be:
'group' => array('Voting.logo_program_id')
So I would update the query to be:
$PrgCond['contain'] = array(
'Attachment',
'Voting' => array(
'fields' => array(
'Voting.logo_program_id',
'COUNT(Voting.employee_id) as noOfEmps',
),
'group' => array('Voting.logo_program_id'),
),
'Employee' => array(
'fields' => array(
'Employee.id',
'Employee.employee_number',
'Employee.first_name',
'Employee.last_name',
),
),
);
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.
I have this NPO table which has one template. A template in turn has a theme. I want to retrieve which theme was selected by Npo.
I have following relation setup:
NPO - template on npo.id = template.npoid Template - theme on theme.id
= template.template_theme_id
And I am using:
$this->Npo->bindmodel(array(
'hasOne' => array(
'NpoTemplate' => array(
'className' => 'NpoTemplate'
)
)
), false);
$this->NpoTemplate->bindmodel(array(
'hasOne' => array(
'TemplateTheme' => array(
'className' => 'TemplateTheme',
'fields' => 'TemplateTheme.html'
)
)
), false);
$arrUserSite = $this->Npo->find('first', array(
'conditions'=> array(
'Npo.address' => $user
)
));
But it does not fetch anything from TemplateTheme. Instead it writes a seperate query for this table and does not consider it in the join.
I have set recursive level to 3
Please help. I don't really understand how the cake association works.
Regards
Himanshu Sharma
Try setting up your relationships in a single bindModel() call.
$this->Npo->bindmodel(array(
'hasOne' => array(
'NpoTemplate' => array(
'foreignKey' => false,
'conditions' => array(
'Npo.id = NpoTemplate.npoid'
)
),
'TemplateTheme' => array(
'foreignKey' => false,
'conditions' => array(
'NpoTemplate.template_theme_id = TemplateTheme.id'
)
)
)
));
$arrUserSite = $this->Npo->find('first', array(
'conditions' => array(
'Npo.address' => $user
)
));
You'll probably need to tweak the bindModel setup because I'm not 100% sure of your database structure. Good luck.
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.