Welcome Guest, Not a member yet? Register   Sign In
how to call my model function in view page?
#1

[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>
#2

[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
#3

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

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




Theme © iAndrew 2016 - Forum software by © MyBB