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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:01:26+00:00 2026-05-15T03:01:26+00:00

I am learning cakePHP, everything seems alright except that I am very confused of

  • 0

I am learning cakePHP,
everything seems alright except that I am very confused of
how to make use of the default.ctp and what should be put inside the Elements folder.

Here is the default.ctp file that I have been using since my very first lesson on learning cakePHP:
(I copied from this URL http://book.cakephp.org/view/96/Layouts)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php echo $title_for_layout?></title>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<!-- Include external files and scripts here (See HTML helper for more info.) -->
<?php echo $scripts_for_layout ?>
</head>
<body>

<!-- If you'd like some sort of menu to 
show up on all of your views, include it here -->
<div id="header">
    <div id="menu">...</div>
</div>

<!-- Here's where I want my views to be displayed -->
<?php echo $content_for_layout ?>

<!-- Add a footer to each displayed page -->
<div id="footer">...</div>

</body>
</html>

But the problem is that the layout will take effect to all web pages that I have created.
Let’s see the case that I have recently encountered.
In one of the .ctp files, I need to use JQuery function
and I need to ass some and tags in the .ctp file.
Here are the and tags I used:

<Script language="javascript">
$(document).ready(function()
{
// some functions here
});
</Script>

<style type="text/css">
{
#toppage{
 width:800px;
}

But when I followed the default.ctp file,
I noticed that these tags (i.e. <Style> and <Script>) happened to appear below the tag.
As far as I know, the and self-defined Javascript functions
should be put inside the tag of the HTML instead.
I have considered to add the <Style> and <Script> in the default.ctp file,
but then
these codes would appear in every web pages instead of just a particular web page.

Please help.

  • 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-15T03:01:27+00:00Added an answer on May 15, 2026 at 3:01 am

    If you could create an external stylesheet for page-specific styles and keep your JavaScript in a separate file as well, then you would be able to use the HTML helper in a view to insert a link tag to the stylesheet where the $stylesheets_for_layout variable appears in the layout, and a script tag to the JavaScript file in place of the $scripts_for_layout variable. To do that, pass an array with the inline key set to false as the second argument to the script() method or as the third argument of the css() method.

    echo $this->Html->script('extra-js', array('inline' => false));
    echo $this->Html->css('extra-css', 'stylesheet', array('inline' => false));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing an e-learning application using CakePHP. The problem is that I need
Will learning Codeigniter (or any framework for that matter such as CakePHP or Zend)
I have noticed that my site in Cakephp is very very slow. I have
I'm learning cakephp for some time and it's very nice, I'm using the cake
I just started using CakePHP, and am learning how to use Bake. Why does
I'm learning CakePHP, my first MVC, and I have a few best practice questions.
Learning some VBA. So far, I've constructed this piece of code which should allow
Learning a lot in my few years of programming that the best projects are
I am learning cakephp in an autodidact manner and I am a complete newbie
I am learning cakephp by myself. I tried to create a user controller with

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.