Monday, March 29, 2010

Re: Newbie question for "best practice" on how to combine CakePHP with a (given) design

To add to Jeremy's comments,

In your menu elements, you can refer to the present location with
$this->here, so you can have logic for showing/hiding submenus, etc.
and avoid having to create separate layouts for each menu situation.

For my login_prompt element, I check if the user is already logged in
like this:

if (!$session->read('Auth.User'))
{
// show "login" link
}
else
{
// show "logout" and "profile" links
}

If your users table has an "admin" column (0 or 1) you can do if
($session->read('Auth.User.admin')) to test whether you should include
admin-specific links or whatever. Note that User is uppercase, as
that's the name of the model. In your controllers, though, you'd use
AuthComponent's user() method: $this->Auth->user('admin').

For including disparate bits of code you can place several $this-
>element() calls and use requestAction() in the elements. Make sure
you have caching enabled in core.php and specifify that you want the
element to be cached because each requestAction() call creates an
entirely new request through Cake, which is expensive. By caching the
element you avoid doing that each time. See this article:

http://bakery.cakephp.org/articles/view/creating-reusable-elements-with-requestaction

Or search for "cakephp requestaction cache" or similar.

On Mar 29, 8:49 am, janitor048 <janitor...@googlemail.com> wrote:
> Hi there,
>
> I'm pretty new to CakePHP (and MVC in general for that matter) and I'm
> just working through the docs etc.
> And since the cookbook is quite informative, I think I've got a pretty
> good idea of what CakePHP could do for me by now.
>
> However, I would like to ask a question on best or common practice on
> how to actually integrate my pieces of cake with a given design.
> So that I can keep these suggestions in mind when digging even deeper
> into the documentation.
>
> Say, I've got a webpage that features
> - a main "view" area in the center
> - a main menu at the top that stays constant over all pages
> - a side menu to the left that stays constant over some pages but does
> in general depend on the content of the central area
> - a small side area to the right with some login / admin bits-and-
> pieces.
>
> Pretty common and probably pretty close to the actual project I'm
> about to work on.
> The general layout as described above I would like to design using
> dreamweaver (for instance) and setting up a css formatted page using
> divs.
>
> The main toolbar would probably best go into a common cake layout
> file. But what about the rest? View files with elements for left menu
> and login-area on the right? Login stuff as an element and the left
> menu in layout files that are selected by the controller accordingly?
>
> Can I attach id-based css rules to a specific element created by a
> (say) form helper? For positioning purposes and the like..
>
> And finally: What is the best way to incorporate bits and pieces from
> different models / controllers into a single view? That would
> something like a summary page, e.g. showing the 5 latests news, the 3
> latest pictures and the most popular comments (or whatever you like)
> in different areas of a single page (as delivered to the user).
>
> Any hints and suggestions would be highly appreciated.
> Cheers,
> Oliver

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

To unsubscribe from this group, send email to cake-php+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.

No comments: