Cakephp Classroom image

osdyui
 
To post your Question Join Classroom
 
Lesson Topics's No:-  First|1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9|Last
Lessons:-Views

Blocks replace the deprecated $scripts_for_layout layout variable. Instead you should use blocks.
The HtmlHelper ties into view blocks, and its script(), css(), and meta() methods each update
a block with the same name when used with the inline = false option:

<?php
// In your view file
$this->Html->script('carousel', array('inline' => false));
$this->Html->css('carousel', array('inline' => false));
?>
// In your layout file.
<!DOCTYPE html>
<html lang="en">
<head>
<title><?php echo $this->fetch('title'); ?></title>
<?php echo $this->fetch('script'); ?>
<?php echo $this->fetch('css'); ?>
</head>
// Rest of the layout follows

The HtmlHelper also allows you to control which block the scripts and CSS go to:

// In your view
$this->Html->script('carousel', array('block' => 'scriptBottom'));
// In your layout
echo $this->fetch('scriptBottom');

Layouts

A layout contains presentation code that wraps around a view. Anything you want to see in all of your views
should be placed in a layout. CakePHP’s default layout is located at /app/View/Layouts/default.ctp. If you want to change the overall look of your application, then this is the right place to start, because controller-rendered view code is placed inside of the default layout when the page is rendered.

Other layout files should be placed in /app/View/Layouts. When you create a layout, you need to tell
CakePHP where to place the output of your views. To do so, make sure your layout includes a place for
$this->fetch('content') Here’s an example of what a default layout might look like:

<!DOCTYPE html>
<html lang="en">
<head>
<title><?php echo $this->fetch('title'); ?></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 $this->fetch('meta');
echo $this->fetch('css');
echo $this->fetch('script');
?>
</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 $this->fetch('content'); ?>
<!-- Add a footer to each displayed page -->
<div id="footer">...</div>
</body>
</html>

The script, css and meta blocks contain any content defined in the views using the built-in HTML
helper. Useful for including JavaScript and CSS files from views.

The content block contains the contents of the rendered view.
$title_for_layout contains the page title. This variable is generated automatically, but you can override it by setting it in your controller/view as you would any other view variable.

You can create as many layouts as you wish: just place them in the app/View/Layouts directory, and
switch between them inside of your controller actions using the controller or view’s $layout property:

// From a controller
public function admin_view() {
// Stuff
$this->layout = 'admin';
}
// From a view file
$this->layout= 'loggedin';

For example, if a section of my site included a smaller ad banner space, I might create a new layout with the smaller advertising space and specify it as the layout for all controllers’ actions using something like:

class UsersController extends AppController {
public function view_active() {
$this->set('title_for_layout', 'View Active Users');
$this->layout = 'default_small_ad';
}
public function view_image() {
$this->layout = 'image';
// Output user image
}
}

CakePHP features two core layouts (besides CakePHP’s default layout) you can use in your own application: ‘ajax’ and ‘flash’. The Ajax layout is handy for crafting AJAX responses - it’s an empty layout. (Most AJAX calls only require a bit of markup in return, rather than a fully-rendered interface.) The flash layout is used for messages shown by Controller::flash() method.

Three other layouts, xml, js, and rss, exist in the core for a quick and easy way to serve up content that isn’t
text/html.

 
 
 

osdyui

Skills    Cakephp

Qualifications :-
Location :-,,,
Description:-
Explore
 

  Students (0)