Welcome Guest, Not a member yet? Register   Sign In
How to include header controller to other pages?
#5

[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>&lt;?=$header?&gt;</h2>

<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
    <th align="right">
    <div class="buttons">
        <a href="&lt;?=site_url($add_url)?&gt;" class="blue">
        &lt;?= $this->page->icon('add');?&gt;
        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"> &nbsp; sort by:&nbsp; </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">

    &lt;?
        $i = 0;
        foreach ($categories_list->result_array() as $categories) {
            $i++;
            if (($i%2)==0) { $bgColor = "#FFFFFF"; } else { $bgColor = "#C0C0C0"; }
    ?&gt;
    <tr bgcolor="&lt;?= $bgColor; ?&gt;">
        <td align="center" nowrap="nowrap">
            <a href = "&lt;?= site_url($modify_url).">Edit</a>
            &nbsp;&nbsp;&nbsp;
            <a href = "&lt;?= site_url($delete_url).">Delete</a>
        </td>
        <td align="left" nowrap="nowrap">&lt;?= $categories['id']; ?&gt;</td>
        <td align="left" nowrap="nowrap">&lt;?= $categories['name']; ?&gt;</td>
    </tr>
        &lt;? } ?&gt;
</tbody>
</table>

<br />

<div class="buttons">
    <a href="&lt;?=site_url($cancel_url)?&gt;" class="negative">
    &lt;?= $this->page->icon('cross');?&gt;
    Cancel
    </a>
</div>

and then the content view has this code:
Code:
<div id="navigation">
    &lt;?=$this->load->view('concentric/menu');?&gt;
</div>

<div id="content">            
    <a name="top"></a>
    &lt;?=$this->status->display();?&gt;
    &lt;?=(isset($content)) ? $content : NULL; ?&gt;
</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


Messages In This Thread
How to include header controller to other pages? - by El Forum - 11-05-2008, 12:15 PM
How to include header controller to other pages? - by El Forum - 11-05-2008, 02:43 PM
How to include header controller to other pages? - by El Forum - 11-05-2008, 02:53 PM
How to include header controller to other pages? - by El Forum - 11-05-2008, 03:04 PM
How to include header controller to other pages? - by El Forum - 11-05-2008, 03:38 PM



Theme © iAndrew 2016 - Forum software by © MyBB