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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:24:46+00:00 2026-05-13T21:24:46+00:00

When I have a controller, e.g. article I often have a action_view() that handles

  • 0

When I have a controller, e.g. article I often have a action_view() that handles most of the code.

Sometimes, it can become 80-100 lines long.

My controller usually handles all of these:

  • binding template variables
  • setting sessions (where appropriate)
  • sending emails
  • validating forms

I could see bit and pieces that I could make another private method in the controller, not necessarily for reuse, but for separation of concerns.

However, then it looks weird (to me) having methods which can be called via a route, and methods that are internal only.

Also some things say to me “I should be in the model, not the controller”. However, I’m not sure if that’s correct either.

In the end, I have a somewhat fat controller method that looks quite procedural.

Should I actually have a list up top of my action_* methods, and then separate the rest of my code into smaller modules?

I’ve got an example below… is this typical controller stuff, or should the sessions etc be in the model?

public function action_pdf($type, $id) {

        // Get PDF file from db and send headers to it
        $id = (int) $id;

        $pdfFile = $this->model->getPdf($id, $type);

        if ($pdfFile) {
           $this->request->redirect($pdfFile);
        } else {
           $this->session->set('pdfMissing', true);
           $this->request->redirect(Route::get('properties')->uri());
        }

    }

So, my question is, am I doing it wrong?

  • 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-13T21:24:46+00:00Added an answer on May 13, 2026 at 9:24 pm

    Your Models are there to encapsulate business logic and usually to abstract the data storage layer away from the rest of the architecture (controllers, views).

    What this means is that any database accesses (e.g. SQL queries) and such should ideally be contained within your models. Your controller will get its data from your models (this includes ORM, which exposes itself through models) without itself having to access the database directly.

    As far as email sending is I guess it depends on the situation. For example, when a user signs up I call a Model method to insert their details into the database. This method then triggers an email to be sent to them. This way I’m making the email sending an explicit part of the sign-up business logic (and that is what I want in this case) so no matter who calls the sign-up method in the model, the system won’t forget to send an email out.

    When it comes to form validation, I try and specify most of my validation rules in the ORM model classes. This is so that no matter who manipulates the model, the model always has some inherent understanding of how to validate its own data. And you’ll notice that the ORM model object already provides a method for validating its data. Any extra validation/callbacks the model does not inherently need to know about keep track off can be done outside the model code.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Divide the interval [0,1] in B-A+1 bins Example A=2, B=5… May 15, 2026 at 6:06 am
  • Editorial Team
    Editorial Team added an answer The answer is SetWindowLongPtr. It allows you to associate a… May 15, 2026 at 6:06 am
  • Editorial Team
    Editorial Team added an answer I'm using ContainerControlledLifetimeManager, and end up with a code like:… May 15, 2026 at 6:06 am

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.