Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

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.


Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -