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 508057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:52:04+00:00 2026-05-13T06:52:04+00:00

I’m busy building an MVC application in PHP using Kohana MVC framework, and it

  • 0

I’m busy building an MVC application in PHP using Kohana MVC framework, and it works very well. But there are some small annoyances which I’d like to address.

A lot of logic is repeated across actions in controllers and controllers themselves. I’ve been thinking about it, and I thought it would be smart to define an object which contains this shared logic, so it doesn’t get repeated.

Then I heard about view-models in some podcasts and on Preventing mission creep in your Views, or, ignorance is bliss. So view-models are what I was looking for.

But now comes the question, what do you put in the view-models. My idea was that I let the view-model gather all the information the corresponding view needs. This has the advantage that every controller/action just needs to pass the input data to the view-model, and then pass it to the view.

Is this a smart idea? On behalve of testing, it would be smart to pass the model to the viewmodel so it’s possible to mock it. But I’m not really using models. In stead, I let the controllers access the database via Doctrine ORM. Translating every query to a seperate method seemed a little awkward, but maybe I’m missing something.

From what i’ve heard about view-models, they’re just plain DTO’s. But what’s the advantage of that in a dynamically weakly typed language?

Maybe I’m on the wrong track entirely and should be doing it different. What are your thoughts about this?

Edit:

Most of the logic I’m talking about is gathering the right information and passing it to the right views.

An example:

I have a customer controller. These have two actions: add and edit. For these two actions, I use the same view. In both actions, the same variables for the view are assigned. In the add action, when the form is not valid, the input variables are passed to the view again. In the edit action, the existing values are passed trough. This is a big duplication which I’d like to address.

  • 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-13T06:52:05+00:00Added an answer on May 13, 2026 at 6:52 am

    Repeated logic is an indication that some refactoring is needed, you don’t say what that loic is so we can’t be sure where you refactor it to, but Do Not Repeat Yourself is a useful principle. So original idea is good. I wonder whether your direct interaction from Controller to DB (ie. the lack of a Model) is part of the reason for duplication?

    View Models are more than DTOs. They contain (or point to) Business Data and also have the relevent interpretation logic. In the “mission creep” article you reference you see the idea. The View itself wants to know whether to display a link. That decision is based on various pieces of business data. You pull together that logic in a simple showLink() method. Then the view can focus on presentation and the viewModel can focus on the interpretaion. And, also important, the actual Business Data itself has no idea about the presentation.

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

Sidebar

Ask A Question

Stats

  • Questions 261k
  • Answers 261k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Doing SQL queries in a for loop 15k times is… May 13, 2026 at 11:36 am
  • Editorial Team
    Editorial Team added an answer With public fields, there would be no way for proxying… May 13, 2026 at 11:36 am
  • Editorial Team
    Editorial Team added an answer Try granting full access permissions to the ASP.NET account (Network… May 13, 2026 at 11:36 am

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want use html5's new tag to play a wav file (currently only supported
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I've got a string that has curly quotes in it. I'd like to replace
In order to apply a triggered animation to all ToolTip s in my app,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.