Welcome Guest, Not a member yet? Register   Sign In
calling a controller model from other objects when its for a menu
#1

[eluser]porangi[/eluser]
Hi,

I know this question has been asked many times before but I would just like some clarification. I am building a simple pages module that I can use in client sites. The idea is that its a simple CMS. I've created all the Frontend/Backend page stuff but what is the best approach with respect to the menu.

I know I could create a helper and call the DB etc from there but then I'm not really using the model and all the wonderful query functions etc I have created there which kind of breaks the MVC model does it not.

Maybe some will just tell me to chill and break the MVC but I want to ensure I doing it the 'right' way.


Cheers in advance.

Chris
#2

[eluser]LinkFox[/eluser]
[quote author="porangi" date="1305313728"]Hi,

I know this question has been asked many times before but I would just like some clarification. I am building a simple pages module that I can use in client sites. The idea is that its a simple CMS. I've created all the Frontend/Backend page stuff but what is the best approach with respect to the menu.

I know I could create a helper and call the DB etc from there but then I'm not really using the model and all the wonderful query functions etc I have created there which kind of breaks the MVC model does it not.

Maybe some will just tell me to chill and break the MVC but I want to ensure I doing it the 'right' way.


Cheers in advance.

Chris[/quote]

Hi I'm not really sure what you're asking but you can call models from helpers. You just need to get an instance of CI.

So
Code:
$inst = &get;_instance();

$inst->load->model('myModel');

$inst->mymodel->myfunction();
That way you can call your DB from your helper. Your helper should be called from your controller etc.

Theres nothing wrong with making database calls in a library or helper if you require information to make it work.

Hope this helps.

Regards

David
#3

[eluser]porangi[/eluser]
Hi David,

Thanks for your reply. I had obviously skipped the lesson that said you can use models!

Just a quick question...

Code:
$inst = &get;_instance();

or

Code:
$CI =& get_instance();

or is the ; a typo?

Regards

Chris
#4

[eluser]LinkFox[/eluser]
Hi,

Yes sorry it's a typo.

Its

Code:
$inst = & get_instance();

I obviously call the variable $inst but you can call it whatever you like Wink

Glad I could help!

Have a good one.

Regards

David




Theme © iAndrew 2016 - Forum software by © MyBB