Welcome Guest, Not a member yet? Register   Sign In
$this->blog_model->func() and $this->blog->func()
#1

[eluser]luffy[/eluser]
I want to use $this->blog->func() instead of $this->blog_model->func()

How should I do

If I use $this->blog->func(), it will shows :
Unable to locate the model you have specified: blog
#2

[eluser]überfuzz[/eluser]
[quote author="luffy" date="1254022315"]...
If I use $this->blog->func();
...
[/quote]
You might wanna read up on that first lesson in programing... ;-)
Code:
$this->blog->func();

//First you need to load the model, if it is a model, in the models folder.
$this->load->model('model_name'); //If theres a model called model_name it's now loaded.

//If you have created a method/function called method_get_stuff_from_db() you can use it, or maybe we could say reach, it like this.
$this->model_name->method_get_stuff_from_db();
#3

[eluser]pistolPete[/eluser]
Have a look at the user guide: http://ellislab.com/codeigniter/user-gui...oader.html

Quote:If you would like your model assigned to a different object name you can specify it via the second parameter of the loading function:
Code:
$this->load->model('Model_name', 'fubar');

$this->fubar->function();
#4

[eluser]steelaz[/eluser]
Don't forget that if you use $this->blog for a model, you can't name your controller "Blog".
#5

[eluser]wiredesignz[/eluser]
[quote author="steelaz" date="1254100228"]Don't forget that if you use $this->blog for a model, you can't name your controller "Blog".[/quote]

You can use blog as a model alias name and have a blog controller class, as PistolPete suggests above. (but it may be confusing)
#6

[eluser]steelaz[/eluser]
[quote author="wiredesignz" date="1254101053"][quote author="steelaz" date="1254100228"]Don't forget that if you use $this->blog for a model, you can't name your controller "Blog".[/quote]

You can use blog as a model alias name and have a blog controller class, as PistolPete suggests above. (but it may be confusing)[/quote]

Thanks for correcting me, I tried it some time ago and got an error (PHP4 fault?), will try again.




Theme © iAndrew 2016 - Forum software by © MyBB