Welcome Guest, Not a member yet? Register   Sign In
CI Database and Sessions - Coding advice
#1

[eluser]evstevemd[/eluser]
I'm still baby boy when it comes to MVC
I would like someone to advice me on how I can Load My Data using model/Controllers without clogging Views. Also I have question on how sessions are hold in CI. I know how they go in PHP Smile

Thanks
#2

[eluser]WanWizard[/eluser]
Sessions in CI work similar to the one's in PHP.

The difference is that CI stores sessions in a database table, not in the filesystem, you don't have to manually start your session, and you access the session store not via $_SESSION, but via the methods mentioned in the user guide.

I'm not sure what you mean by 'clogging views'. You're supposed to keep the amount of code in a view to a minimum, only the code needed to generate your markup. You prepare that data to be passed to the view in your controller, assisted by model methods to do the 'dirty' work (to keep your controllers tidy).
#3

[eluser]evstevemd[/eluser]
[quote author="WanWizard" date="1281579784"]Sessions in CI work similar to the one's in PHP.

The difference is that CI stores sessions in a database table, not in the filesystem, you don't have to manually start your session, and you access the session store not via $_SESSION, but via the methods mentioned in the user guide.[/quote]
So Have I to define specific table or just DB settings in database.php is enough?

[quote author="WanWizard" date="1281579784"]I'm not sure what you mean by 'clogging views'. You're supposed to keep the amount of code in a view to a minimum, only the code needed to generate your markup. You prepare that data to be passed to the view in your controller, assisted by model methods to do the 'dirty' work (to keep your controllers tidy).[/quote]
I mean to clog with messy codes.
I know how to write view and controllers but I get difficult when it comes how to interact with the Whole M-V-C thing Smile
#4

[eluser]WanWizard[/eluser]
You have to create a table, and configure sessions you use that table (in application/config/config.php). See the user guide on the fields that need to be in the session table.

CodeIgniter doesn't give you any restrictions on how you want to apply the MVC pattern. In general, most people opt for a slim-controller, fat-model approach, in which the controller defines a data array to be passed to the view, and model methods providing the informating going into the array. If your models do the job properly, all the view has to do is to display it, using at most a few foreach() and if() statements. Shouldn't get any messier than that.
#5

[eluser]evstevemd[/eluser]
[quote author="WanWizard" date="1281645765"]You have to create a table, and configure sessions you use that table (in application/config/config.php). See the user guide on the fields that need to be in the session table.

CodeIgniter doesn't give you any restrictions on how you want to apply the MVC pattern. In general, most people opt for a slim-controller, fat-model approach, in which the controller defines a data array to be passed to the view, and model methods providing the informating going into the array. If your models do the job properly, all the view has to do is to display it, using at most a few foreach() and if() statements. Shouldn't get any messier than that.[/quote]
That i clear now to me
I think I will follow this approach
"Do messy code in Models and Do data loading in Controllers"
Thank you




Theme © iAndrew 2016 - Forum software by © MyBB