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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:22:36+00:00 2026-05-18T10:22:36+00:00

Im new to cakePHP, and Im wondering how a ‘live’ site does this. I

  • 0

Im new to cakePHP, and Im wondering how a ‘live’ site does this.

I see 2 possibilities :

1) There is one controller with a bunch of pages (functions) in its (extended) AppController.

2) There are many controllers, each with a small number of pages (functions) in its (extended) AppController.

(You probably get my question already, but Im going to say it in another way too)

Should I put my contact page in a separate controller than my blog page? (I have a hunch the answer is yes.) Why?

  • 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-18T10:22:36+00:00Added an answer on May 18, 2026 at 10:22 am

    You don’t need to create a controller for everything. In fact, you shouldn’t, because there are better ways around it. The more static pages you have, the more out of hand it can get.

    For Static Pages

    Copy pages_controller.php from the cake/libs/controller folder over to your app/controllers folder. Add the following piece of code to your display() action:

    function display() {
    
        ...
    
        $page = Inflector::slug($page);
        if (method_exists($this, $page)) {
            $this->$page();
        }
    
        $this->render(join('/', $path));
        return;
    }
    

    Then, modify your routes.php file to add the various static pages:

    Router::connect('/about', array('controller' => 'pages', 'action' => 'display', 'about'));
    Router::connect('/contact', array('controller' => 'pages', 'action' => 'display', 'contact'));
    

    Now, the contact form is a static page, but has some logic attached to it. So, you can head over to your PagesController and create an action specifically for this (or any other page that isn’t merely static):

    function contact() {
        if (!empty($this->data)) {
            ...
        }
    }
    

    Basically, the route directs your static page request to the PagesController’s display() action. The display action checks if a method of the same name exists. If it does, it executes that action and displays the pages/{page}.ctp view.

    For Non-Static Pages, eg. Blog

    Now, this definitely needs a model. In fact, multiple models (Post hasMany Comment, Post HABTM Tag). In order to manipulate and access these different models, it’s better that you place the code into a separate controller.

    A lot of people like to name their controllers based on their URLs. For example, they name their controller as BlogController if they want a URL such as /blog.

    A method that I prefer is using routing to get the URLs that I want, and keeping controllers named as per CakePHP conventions.

    Eg. A PostsController would control the Post model and related models. But if I wanted the /blog URL to display a list of all the posts, I would write a route to point it to /posts/index.

    Router::connect('/blog', array('controller' => 'posts', 'action' => 'index'));
    

    You can have additional routes too. Example: /blog/2010/06/10/whats-in-a-post to point to /posts/view/.

    Again, this is just an example of what’s possible. In the end, you should stick to the methods that you think helps keep your code organized for both you and your team.

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

Sidebar

Related Questions

I'm new to CakePHP but I've been though their FAQs and guides to no
I am creating a website in CakePHP and I am kind of new on
New to javascript/jquery and having a hard time with using this or $(this) to
New class is a subclass of the original object It needs to be php4
New to xml. Looking for XPath to search a xml file with python ElementTree
New to silverlight. Traditionally if I were to design a wizard-like process where a
New to both Ruby and Rails but I'm book educated by now (which apparently
New to WCF, but familiar with COM+ - can I wrap a WCF service
New to Linux programming in general. I am trying to communicate with a kernel
The new extensions in .Net 3.5 allow functionality to be split out from interfaces.

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.