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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:41:23+00:00 2026-06-07T03:41:23+00:00

I have some controllers in my Cake application, namely servers and users . I

  • 0

I have some controllers in my Cake application, namely servers and users. I want to write a simple API and have a controller called ApiController. Within this controller I want to use both the servers and users models.

I’m very new to Cake, but not MVC in general. From what I’ve picked up so far Cake will automatically use the servers model in the ServersController controller, I don’t know how to explicitly use a model from a certain controller.

Also, I want the API requests to only serve JSON without any HTML markup. I have a default layout that defines the header/footer of all my site pages and that gets outputted when I request an API function as well as the JSON from the view. How can I stop the layout from being output and instead just serve the view?

  • 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-07T03:41:27+00:00Added an answer on June 7, 2026 at 3:41 am

    You need to declare the $uses property in your controller see http://book.cakephp.org/2.0/en/controllers.html#controller-attributes

    The $uses attribute states which model(s) the will be available to the controller:

    <?php
    class ApisController extends AppController{
        public $uses = array(
            'User',
            'Server'
        );
    }
    

    Also you don’t appear to be following Cake naming conventions where controller names are plural (Apis or Servers) and model names are singular (Api or Server). These names should also be in CamelCase. See http://book.cakephp.org/2.0/en/getting-started/cakephp-conventions.html for more information

    Regarding the JSON, there is an Ajax layout you can use to help you server JSON requests. See http://book.cakephp.org/2.0/en/views.html#layouts for more information on how to achieve this.

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

Sidebar

Related Questions

I have a 3yr old application that has some controllers with some very unrestful
I have some controllers in my grails application:- LoginController LogoutController SearchableController cirnele.SearchAllController com.ten.cirnelle.domain.CustomerController com.ten.cirnelle.domain.ProjectController
I have some controllers I want to default to table and not index, as
i have some controllers, i want to put categories names into layout, like menu,
I have some CodeIgniter controllers which should only be accessed by users who have
I have a Rails 3 application of which some controllers are normal rails controllers
In my application i have some view controllers and one objective c class ,how
I have many controllers that will have some similar behavior, e.g. the user should
I have a View controller displaying some information (not table views). I have an
My site is open to all but i have a controller with some method

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.