[eluser]lmv4321[/eluser]
A browse function in my categories controller which displays all rows in the table:
Code:
// -------------------------------------------------------------------------
// Function: browse()
// Description: Extracts a list of all categories and
// displays it.
function browse()
{
$this->load->model('categories_model'); // Instantiate the model
// fetch query object from categories with fields id, name
$template['categories_list'] = $this->categories_model->fetch('categories','id, name');
// create urls for use in content view
$template['base_url'] = 'concentric/categories/browse/';
$template['modify_url'] = 'concentric/categories/modify/';
$template['delete_url'] = 'concentric/categories/delete/';
$template['add_url'] = 'concentric/categories/add/';
$template['cancel_url'] = 'concentric/home';
// set values for use in content view
$template['form_attributes'] = array('name' => 'frmcc_categories', 'id' => 'frmcc_categories');
$template['header'] = $this->form_name;
// build content html using grid view and template data
$data['content'] = $this->load->view('/concentric/categories/categories_grid', $template, TRUE);
// set values for use in header view
$data['header'] = $this->form_name;
// pass all data to container view and display to user
$this->load->view('/concentric/container',$data);
}
In the contructor of this controller, other libraries get called which set values that are then output in the header view.
Code:
$this->page->set_metatag('robots','nofollow, noindex');
$this->page->set_metatag('pragma','nocache',TRUE);
(BackendPro users may recognize these functions.)
The categories_grid view contains this code:
Code:
<h2><?=$header?></h2>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<th align="right">
<div class="buttons">
<a href="<?=site_url($add_url)?>" class="blue">
<?= $this->page->icon('add');?>
Add
</a>
</div>
</th>
</tr>
</table>
<br />
<table class="tbl" border="0" cellpadding="2" cellspacing="1" width="100%">
<thead>
<tr>
<th align="right" width="70"> sort by: </th>
<th VALIGN='MIDDLE' ALIGN='CENTER' class='tbl_headercell'>
Id
</th>
<th VALIGN='MIDDLE' ALIGN='CENTER' class='tbl_headercell'>
Name
</th>
</tr>
</thead>
<tbody class="scrollingContent">
<?
$i = 0;
foreach ($categories_list->result_array() as $categories) {
$i++;
if (($i%2)==0) { $bgColor = "#FFFFFF"; } else { $bgColor = "#C0C0C0"; }
?>
<tr bgcolor="<?= $bgColor; ?>">
<td align="center" nowrap="nowrap">
<a href = "<?= site_url($modify_url).">Edit</a>
<a href = "<?= site_url($delete_url).">Delete</a>
</td>
<td align="left" nowrap="nowrap"><?= $categories['id']; ?></td>
<td align="left" nowrap="nowrap"><?= $categories['name']; ?></td>
</tr>
<? } ?>
</tbody>
</table>
<br />
<div class="buttons">
<a href="<?=site_url($cancel_url)?>" class="negative">
<?= $this->page->icon('cross');?>
Cancel
</a>
</div>
and then the content view has this code:
Code:
<div id="navigation">
<?=$this->load->view('concentric/menu');?>
</div>
<div id="content">
<a name="top"></a>
<?=$this->status->display();?>
<?=(isset($content)) ? $content : NULL; ?>
</div>
This may not be the best code or the most efficient, but after only 2-3 weeks of using CodeIgniter (and with very little prior experience in php), I think it is pretty good.
Notes: CodeIgniter version 1.6.3, BackendPro 0.3.1