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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:37:54+00:00 2026-06-02T12:37:54+00:00

I have a simple web application with database tables orders and products that I’m

  • 0

I have a simple web application with database tables orders and products that I’m reworking with CakePHP. There are more, but for simplicity, I’m using just these two here. In the web app, I’d like to be able to search items, search orders, and do order-related jobs, but I’m having difficulty setting up and choosing components to use to make this web app. As an example to my problem, I have the following page. Check out the layout below.

|------------------------------|   
|            My App            | 
|------------------------------|
|Search <--| search order      |
|Orders    | search product    |
|etc.      |                   |
|          |                   |
|          |                   |
|------------------------------|

Figure: left navigation bar and body shown. Arrow denotes page we’re on.

  1. Controllers: for this search page, which controllers should be used? I’m defaulting to PagesController for static pages right now, but should this search page really use PagesController? I also have ProductsController and OrdersController that were created when I created Product and Order models, but it seems more appropriate to use a completely new controller, perhaps one called SearchController. This way the URL stays under myapp/search/... and doesn’t go all over the place. Is this the proper way? (I know I can rewrite URLs, but that’s for later)

  2. Models and actions: I have Product and Order models. Each of these models have a search logic for its respective DB table. If a new controller was created for the above page, then that controller can simply use these models’ actions right? I’m reading controller and model separation is completely normal and actually a good thing. At first I thought they went together, but the more I familiarize with CakePHP, it seems to be the opposite.

  3. If my approach (from 1 and 2) is not inefficient, wrong, or improper, could you suggest a good structure to set this specific page up with respect to what controllers to use and how the controller should be using models and their actions?

  • 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-06-02T12:37:57+00:00Added an answer on June 2, 2026 at 12:37 pm

    TLDR:

    The real answer is – personal preference. It’s not a big deal either way whether you create a SearchesController or use the ProductsController and OrdersController (but don’t use PagesController).

    My preference and reasoning

    I would create a SearchesController. This just makes the most sense for organizational purposes. All your search functionality can be in the same controller, all your search views will be in the “Views/Searches/” folder, and any/all related css and javascript can be in /css/searches or /js/searches/ (if you like to organize that way like I do).

    You’ll also want to make a Search model (Models/Search.php) and within it, add: public $useTable = false; [details] to tell it you aren’t going to make a searches table.

    Within each of the SearchController’s actions like function orders() and function products(), you can use $this->loadModel('Order'); [details], to make those models accessible from the SearchesController, then run your searches.

    To stick with the “Fat Models, Skinny Controllers” mantra, I recommend keeping your controller code small – something like this:

    $opts = array('limit'=>5);
    $orders = $this->Order->search($string, $opts);
    

    Then, in your Order model (per this example), do the meat of the logic (below is rough idea):

    public function search($string = null, $opts = null) {
        $params = array();
        $params['limit'] = 10; //sets default
        if(!empty($opts['limit'])) $params['limit'] = $opts['limit'];
        //... build options, contains, limits...etc
        return $this->find('all', $params);
    }
    

    Keeping all your controller actions together allows you to more easily make sweeping changes – like if you want to set a single variable for results per page that changes all your search pages…etc. I’m sure there are a lot of other ideas, but bottom line, it’s keeping similar code together.

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

Sidebar

Related Questions

I have a really simple ASP.NET web application and a web setup project that
I have a web application that loads some 50 tables from SQL Server into
I have an extremely simple web application running in Tomcat using Spring 3.0.2, Hibernate
We have a very simple ASP.NET web application comprising mostly static content and a
I have a war file which is a simple dynamic web application where I
In my web application, I have users input a date in a simple textbox.
A simple question. I have an ASP.NET web application which contains several assemblies and
I need to implement a simple logging mechanism for my web application. I have
I have a web application that I am currently working on that uses a
I have a simple web application in which I have created a wizard, each

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.