CodeIgniter Forums
how to call my model function in view page? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: how to call my model function in view page? (/showthread.php?tid=23186)



how to call my model function in view page? - El Forum - 10-03-2009

[eluser]suba[/eluser]
HI All,
hopefully CI is very useful for PHP programmer.
I created one function in my model class.
i want to call this function into my view page.
Example code:
class Newmodel extends Model
{
function Newmodel()
{
parent::Model();
}
function getName()
{
echo "suba";
....
}
}//end class
My view page.
<html>
...
i loaded model class in my controller using $this->load->model('newmodel').
here i want to call getName function. How to call? please help to me.

</html>


how to call my model function in view page? - El Forum - 10-03-2009

[eluser]InsiteFX[/eluser]
If you autoload your model in application/config/autoload

you can then access it like this:

Code:
<php echo $this->modelname->getname();?&gt;

or you can get it in your Controller and pass it to your view like this:

Code:
var $data = array();

function index
{
    $data['name'] = $this->model->getname();

    $this->load->view('viewname', $data);
}

In your view:

Code:
&lt;?php echo $name;?&gt;

Enjoy
InsiteFX


how to call my model function in view page? - El Forum - 10-03-2009

[eluser]suba[/eluser]
Hi,
thanks. very much.
will try this..
lot of thanks..


how to call my model function in view page? - El Forum - 10-03-2009

[eluser]suba[/eluser]
hi,
i want to pass argument from view page.
what is the execution process.?
please explain how to execute this?