Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] "Non-object" fatal error when loading two models in a controller
#7

[eluser]adityamenon[/eluser]
Hi, CIDeveloper thanks for trying to help. Here's the code for the model:

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Frontend_model extends CI_Controller {

    function __construct()
    {
        parent::__construct();
        $this->load->database();
    }
    
    //X and Y data on the home page
    function home_data($type)
    {
        $return = 'none found';
        $this->db->order_by('last_changed', 'DESC');
        $query = $this->db->get($type, 4);
        if($query->num_rows() > 0)
        {
            $return = $query->result_array();
        }
        return $return;
    }

    //get the marquee above the navigation
    function get_marquee()
    {
        $return = 'none found';
        $this->db->order_by('timestamp', 'DESC');
        $query = $this->db->get('home_news');
        if($query->num_rows() > 0)
        {
            $return = $query->result_array();
        }
        return $return;
    }
    
    //X and Y data in the dedicated pages
    function all_type_data($type)
    {
        $return = 'none found';
        $this->db->order_by('last_changed', 'DESC');
        $query = $this->db->get($type);
        if($query->num_rows() > 0)
        {
            $return = $query->result_array();
        }
        return $return;
    }
}

^^As you can see, the above is pretty innocent stuff, and there are no errors coming out of there.

Like I had stated, I had abandoned trying to load two models in the same controller after I faced this error. However, I am facing a new, but somehow related problem.

I'm trying to use the pagination library, but it won't execute the create_links() function inside the view. I have already put this line into application/config/autoload.php

Code:
$autoload['libraries'] = array('form_validation', 'session', 'pagination', 'database');

All the other libraries are working fine. Except for Pagination and Database. As you can see, I had to include this line inside the __constructor function in the frontend_model:

Code:
$this->load->database();

I'm unable to use any db functions otherwise! CI says $this->db is an unidentified object.

And coming back to pagination, here's the controller code:

Code:
function index($type)
    {
        $this->load->view('head_section', array('title' => 'Browse all '.$type.' - Site name', 'marquee' => $this->frontend_model->get_marquee()));
        
        $pag_config['base_url'] = base_url().'find_partner/index/'.$type.'bml';
        $pag_config['total_rows'] = 4;
        $pag_config['per_page'] = 2;
        $this->pagination->initialize($pag_config);
        
        $this->load->view('find_partner', array('data' => $this->_data($type), 'type' => $type));
        $this->load->view('footer');
    }

The Pagination initialize() function is working in the controller, but in the view,

Code:
<div id="mainbody">
                <div id="inner-page-box">
                    <img src="&lt;?=base_url()?&gt;assets/images/inner-page-box/bg-top.png" id="inner-page-box-top" /><img src="&lt;?=base_url()?&gt;assets/images/inner-page-box/bg-btm.png" id="inner-page-box-btm" />
                    <h1>All  &lt;?=$type?&gt; with Site X</h1>
                    <p>
                        &lt;?php echo $this->table->generate($data); ?&gt;
                        &lt;?php echo $this->pagination->create_links(); ?&gt;
                    </p>
                </div>
            </div>

^^ In the above create_links() is not working. The error I'm getting is:

Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: CI_Loader::$pagination

Filename: views/find_partner.php

Line Number: 8

Can anyone tell me what's wrong? I even changed the config['uri_protocol'] from 'QUERY_STRING' to 'AUTO' to see if that was causing the problem, but there was no result...

Thanks a lot for reading my long message!


Messages In This Thread
[SOLVED] "Non-object" fatal error when loading two models in a controller - by El Forum - 06-08-2011, 01:53 AM



Theme © iAndrew 2016 - Forum software by © MyBB