How to create link make cakephp with twitter bootstrap - cakephp

example:
<a class="btn btn-mini" href="#"><i class="icon-star"></i> Star</a>
i try by Html::Helpers like
echo $this->Html->link($this->Html->tag('i','',
array('class' => 'btn')), array('action' => '../link'));
but it not work !

try:
echo $this->Html->link(
$this->Html->tag('i', '', array('class' => 'icon-star')) . " Star",
array('action' => 'your_action'),
array('class' => 'btn btn-mini', 'escape' => false)
);

Related

how can i write helper link with image link in span tag cakephp

i want to generate this
<a href="/users/signup" class="sf-with-ul">
<span class="profile-avatar">
<img alt="" src="img/avatar/anonymous.png" height="40" width="40">
</span>
</a>
I have written
<?php echo $this->Html->link(
$this->Html->image('avatar/anonymous.png',array('height' =>40,'width'=>'40')), array('controller' => 'users', 'action' => 'signup'),
array('class' => 'sf-with-ul', 'escape' => false));?>
which generates
<span class="profile-name"></span><img src="/FindTutor/img/avatar/anonymous.png" height="40" width="40" alt="" />
Any help? Thanks in advance.
you can try this just change your image path
<?php echo $this->Html->link('<span class="profile-avatar">'. $this->Html->image('home/logo.png',array('width'=>'40px','height'=>'40px'), array('alt' => '')), array('controller' => 'users', 'action' => 'signup' ), array('class' => 'sf-with-ul', 'escape' => false)).'</span>';?>
Try this:
<?php
$img = $this->Html->image("avatar/anonymous.png",
array("height" => "40", "width" => "40")
);
$img_span = $this->Html->tag('span', $img,
array('class' => 'profile-avatar')
);
echo $this->Html->link($img_span,
array("controller" => "users", "action" => "signup"),
array("escape" => false)
);
?>
This looks a little lengthy but it's easier to understand and works exactly like what you're asking for.
Peace! xD

CakePHP Html->link and Form->end

I have this link that I use to for my modal
<?php
echo $this->Html->link('Create Schedule', '#', array('id' => 'createSchedule', 'class' => 'btn btn-success', 'role' => 'button', ));
?>
How do I convert it to $this->Form->end() format?
Thank you!
You can do this also
<?php
echo $this->Form->button("Create Schedule", array("id" => "createSchedule", "class" => "btn btn-success", "type" => "submit"));
echo $this->Form->end();
?>
or you could also do this
<?php
echo $this->Form->submit("Create Schedule", array("id" => "createSchedule", "class" => "btn btn-success"));
echo $this->Form->end();
?>
You can try this
<?php
$options = array(
'label' => 'Create Schedule',
'id' => 'createSchedule',
'class' => 'btn btn-success'
);
echo $this->Form->end($options);
?>

What is cakephp's 'maximum depth reached', I got this error while patination with message 'address not found'

