Calling model functions from views

#1
[eluser]Unknown[/eluser]
I can't seem to do it. Every time I try, I get an error message like this:

Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined property: CI_Loader::$mymodel

Filename: mymodel.php

Line Number: 5

Fatal error: Call to a member function hello() on a non-object in ~/public_html/codeigniter/system/application/views/content/form/forening_redigera.php on line 5

From the view file:
Code:
$this->load->model('mymodel');
echo $this->mymodel->hello();

From the model file:
Code:
function hello()
    {
        $hi = 'hello';
        return $hi;
    }

#2
[eluser]wiredesignz[/eluser]
You can't load Models in your View, but you can access them from the View after they have been loaded in the Controller

#3
[eluser]Unknown[/eluser]
[quote author="wiredesignz" date="1201233580"]You can't load Models in your View, but you can access them from the View after they have been loaded in the Controller[/quote]
Oh! Thanks a lot. Smile

#4
[eluser]Sawariya[/eluser]
in controller

$this->load->model('mymodel');

in view

echo $this->mymodel->hello();
it will print hello...

#5
[eluser]sikkle[/eluser]
I think if you try to create kind of partial, you can use helper to create them and call them in view.

Good luck !


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.