Featured post
php - codeigniter -> having trouble loading multiple libraries/classes -
ok, in base controller (page.php) have following code works fine:
$this->load->library('siteclass'); $mysite = new site_model();
the siteclass library references model named site_model , instantiates based on data received model. good.
now want load library can instantiate object well. add page.php:
$this->load->library('memberclass'); $mysite = new member_model();
but following error:
message: undefined property: memberclass::$site_model filename: libraries/loader.php line number: 1035
from can tell, seems loader class, when being applied memberclass, somehow still referencing site_model instead of member_model. i've checked code , calling correct files.
here's siteclass.php looks like:
if ( ! defined('basepath')) exit('no direct script access allowed'); class siteclass extends controller { function __construct() { parent::controller(); $this->load->model('site_model'); $data = $this->site_model->load_site_data(); // etc etc
and here's memberclass.php looks like:
if ( ! defined('basepath')) exit('no direct script access allowed'); class memberclass extends controller { function __construct() { parent::controller(); $this->load->model('member_model'); $data = $this->member_model->load_member_data(); // etc etc
thanks in advance help!
gary
i think you're confused how mvc works in codeigniter. why using loader class create controller? why creating stand-alone instance of model outside of controller class?
in codeigniter, urls represent paths controllers' methods. means "base controller" should automatically instantiated if go to:
www.example.com/memberclass
or perhaps more point, if have link this:
www.example.com/page
you should have file in /application/controllers
directory called page.php
looks this:
if ( ! defined('basepath')) exit('no direct script access allowed'); class page extends controller { function __construct() { parent::controller(); // etc etc
furthermore, unless you're loading data model used every single time call controller, you'll want put model calls inside non-constructor method of class. like:
class page extends controller { function __construct() { parent::controller(); } function index() { $this->load->model('member_model'); $data = $this->member_model->load_member_data(); $this->load->view('myview', array('data'=>$data)); } }
so again...not entirely sure context you're doing in, seems you're not standing firmly within framework. there's no reason should using loader class load controllers, , furthermore there's no reason should creating stand-alone instances of model classes using php's new
keyword.
- Get link
- X
- Other Apps
Comments
Post a Comment