Welcome Guest, Not a member yet? Register   Sign In
Help needed with Modular Extensions
#1

[eluser]k2zs[/eluser]
Hello,

I'm using CI ver 1.7.x and am having problems loading a module from my default view. I have followed the bit bucket wiki and was able to move my entire project from the default directory structure to my new application/modules structure and have it work.

I want to break up the default view into modules so the first module I tried was for my main navigation. I created the following files:

mainnav controller in /modules/mainnav/controller
Code:
<?php
/**
*
* This is the controller for main navigation
*
*/

class Mainnav extends Controller
{
    function Mainnav()
    {
        // load controllers parent
        parent::Controller();
        // load this controllers model
        $this->load->model('mainnav_model');
    }
    
    function index()
    {        
        // build the main navigation through the model
        $data['mainNav'] = $this->mainnav_model->getMainNav();
        
        // NOTE: using static value for testing
        $data['activeParentID'] = 1;
        
        // load the main nav view
        $this->load->view('mainnav_view', $data);
    }
}

/* End of file mainnav.php */
/* Location: ./application/modules/mainnav/controllers/mainnav.php */

mainnav model in /modules/mainnav/models
Code:
<?php
/**
*
* This is the model for main navigation
*
*/

class Mainnav_model extends Model {
        
    // collect the items for main navigation
    function getMainNav()
    {
        $this->db->order_by('ParentID', 'asc');
        $this->db->order_by('pgNavOrder', 'asc');
        $this->db->where('pgActive', 1);
        $this->db->where('ParentID', 0);
        $q = $this->db->get('pages');
        
        if($q->num_rows() > 0) {
            foreach ($q->result() as $row) {
                $data[] = $row;
            }
        return $data;
        }
    }
}

/* End of file mainnav_model.php */
/* Location: ./application/modules/mainnav/models/mainnav_model.php */

mainnav view in /modules/mainnav/views
Code:
<div id = "topNav">
<span class = "left">&nbsp;</span>
&lt;?php if (!EMPTY($mainNav)): ?&gt;
    &lt;?php foreach ($mainNav as $row): ?&gt;
    &lt;?php
        $url_title = url_title($row->pageURI, 'dash', TRUE);
        $rootURI = $row->rootURI;
    ?&gt;
    &lt;?php if ($row->pgID == $activeParentID): ?&gt;
        &lt;?php echo anchor($rootURI . '/' . $url_title, $row->pgName, array ('class' => 'currentParent')); ?&gt;
    &lt;?php else: ?&gt;
        &lt;?php echo anchor($rootURI . '/' . $url_title, $row->pgName); ?&gt;
    &lt;?php endif; ?&gt;
    &lt;?php endforeach; ?&gt;
&lt;?php endif; ?&gt;
</div>

I call the view from within my default view using:
Code:
&lt;?php
    // I tried by loading view
    //$this->load->view('mainnav');
    
    // then I tried by running module
    echo modules::run('mainnav', $activeParentID);
    
    //neither method works
    ?&gt;

When I load the default page CI breaks and I see repeated errors for the error pages heading variable

I have even tried having the mainnav controller just echo a word so I'm not sure whats going on. What am I doing wrong?

I saw somewhere that modules have to extend controllers usin MX_ and I tried this in my mainnav controller:
Code:
&lt;?php
/**
*
* This is the controller for main navigation
*
*/

class Mainnav extends MX_Controller
{
    function Mainnav()
    {
        // load controllers parent
        parent::MX_Controller();
        // load this controllers model
        $this->load->model('mainnav_model');
    }
    
    function index()
    {        
        // build the main navigation through the model
        $data['mainNav'] = $this->mainnav_model->getMainNav();
        
        // NOTE: using static value for testing
        $data['activeParentID'] = 1;
        
        // load the main nav view
        $this->load->view('mainnav_view', $data);
    }
}

/* End of file mainnav.php */
/* Location: ./application/modules/mainnav/controllers/mainnav.php */
and I get this:
Fatal error: Cannot redeclare class CI in /srv/www/htdocs/staging/ci.k2zs.com/application/third_party/MX/Base.php on line 76




Theme © iAndrew 2016 - Forum software by © MyBB