You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently the 4-full version uses one model per controller, this means for example a controller Animal uses the animal_model (automatically). I've seen this quite often in several frameworks, but it has the huge disadvantage that only one model can be used at a time.
A more professional architecture would be to let the developer decide which models he/she wants to use in the controller (manually), and
pass all models to the view or
collect data from all models in a $var (let's call it... ehmm.. $model) and pass this $model to the view
I've seen solution #2 in Grails (which is a framework for Groovy), obviously this is also used in other frameworks.
My questions to all of you:
a.) Does anybody know how what the professional name of $model is ? I mean, is THIS the model or are the two used models the models ? Hmm.. it's hard to describe this...
b.) What would be the most professional way to do this ? Is there a definitive way to do this ?
Code of current behaviour:
class Overview extends Controller
{
function__construct()
{
parent::__construct();
}
functionshowUserProfile($user_id)
{
// model is automatically loaded (by the Controller from which we extend)// result of the getUserProfile() method is passed to view property$this->view->user = $this->model->getUserProfile($user_id);
$this->view->render('overview/showuserprofile');
}
}
What the new behaviour could look like (partly pseudo-code):
class Overview extends Controller
{
function__construct()
{
parent::__construct();
}
functionshowUserProfile($user_id)
{
// manual loading of model #1$overview_model = newOverview_model();
// manual loading of model #2$foo_model = newFoo_model();
// create empty container for model data$model = array();
// get data from model #1, pass it into an empty variable $model (?)$model["user_profile_data"] = $overview_model->getUserProfile($user_id);
// get data from model #2, pass it into an empty variable $model (?)$model["example_foo_data"] = $foo_model->doStuff($user_id);
// pass the $model to the view (maybe not necessary)$this->view->render('overview/showuserprofile', $model);
}
}
The text was updated successfully, but these errors were encountered:
Like I mentioned before, you could accomplish this by autoloading your models. this way you don't have to require your model classes. also I don't see why it is useful to pass the model in the render function. first of all, the name $model (array) is not suitable because it does not contain models but data returned by the models instead. So a more suitable name would be $data= array(). This array contains all data returned by all models. Then just pass the data array to the view the normal way...like so
this->view->data= $data;
Done in develop branch! Models are NOT autoloaded, they can be easily loaded within a controller with $x = load_model('mymodel');, $x now contains a new mymodel object. A controller can now load multiple models at once. All models share one database connection btw ;)
Currently the 4-full version uses one model per controller, this means for example a controller
Animal
uses theanimal_model
(automatically). I've seen this quite often in several frameworks, but it has the huge disadvantage that only one model can be used at a time.A more professional architecture would be to let the developer decide which models he/she wants to use in the controller (manually), and
I've seen solution #2 in Grails (which is a framework for Groovy), obviously this is also used in other frameworks.
My questions to all of you:
a.) Does anybody know how what the professional name of
$model
is ? I mean, is THIS the model or are the two used models the models ? Hmm.. it's hard to describe this...b.) What would be the most professional way to do this ? Is there a definitive way to do this ?
Code of current behaviour:
What the new behaviour could look like (partly pseudo-code):
The text was updated successfully, but these errors were encountered: