Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6975745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:24:29+00:00 2026-05-27T17:24:29+00:00

In our setup, we have models+mappers for all db objects. Then there are controller

  • 0

In our setup, we have models+mappers for all db objects. Then there are controller actions which prepare model objects for respective actions based on business logic.

We have send entire model object to the view and if view (html) wants to show first name, it can call $obj->getFirstName() or if some other view (pdf) can even call $obj->getFullName(). Is this how it is supposed to be done?

What if country was left empty and the view ignorantly calls $obj->getCountry()->getISO3Code() will be fatal since getCountry() returned false instead of a expected country object.

One option is to bother the view with IF.. etc so it is made safe. but does it not defeat the purpose that views should be dump without logic? or maybe I over stressed it.

should we send the entire model object to the view (as now) or safely prepare and send a array of viewable fields? It kinda it makes the action to be aware how PDF view looks like and html view looks like, again maybe defeating controllers purpose.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:24:30+00:00Added an answer on May 27, 2026 at 5:24 pm

    I confess that I struggle with the same question. When the controller/action sets values in the view – $this->view->someKey = 'someValue' – then there is an implicit expectation that that the controller is aware of what the view requires. I guess the general idea is that this is ok; the view is responsible for how to render the data it is passed.

    There is nothing wrong with using if statements inside your view-scripts. It is pretty common to see something like:

    <?php if ($someCondition): ?>
    <!-- some markup here -->
    <?php endif; ?>
    

    in a view-script. For example, take a look at the partials associated to a pagination control.

    I have created view-model objects – kind of a read-only version of my model intended for use in a view – that permits me to do things in a view-script that are a bit cleaner. For example, you could have a view-model object with a method like hasCountry(), so that your view-script could do something like:

    <?php if ($viewmodel->hasCountry()): ?>
    <p>Country: <?= $model->getCountry()->getISO3Code() ?></p>
    <?php endif; ?>
    

    Kind of a trivial example, but for more complex logic about the entity I am trying to render, I find that a view-model like this provides a home for some of that rendering-specific logic that doesn’t feel right in the controller and seems a bit complex for a view-script.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have just setup our hudson server to build .NET projects which seems to
We have our custom setup.exe program which launches a series of individial MSIs in
Our setup as follows: We have a local development server running Ubuntu, with a
Our VSS setup is like this: We have a set of unique folders with
I am not using github. We have git setup on our machine. I created
We have CC.NET setup on our ASP.NET app. When we build the project, the
I have a rather complicated deploy setup for our Drupal site that is a
We have a setup here that is less than ideal, We have our webserver
Background: We have a TFS server setup where me manage our source code and
I have a project to setup an anonymous feedback form to our website. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.