1

When we are working with some MVC FW on PHP, generally we have a view loading function like load(string viewName, optional array viewVariables). My doubt here is: if we are working with some object, like a table row result, we need pass this object entirely to view or we need pass only what will be need on view?

Example I: pass object entirely.

$data["text"] = $text_object;

load("text_view", $data);

For this case, the view will can access the public property of text object (like title, text and date created). But I need create a getter for property, or I can access it directly? And if the property name has to change?

Example II: pass only what will be need on view

$data["title"] = $text_object->title;
$data["text"] = $text_object->text;
$data["date_created"] = $text_object->date_created;

load("text_view", $data);

In this case, the controller is responsible for sending only what is necessary to view. However, the maintenance becomes a little more complicated, because new information in view also requires a new definition of variable in the controller.

Anyway, I wonder what would be the most acceptable concept for this type of task. Note that I am not talking about coding, and yes, the concept that will be used to develop something similar.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.