Welcome Guest, Not a member yet? Register   Sign In
PHP objects
#3

[eluser]TWP Marketing[/eluser]
[quote author="ndriana" date="1348354389"]Hi,

I am fairly new to MVC and ci in general. I don't understand why the view can change a model object. I think that it is logical that View is just the place where the templates are located.

But when I create a model object, say the header of the page (logo, horizontal nav, selected menu...) in the Controller, I(or the webdesigner) can change it when it is passed to View. Googling told that since PHP5, when you pass an object, it is always by reference.

But if it is changed in the view, my whole buisness logic in my Controller can be corrupted.

Namespace sounds a solution but I don't know how to do it.[/quote]

Well, like the doctor said, don't do that. Don't change a value in the view. Move that ability into your Controller and/or Model. The only way a view "should" effect your data is if you send data back to the Controller for processing, by placing an html link or send form data back in a POST or GET array. And even then, your code controls how that information is handled upon reading the input data.
When your view data is submitted (via a form or url), YOU control the code in the controller(s) and model(s) which process that data.

Do read about the MVC paradyme. The "view" does not "create a model object", at least in the sense of an MVC model file. The "view" isn't "the place where the templates are located", view(s) are the actual html code files (with some parsed php if you need it) which is passed to the server for rendering. Strictly speaking, a view does no data processing/manipulation, but that is a grey area. Some views need to use php loops to properly display dynamic data. But they only display the data, not change it.

Controller directs the data flow
Model reads the database (and manipulates that data if necessary)
View displays the data and takes user input


Messages In This Thread
PHP objects - by El Forum - 09-22-2012, 03:53 PM
PHP objects - by El Forum - 09-22-2012, 04:28 PM
PHP objects - by El Forum - 09-22-2012, 04:37 PM
PHP objects - by El Forum - 09-22-2012, 05:49 PM



Theme © iAndrew 2016 - Forum software by © MyBB