how to join two table in codeigniter easily[updated] | ci_model | ci_controller | codeigniter 3 -datainflow
Some issues may occur when data table is used with huge records for pagination. So, framework pagination is always better to avoid that issues. I would like to post a pagination on Cakephp, Kindly follow the below steps.
Step 1 : make a model file named ‘course.php’ and use the database table in this model then make a controller and create a function named “index”.
function index() { $this->Course->recursive = 0; $this->set('courses', $this->paginate()); }
Step 2: As the flow of CakePHP, the view page name would be same name as controller name i.e index.ctp and place the following code.
<div> <div style="float: left"><h2><?php __('Manage Courses');?></h2></div> <div style="float: right; padding-bottom:5px;"><?php echo $this->Html->link(__('(Add New Course)', true), array('action' => 'add'), array('style'=>'color:#003D4C;')); ?></div> <div style="clear: both"></div> <table cellpadding="0" cellspacing="0"> <tr> <th><?php echo $this->Paginator->sort('id');?></th> <th><?php echo $this->Paginator->sort('course_name');?></th> <th style="text-align:center;"><?php echo $this->Paginator->sort('status');?></th> <th class="actions" style="text-align:center;"><?php __('Actions');?></th> </tr> <?php $i = 0; foreach ($courses as $course): $class = null; if ($i++ % 2 == 0) { $class = ' class="altrow"'; } ?> <tr<?php echo $class;?>> <td><?php echo $course['Course']['id']; ?> </td> <td><?php echo $course['Course']['course_name']; ?> </td> <td class="actions" style="text-align:center;"><?php if($course['Course']['status']=='Y') { $status = 'Active'; $action = 'deactivate'; } else { $status = 'Inactive'; $action = 'activate'; } echo $this->Html->link(__($status, true), array('action' => 'status', $course['Course']['id']), array('title' => 'Click here to '.$action.' course')); ?> </td> <td class="actions" style="text-align:center;"> <?php echo $this->Html->link(__('View', true), array('action' => 'view', $course['Course']['id'])); ?> <?php echo $this->Html->link(__('Edit', true), array('action' => 'edit', $course['Course']['id'])); ?> <?php echo $this->Html->link(__('Delete', true), array('action' => 'delete', $course['Course']['id']), array('class'=>'ask'), null, sprintf(__('Are you sure you want to delete # %s?', true), $course['Course']['id'])); ?> </td> </tr> <?php endforeach; ?> </table> <p> <?php echo $this->Paginator->counter(array( 'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true) )); ?> </p> <div class="paging"> <?php echo $this->Paginator->prev('<< ' . __('previous', true), array(), null, array('class'=>'disabled'));?> <?php echo $this->Paginator->numbers();?> <?php echo $this->Paginator->next(__('next', true) . ' >>', array(), null, array('class' => 'disabled'));?> </div> </div>
According to your database you must use the database table field name in the ctp file.
Related posts