Welcome Guest, Not a member yet? Register   Sign In
Setting Flash Vars in the Model
#1

[eluser]SirSickboy[/eluser]
Howdy everyone

I'm currently building a cms using code igniter (who isn't? ;-) ) and have found myself evaluating a response from my model in the controller and setting flash vars accordingly. It strikes me that this is a bit daft as my model is in a better position to give an idea of what's happening.

For example i've got a save_page method in my cms model which calls on another method in that model _page_exists which returns true or false. If false the model tries to save the page and if all is ok the model returns true back to the controller. At no point does the controller know the outcome of _page_exists and can only evaluate what save_page has sent back to it. This is the point where i feel that the model should be setting the flash vars but i'm just wondering if i'm going about it the right way.

Any thoughts would be much appreciated.

Cheers
#2

[eluser]wiredesignz[/eluser]
Models are a representation of data. That is their only purpose. Your Controller should set flash variables based on the result returned from your Model.
#3

[eluser]SirSickboy[/eluser]
That's precisely my opinion.

I've decided to extend the validation class with my page_exists method which, imo, is the most suitable place for it.
#4

[eluser]wiredesignz[/eluser]
Good choice, and welcome to the CI forums. Wink




Theme © iAndrew 2016 - Forum software by © MyBB