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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:20:52+00:00 2026-06-14T06:20:52+00:00

I would like an action in one of my controllers to output plain javascript,

  • 0

I would like an action in one of my controllers to output plain javascript, but I can’t find anything in the Book on the proper way to achieve this.

I’ve tried $this->response->type('js'); which does set the Content-Type: text/javascript; charset=UTF-8 but doesn’t change the layout to Layouts/js/default.ctp

I keep finding posts all over saying to use $this->RequestHandler->renderAs($this, 'js')
but it’s as if that method no longer exists: What’s the usage of app\views\layouts\js?

The only thing that has worked so far is $this->layoutPath = "js"; according to: How to change cakephp layout?

However, this article seems to be from Cake 1.3 days. Is this still the correct way to do switch to the js layout?

  • 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-14T06:20:54+00:00Added an answer on June 14, 2026 at 6:20 am

    RequestHandlerComponent::renderAs still exists:

    http://book.cakephp.org/2.0/en/core-libraries/components/request-handling.html#RequestHandlerComponent::renderAs

    Don’t forget to include the Request Handler component in your controller, and then it should work fine.

    public $components = array
    (
        'RequestHandler'
    );
    
    public function action()
    {
        $this->RequestHandler->renderAs($this, 'js');
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like vanity URLs for the #show action on one of my controllers.
I would like to handle a missing action in one of my controllers in
I would like to have a form that can submit to two different action
I have a action result method i would like to run. How can i
I would like to create one .erb file to be the output for a
i would like an index action to be able to take get and post
I would like that the Index action doesn't appear in the url. For example,
I would like to perform a different action when my app moves to the
What i would like to do is a simple button with an action method,
I would like to emulate the following interface: interface MultiSideEffectFunction<T> { void action(T first,

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.