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

  • Home
  • SEARCH
  • 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 513977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:28:36+00:00 2026-05-13T07:28:36+00:00

Rather than use a full-blown PHP MVC, I’m designing one that will best-fit my

  • 0

Rather than use a full-blown PHP MVC, I’m designing one that will best-fit my uses. I have the basic framework done, and have coded the models and controllers I’ll need to run my website.

Now I’m moving onto the Views, and I’ve encountered a small dilemma. My approach is working fine for me, but for future reference, I want to know if what I’m doing is a bad habit to get into.

What I’m trying to do:

In my View, I’m calling a Model that runs my authentication system, and requesting the login status of a user. I then use that boolean to decide whether to show certain elements within the view, and where to place others.

Should I be designing separate views for each login status, or is this approach fine? However, if I’m going to be implementing this MVC into the work I’m doing for my clients, I need to use the best practices.

Any advice would be appreciated!

  • 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-13T07:28:37+00:00Added an answer on May 13, 2026 at 7:28 am

    Can I call the model from the View?

    Yes, you can. As long as you maintain the separation of concerns between M,V and C, you are free to call upon the Model (or the Controller) from the View. Most MVC diagrams show a bidirectional connection at least between View and Model. What you don’t want to do though, is place logic/code from the Model (or the controller) into the View and you don’t want to modify the model from there.

    For example, you might have a widget on your page that aggregates the latest ten blog posts headlines from your favorite blogs on each page of your website. You get the headlines by calling, say MyFavFeeds::getLatest(); in your model. What are your options now?

    1. You could add the code to fetch the headlines into the controller, but that would require you to replicate it in each and every controller action, which is against the DRY principle. Also, the controller’s concern is handling user input for specific actions and fetching the headlines on each call is likely not even related to these actions.
    2. If your architecture supports it, you could fetch that data in some sort of preDispatch hook, that is, the headlines get loaded and injected into the View from a plugin or callback. That would be DRY, but a second developer might not be aware of that plugin and accidently overwrite the variable holding the headlines from his controller action. And there might be cases in which you wouldn’t want to load the headlines, e.g. when just rendering confirmation pages for form submissions, so you’d have to have mechanism for disabling the plugin then. That’s a lot to consider.
    3. You place the call to (not the code of) MyFavFeeds::getLatest() into the View or Layout template or, better, a ViewHelper, that encapsulates the call to your model class and renders the widget. This way you don’t have to worry about overwriting any variables or repetition. And when you don’t need the headlines on your view, you simply don’t include it.

    About your other question:

    In my View, I’m calling a Model that
    runs my authentication system, and
    requesting the login status of a user.
    I then use that boolean to decide
    whether to show certain elements
    within the view, and where to place
    others.

    Authentication is something you will want to do early in the application flow, before any controller actions are called. Thus, you should not run your (entire) authentication system in the View. The actual authentication is not View-related logic. Just requesting the user status after authentication, on the other hand, is okay. For instance, if you want to render a widget showing the user name and giving a login/logout button, it would be fine to do something like

    <?php //UserHelper
    class UserMenuHelper
    {
        public function getUserMenu()
        {
            $link = '<a href="/user/logout">Logout</a>';
            if(MyAuth::userHasIdentity()) {
               $link = sprintf('<a href="/user/logout">Logout %s</a>',
                                MyAuth::getUsername());
            }
            return $link;
        }
    }
    

    If you got larger portions of your GUI to be modified by a User’s role, you might want to break your View apart into partial blocks and include them based on the status, instead of writing all the HTML into a View Helper.

    If you are only looking to render a navigation based on the user role, have a look at Zend Framework’s Zend_Navigation and Zend_Acl to see how they do it.

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

Sidebar

Related Questions

I'm working with an incorrectly built spring application. Rather than use IOC, objects that
Has anyone used Lucene.NET rather than using the full text search that comes with
After working with .NET's HttpWebRequest / Response objects, I'd rather shoot myself than use
I want to use the new report builder 2.0, rather than the old VS2005
I'm developing an operating system and rather than programming the kernel, I'm designing the
Rather than population said DOM object with an external page such as HTML CFM
Rather than scraping a Ruby version of this algorithm off the net I wanted
(This is a question about the UI rather than the technology required to do
Does creating an object using reflection rather than calling the class constructor result in
Using C# and WPF under .NET (rather than Windows Forms or console), what is

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.