On Jan 2, 2007, at 12:49 PM, PHPBABY3 wrote:
anselm wrote:
> 1. Create a button that will appear on all pages in the
application at
> a particular location using CSS, and that does as follows.
If you want your button to appear on all pages at the same place,
then
the easiest is to put the button as part of your layout. Your default
layout goes in app/views/layout/default.thtml -- see this part of the
manual to lear more about views and about layouts :
http://manual.cakephp.org/chapter/views
I have some questions (numbered):
CakePHP: The Manual
Views
Section 1
Views
A view is a page template, usually named after an action.
1. Is there a formal thing called a "page template" and this is
meant to invoke its known properties?
The definition of formal depends on context.
Also, is "action" a defined
formal term for something?
Again, this depends on your definition of formal. I've seen the same
thing coined as controller action, function, and method.
For example, the view for PostsController::add()
2. What does "PostsController::add()" represent?
(http://php.net/manual/en/language.oop5.paamayim-nekudotayim.php)
A call to the add function of the PostsController.
would be found at /app/views/posts/add.thtml. Cake views are quite
simply PHP files, so you can use any PHP code inside them. Although
most of your view files will contain HTML, a view could be any
perspective on a certain set of data, be it XML, and image, etc.
3. What do you do with these files?
View files? You place your presentational code inside them.
In the view template file,
4. Is that supposed to mean something, the "view template file"?
Yes. Its referring to the view template file at /app/views/
controller_name/action_name.thtml
Is that the verb "to view the template file"? Then we have
something called a template file and there s a file that when executed
displays it? Where is this explained?
Please clarify this question, as I'm not sure what you're asking here.
you can use the data from the corresponding Model. This data is passed
as an array called $data.
5. How do you do that and why?
Check the Controller::set() method in the API.
http://api.cakephp.org/
class_controller.html#8d64f371009811f1d5662a491ba5cf82
Any data that you've handed to the view using set() in the controller
6. What does "using set" mean?
http://api.cakephp.org/
class_controller.html#8d64f371009811f1d5662a491ba5cf82
is also now available in your view.
The HTML helper
7. What are HTML helpers?
http://manual.cakephp.org/chapter/helpers says:
"Helpers are meant to provide functions that are commonly needed in
views to format and present data in useful ways."
is available in every view by default, and is by far the most commonly
used helper in views. It is very helpful in creating forms, including
scripts and media, linking and aiding in data validation. Please see
section 1 in Chapter "Helpers" for a discussion on the HTML helper.
Most of the functions available in the views
8. How can I see a list of all of these functions with explanations?
http://api.cakephp.org/class_html_helper.html
are provided by Helpers. Cake comes with a great set of helpers
(discussed in Chapter "Helpers"), and you can also include your own.
Because views shouldn't contain much logic, there aren't many well
used
public functions in the view class. One that is helpful is
renderElement(), which will be discussed in section 1.2.
Layouts
A layout contains all the presentational code that wraps around a
view.
Anything you want to see in all of your views should be placed in your
layout.
Layout files are placed in /app/views/layouts. Cake's default layout
9. What does "default layout" mean?
Its the layout that is used unless another is specified.
http://manual.cakephp.org/chapter/views, see the Layouts section.
can be overridden by placing a new default layout at
/app/views/layouts/default.thtml. Once a new default layout has been
created, controller view code is placed inside of the default layout
when the page is rendered.
When you create a layout,
10. Why do we create a layout and where does t explain how to?
(http://manual.cakephp.org/chapter/views)
"A layout contains all the presentational code that wraps around a
view. Anything you want to see in all of your views should be placed
in your layout."
It reduces code duplication.
you need to tell Cake where to place your controller view code: to do
so, make sure your layout includes a place for $content_for_layout
(and
optionally, $title_for_layout).
11. What kind of thing is $content_for_layout?
It is a scalar variable, usually with string contents.
And why is
$title_for_layout optional?
A complete <title> element isn't required for a page to render in a
browser.
Here's an example of what a default layout might look like:
<!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">
</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>
To set the title for the layout, it's easiest to do so in the
controller, using the $pageTitle controller variable.
12. What is a controller variable?
A variable that is available to all methods of the controller class.
class CakeController extends AppController
{
var $controllerVar = 'value';
}
class UsersController extends AppController
{
function viewActive()
{
$this->pageTitle = 'View Active Users';
}
}
You can create as many layouts as you wish for your Cake site, just
place them in the app/views/layouts directory, and switch between them
inside of your controller actions using the controller's $layout
variable, or setLayout() function.
13. What is the controller's $layout variable and setLayout()
function?
See answer to #12 and http://api.cakephp.org/
class_view.html#4d78a964abdf60dea723fbf558e1cab3 .
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 controller's actions using
something like:
var $layout = 'default_small_ad';
Elements
Many applications have small blocks of presentational code that needs
to be repeated from page to page, sometimes in different places in the
layout. Cake can help you repeat parts of your website that need to be
reused. These reusable parts are called Elements. Ads, help boxes,
navigational controls, extra menus, and callouts are often implemented
in Cake as elements. An Element is basically a mini-view that can be
included in other Views.
Elements live in the /app/views/elements/ folder, and have the .thtml
filename extension.
The Element by default has no access to any data. To give it access to
data, you send it in as a named parameter in an array.
14. What does it mean to give an element access to data, and to
send it
as a named parameter in an array?
It means that your element can have dynamic data associated with it.
Instead of just:
<p>This is John's paragraph</p>
You can also have
<p>This is <?php echo $name; ?>'s paragraph</p>
In elements.
Calling an Element without parameters
<?php echo $this->renderElement('helpbox'); ?>
Calling an Element passing a data array
<?php echo
$this->renderElement('helpbox', array("helptext" => "Oh, this text is
very helpful."));
?>
Inside the Element file, all the passed variables are available as the
names of the keys of the passed array (much like how set() in the
controller works with the views). In the above example, the
/app/views/elements/helpbox.thtml file can use the $helptext variable.
Of course, it would be more useful to pass an array to the Element.
Elements can be used to make a View more readable, placing the
rendering of repeating elements in its own file. They can also help
you
re-use content fragments in your website.
15. What in general do you input into CakePHP?
User requests, database tables, RSS feeds, LDAP data... anything.
How do you use it after
you do all the input to set it up? What are the options that you can
use in order to run the application then?
Please clarify and narrow the scope for these last questions, as they
are too broad to address.
-- John
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---