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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:23:02+00:00 2026-05-26T23:23:02+00:00

I read about the concept fat model and skinny controller. I certainly would like

  • 0

I read about the concept “fat model and skinny controller”. I certainly would like to follow this concept.

Right now, all my controllers are fat and my models are skinny. I have a lot of find stmts (queries) in controllers that I would like to move to the models. But I have no idea on how to do it.

In which function of the model am I supposed to put the find statements? and after the set stmts in the model, will I be automagically able to view that data in the respective view?

Can someone please give me an example? I have already gone through the cakephp cookbook blog sample. And over there the find stmts are in the controller instead of the model. The model only contains the relationships and validations. I’m yet to see a model example containing find stmts.

  • 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-26T23:23:03+00:00Added an answer on May 26, 2026 at 11:23 pm

    The answers which have been given answer part of your question. You can use the find method without the Model class declaration (so $this->find() instead of $this->Model->find()).

    To adhere to the “fat models, skinny controllers” principle, your models should hold most of the business logic of your application, while the controllers handle the data from the model that’s used by your views.

    So, if you want to have all the find logic happening in your models, you should do the following.

    Product.php:

    <?php
      class ProductModel extends AppModel {
        //Associations, etc. go here
    
        function getProducts($limit=5) {
          $products = array();
          $products = $this->find('all', array('limit' => $limit));
          return $products;
        }
      }
    ?>
    

    Note that you cannot use $this->set() in your model, you should use it in your controller:

    ProductsController.php:

    <?php
      class ProductsController extends AppController {
        //Components, helpers, etc. go here
    
        function index() {
          $products = $this->Product->getProducts(10);
          $this->set('products', $products);
        }
      }
    ?>
    

    A populated $products variable (if there are records in the revelant database table) will now be available in you view.

    This is a great article detailing the concepts of Cake and there’s another one in the Cookbook on MVC in general.

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

Sidebar

Related Questions

Ive read about it and to be honest it all seems like a bunch
I like what I read about Lift , and I like the concept of
I try to develop my own little framework. For this, I'd like to read
I just read this post about really nasty (and cool at the same time)
I read all over the Internet (various sites and blogs) about version control. How
I have just been thinking about the concept of view model object we create
I'm fairly new to DDD and have read a few articles about the concept
Read about Server push here . I want to push data to client from
I read about the Conditional attribute today. According to MSDN: Applying ConditionalAttribute to a
I read about using the CASE expression inside the WHERE clause here: http://scottelkin.com/sql/using-a-case-statement-in-a-sql-where-clause/ I'm

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.