Welcome Guest, Not a member yet? Register   Sign In
MVC best practices, to display the models
#1

[eluser]Dready[/eluser]
Hello all,

I read some threads here about MVC best practices, on the subject of what part is responsible of displaying the model.

As I read I saw two "schools" :

* in the first one the view is responsible of displaying the model, and as so is "intelligent", which means the view embed PHP code.
* in the second one the controller is responsible of taking the model, extracting data, in general as an array, and then display with the help, for example of the parser class. In this case the view file has no PHP code, only {templates tags}.

On my own implementation of models, my models can return an array describing themselves and that can directly be used through the Perser class. To illustrate :

Code:
// somewhere in the controller
$myobject = new somethingModel($id);
$object_html = $this->parser->parse('some_view_file', $myobject->parser_array(), TRUE);

And of course, because things are not all that simple, I ended by adding a "template file" argument to the function, and so models can return their "string" output, be it in xml, html or whatever, directly :

Code:
// somewhere in the controller
$myobject = new somethingModel($id);
$object_html = $myobject->parser_array('some_view_file');

which means my models access to the parser class, some part of the view is managed by the controller (website layout, menus,...) and some other part by the model itself.

I'm asking you what do you think about this design, and what are the problems of doing like this ? Is it MVC-acceptable ?

Thanks for your opinions.


Messages In This Thread
MVC best practices, to display the models - by El Forum - 09-20-2008, 05:06 AM
MVC best practices, to display the models - by El Forum - 09-20-2008, 06:50 AM
MVC best practices, to display the models - by El Forum - 09-20-2008, 10:47 AM
MVC best practices, to display the models - by El Forum - 09-20-2008, 10:56 AM
MVC best practices, to display the models - by El Forum - 09-20-2008, 11:24 PM
MVC best practices, to display the models - by El Forum - 09-20-2008, 11:57 PM
MVC best practices, to display the models - by El Forum - 09-21-2008, 12:22 AM
MVC best practices, to display the models - by El Forum - 09-21-2008, 02:56 AM
MVC best practices, to display the models - by El Forum - 09-21-2008, 03:21 AM
MVC best practices, to display the models - by El Forum - 09-21-2008, 03:25 AM
MVC best practices, to display the models - by El Forum - 09-21-2008, 11:40 AM
MVC best practices, to display the models - by El Forum - 09-21-2008, 12:06 PM
MVC best practices, to display the models - by El Forum - 09-21-2008, 12:23 PM



Theme © iAndrew 2016 - Forum software by © MyBB