How to call my model function ? |
[eluser]suba[/eluser]
Hi everybody.. class Model_sims extends Model { function Model_sims() { parent::Model(); $this->load->database(); } function checkAuthorization() { if($this->session->userdata('username')) { redirct(base_url()); exit(); } } } This is my model class. now i want to call this function(checkAuthorization) into my controller. how to call. pls favor me.
[eluser]pistolPete[/eluser]
Please use [ code ] tags! Read the user guide, it's all there: http://ellislab.com/codeigniter/user-gui...ml#loading
[eluser]whitey5759[/eluser]
[quote author="suba" date="1254224488"]Hi everybody.. class Model_sims extends Model { function Model_sims() { parent::Model(); $this->load->database(); } function checkAuthorization() { if($this->session->userdata('username')) { redirct(base_url()); exit(); } } } This is my model class. now i want to call this function(checkAuthorization) into my controller. how to call. pls favor me.[/quote] In your Controller you would put: //Load your Model $this->load->model("model_sims"); //Now that your Model is loaded, call the function within it $this->model_sims->checkAuthorization();
[eluser]suba[/eluser]
Hi, thanks.. class Home extends Controller { function Home() { parent::Controller(); } function index() { $this->Model_sims->checkAuthorization();//this model function $this->load->view('header/menu_link'); } } this is my controller. But i have received error. Error is A PHP Error was encountered Severity: Notice Message: Undefined property: Home::$Model_sims Call to a member function checkAuthorization() on a non-object in
[eluser]whitey5759[/eluser]
Yeah that's coz you first have to load the Modle, then and only then can you call it (with no capitals).
[eluser]suba[/eluser]
Hi, thanks a lot but i loaded automatically. using this $autoload['model'] = array('model_sims'); in autoload. |
Welcome Guest, Not a member yet? Register Sign In |