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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:13:43+00:00 2026-05-27T05:13:43+00:00

I am new to Cake PHP and I had a website with regular PHP

  • 0

I am new to Cake PHP and I had a website with regular PHP and HTML, but now I am switinching to use Cake PHP. The issue I am having is that it is not picking up the javascript for a slider I have on a menu. (But it works on the original web).

So I did the following steps, maybe you can see where I am making my mistake.

First I put the Javascript file under webroot/js

FILE javascript.js

/**
 * 
 */
$(document).ready(function() {

    //ACCORDION BUTTON ACTION   
    $('div.accordionButton').click(function() {
        $('div.accordionContent').slideUp('normal');    
        $(this).next().slideDown('normal');
    });

    //HIDE THE DIVS ON PAGE LOAD    
    $("div.accordionContent").hide();

});

Then I went to AppController and added the following line under cake/libs/controller/app_Controller

class AppController extends Controller {
    var $helpers = array('Html', 'Form', 'Javascript');
}

Then, that change allowd me to add it to layout

 FILE mylayout.ctp

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <?php

       $javascript->link('javascript.js');
</head>

<?php include 'menu_nav.php';?> //this has starting <body> tag
            <?php include 'leftmenu_nav.php';?>
             <div id="content" class="divContent">
              <div id="mainContent" class="divMainContent" style="text-align: left;">
            <?php echo $content_for_layout; ?>
               </div>   
               </div>
            <?php include 'footer.php';?> //this had end </body> tag
</html>

Now somewhere in the

$content_for_layout

there some <divs> that make use of the JS, but for some reason 1) I do not see the JS markup when i do page source and 2) It is not sliding like it used to..

Can anyone please tell me what I may be missing in this CakePHP config?.

Thank you

echo $this->Html->script('javascript.js');
         echo $this->Html->script('jquery-ui-1.8.16.custom.min.js');
         echo $this->Html->script('jquery.js');
         echo $this->Html->script('jquery.MetaData.js');
         echo $this->Html->script('jquery.min.js');
         echo $this->Html->script('jquery.rating.js');
         echo $this->Html->script('jquery.rating.pack.js');
         echo $this->Html->script('jquery.validate.js');
         echo $this->Html->script('paging.js');
         echo $this->Html->script('ui.datetimepicker.js');
         echo $this->Html->script('format.js');
  • 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-27T05:13:44+00:00Added an answer on May 27, 2026 at 5:13 am

    There are a couple of things you need to check.

    First, don’t change anything in the cake folder. That is a big no no. If you want to have an app controller, simply create a new file name app_controller.php and put it in your /app folder. Add the following code in it.

    class AppController extends Controller {
       var $helpers = array('Html', 'Form', 'Javascript'); //what version are you using?
    }
    

    How you include the JS file depends on what version of cake your are using. The newer version uses the following syntax

    <?php echo $this->Html->script('script'); ?>
    

    http://book.cakephp.org/view/1589/script (1.3)

    Next, make sure that all the JS is actually being included. Look at the source and click through to the JS file to confirm that the file is loaded. I don’t see a jquery include anywhere so you should confirm that jquery is included in your layout.

    After that, confirm that the div.accordionButton div is contained in your view. Since it doesn’t look like it’s in the layout, open up the specific view element and check in there.

    As a last resort, add alert($('div.accordionButton').length) in your JS file to confirm that the JS is actually picking up the DIV from the view. If the alert shows 0, then this means that it’s not.

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

Sidebar

Related Questions

I am new to Cake PHP, in regular PHP I had a index.php and
I had a working cake application that I tar'd up and sent to someone
Upgraded a (dev) Cake PHP site and had to change database drivers from ADO
I am new to cake php and I have a plugin folder in my
I'm already into PHP and now I'm going to learn a new framework, because
I am relatively new to Cake PHP framework and was trying few things in
I am new to Cake PHP and this set up is giving me a
I am using cake php now. I have two file example1.ctp and example2.ctp. I
Hi i am new in cake php and can't solve the problem. The problem
I'm new to CakePHP but I've been though their FAQs and guides to no

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.