Welcome Guest, Not a member yet? Register   Sign In
Confused by senior developer by talk of objects in a view

[quote author="mddd" date="1281466111"]I think you have to separate form from function here.

The MVC principle means that you try to keep the 'smart bits' of your website (checking if a user is logged in, getting things from the database etc) out of your views. The model is the place to do those things. The view is simply for displaying things.

This is different than saying you should not use objects in your view. There's nothing wrong with that. Just don't be tempted to do complicated things to those objects. If you need to save a password for a user, do it in the model. But if you pass a "user" object from the controller to the view, it's fine to use $user->is_logged_in() to check if the user is logged in. That is not really any different from doing " if ($user_logged_in) { ... } ".[/quote]

Hi everyone,

I agree, I always try to make my views as simple as possible, with the complexity of things at controllers and models. The most information ready to show in view, better. The only exception in my projects are session information, because they are already in session, then isnĀ“t necessary to pass they to the view. And yes you can have a any kind of variable at view that is an object but avoid to call database things directly from view :-) Hope can help, good luck!

Messages In This Thread
Confused by senior developer by talk of objects in a view - by El Forum - 08-10-2010, 08:16 AM

Theme © iAndrew 2016 - Forum software by © MyBB