I am new to cakephp and using 2.4 version with bootstrap css.
I have almost finished my project but getting some errors while creating search with pagination.
While pagination in Cakephp, first pages are working fine but last 2-3 pages shows error as the requested address was not found on this server.
tables are below.
universities, courses, semesters, subjects, units, topics
respectively these models having hasMany relationships from left to right.
e.g. universities hasMany courses, courses hasMany semesters.....
my search actions is as below.
public function searchresults() {
if($this->request->is('post')) {
$unid=$this->data['University']['universities'];
$searched = $this->data['University']['searchtxt'];
$this->Session->write('Searched.stext',$searched);
$this->Session->write('Searched.univ',$unid);
}
$unid=$this->Session->read('Searched.univ');
$searched = $this->Session->read('Searched.stext');
//Create Join to find total numbers of records after search
$this->Topic->bindModel(array(
'belongsTo' => array(
'Unit' => array(
'foreignKey' => false,
'type' => 'RIGHT',
'conditions' => array(
'Topic.unit_id = Unit.id' ,
)
),
'Subject' => array(
'foreignKey' => false,
'type' => 'RIGHT',
'conditions' => array(
'Unit.subject_id = Subject.id',
)
),
'Semester' => array(
'foreignKey'=> false,
'type'=>'RIGHT',
'conditions' => array (
'Subject.semester_id = Semester.id'
)
),
'Course' => array(
'foreignKey'=> false,
'type'=>'RIGHT',
'conditions' => array (
'Semester.course_id = Course.id'
)
),
'University' => array(
'foreignKey'=> false,
'type'=>'RIGHT',
'conditions' => array (
'Course.university_id = University.id'
)
)
)
));
$this->Paginator->settings=array(
'limit'=>10,
'page'=>1,
'conditions' => array('or'=>array(
'Topic.name LIKE' => '%'.$searched.'%',
'Topic.description LIKE' => '%'.$searched.'%'
)),
);
$data=$this->paginate('Topic');
//debug($data);
$this->set('searched',$searched);
$this->set('sresults',$data);
$this->set('uni_id',$unid);
}
my view's pagination part code is as below:
<div class="row"><!--Pagination links begins -->
<div class="col-sm-8 col-sm-offset-3">
<!-- Shows the next and previous links -->
<ul class="pagination largescreen">
<li class="disabled-page mobileview">
Page <?php echo $this->Paginator->counter(); ?>
</li>
<?php echo $this->Paginator->prev('«', array('tag'=>'li'), null, array('class' => 'disabled-page','tag'=>'li')); ?>
<!-- Shows the page numbers -->
<?php
echo $this->Paginator->numbers(array(
'tag'=>'li',
'separator'=>'',
'currentClass'=>'active',
'currentTag'=>'a',
'modulus'=>4
));
?>
<?php echo $this->Paginator->next('»', array('tag'=>'li'), null, array('class' => 'disabled-page','tag'=>'li')); ?>
</ul>
</div>
<div>
<ul class="pagination pagination-sm smallscreen" style="overflow:auto;">
<li class="disabled-page mobileview">
Page <?php echo $this->Paginator->counter(); ?>
</li>
<?php echo $this->Paginator->prev('«', array('tag'=>'li'), null, array('class' => 'disabled-page','tag'=>'li')); ?>
<!-- Shows the page numbers -->
<?php
echo $this->Paginator->numbers(array(
'tag'=>'li',
'separator'=>'',
'currentClass'=>'active',
'currentTag'=>'a',
'modulus'=>8
));
?>
<?php echo $this->Paginator->next('»', array('tag'=>'li'), null, array('class' => 'disabled-page','tag'=>'li')); ?>
</ul>
</div>
</div><!--Pagination links ends -->
Please help as i am stuck after searching a lot about this...

cannot set id in cakephp postLink

I am unable to set the id of the form or the class of the submit button. I seen examples that follow my code but I am not getting either set.
I am using cakePHP 2.5.
<?php
echo $this->Form->postLink(
'Confirm',
array('controller' => 'assets', 'action' => 'delete'),
array('id' => 'testId', 'class' => 'btn btn-confirm')
);
?>
What I get is
<form action="/assets/ajax_delete/56.json" name="post_53ac1bb05415c464261170" id="post_53ac1bb05415c464261170" style="display:none;" method="post">
<input type="hidden" name="_method" value="POST">
</form>
Confirm
<?php echo $this->Form->postLink('Confirm', array('controller' => 'assets', 'action' => 'delete', $yourId), null, __('Are you sure you want to delete # %s?', $yourId)); ?>

cakephp pagination with count issue

I have written below code in my controller action.
$this->paginate['Tag'] = array(
'fields' => array('COUNT(tag_id) AS numbers', 'tag', 'slug'),
'limit' => 50,
'order' => 'numbers desc',
'recursive' => 2,
'group' => array('tag'),
);
$tags = $this->paginate('Tag', array('not' => array('site_id' => NULL), 'tag !=' => ''));
And written below code in the .ctp file.
<div class="row section">
<div class="col col_16 pagination">
<h3>Tags</h3>
<?php
foreach ($tags as $key => $tag) {
echo '<span>' . $this->Html->link($tag['Tag']['tag'] . ' (' . $tag[0]['numbers'] . ')', '/tags/' . $tag['Tag']['slug']) . '</span>';
}
?>
</div>
<div class="col col_16 pagination">
<?php
echo $this->Paginator->first('First', null, null, array('class' => 'disabled'));
echo $this->Paginator->prev('Previous', null, null, array('class' => 'disabled'));
echo $this->Paginator->numbers(array('separator' => ''));
echo $this->Paginator->next('Next', null, null, array('class' => 'disabled'));
echo $this->Paginator->last('Last', null, null, array('class' => 'disabled'));
?>
</div>
<div class="col col_16 pagination">
<h5 class="margin0Px">
<?php
echo $this->Paginator->counter(array(
'format' => __('Page %page% of %pages%, showing %current% out of %count% total, starting on %start%, ending on %end%.', true)
));
?>
</h5>
</div>
</div>
Getting false result in view $this->Paginator.
What is the issue here? I am not getting any idea. Pls help.
Does you controller define the helpers variable? If it doesn't the Paginator helper is included by default. If it does you have to remember to include it yourself.
Documentation: http://book.cakephp.org/1.3/en/view/1096/Using-Helpers

Resources