Warning: Illegal string offset '_imagedir' in /home/cakephpf/public_html/lofiversion/index.php on line 545

Warning: Illegal string offset '_emodir' in /home/cakephpf/public_html/lofiversion/index.php on line 546
CakePHP UnOfficial Community Forum > General Layout Question...
Help - Search - Member List - Calendar
Full Version: General Layout Question...
CakePHP UnOfficial Community Forum > Layouts and Design

gsolomonuk
Hi,

I have a feeling this may be a dumb question, I have been looking at CakePHP, I am new to MVC & am generally quiet impressed (the validation methods extremely cool), however, I have followed the blog tutorial and done some brief reading, I can't seem to find out how I can display multiple views to my user.

For example if I had a registration page & wanted to display the registration form in the center, a menu on the left, and a list of most recent news on the right, it obviously does not make sense to bundle all of these into one function/view.

I was wondering if someone could give me a brief explanation or point me to a tutorial that explains the best practice for this kind of scenario.


Many Thanks,
Graham Solomon
Sir P
HI gsolomonuk,

No, quite a good question and does take a bit of digging to find the answer when your new to cakephp dont sweat it.

The HTML for your registration form would be in /views/yourcontroller/register.ctp for example... and in the file /views/layouts/default.ctp (or whatever you have named your template) you would have your normal $content_for_layout that displays the reg form.. and then to display the menu or any other repeated chunks of HTML, use the Element system...

in /views/layouts/default.ctp..

[php]
echo $this->element('menu');
[/php]

and then create the menu html in /views/elements/menu.ctp

Let us know how you get on,

Cheers,



gsolomonuk
Thanks for that Sir P, I think a combination of elements and plugins thrown into the layout is what I am after.


Graham
Sir P
Good stuff...

You can pass data to elements too if needed, you can even set the cache of elements ..

[php]
$this->element('helpbox',
array(
"helptext" => "This is passed to the element as $helptext",
"foobar" => "This is passed to the element as $foobar",
"cache" => "+2 days", //sets the caching to +2 days.
"plugin" => "" //to render an element from a plugin
)
);
[/php]

More info on elements here .. http://book.cakephp.org/view/97/Elements

Chees,
AcakeFan
Hi Guys,

I have a something to add, I do the following in the default.ctp file layout :

if($this->action=="registration") { echo $this->element(menuleft); } else {echo $this->element(menuright);}


With this method you can layout elements precisely according to action and use one layout.


You can also switch layouts in actions by using :

var $layout = 'registration';

(assuming you have created registration.ctp in views/layout )


Let me know if this helps
wekko
QUOTE (AcakeFan @ Jan 7 2010, 04:38 PM)
Hi Guys,

I have a something to add, I do the following in the default.ctp file layout :

if($this->action=="registration") { echo $this->element(menuleft); } else {echo $this->element(menuright);}


With this method you can layout elements precisely according to action and use one layout.


You can also switch layouts in actions by using :

var $layout = 'registration';

(assuming you have created registration.ctp in views/layout )


Let me know if this helps

Why not just create 2 layouts for a left and right menu? Your solution let's the element depend on the action name, which might change or be re-used in a different controller.
ram4nd
This was very helpful, but how do you make controllers for elements?
Sir P
QUOTE (ram4nd @ Jul 24 2010, 12:47 PM)
This was very helpful, but how do you make controllers for elements?

Hi there,

You don't really make a controller just for an element.. I don't think... just get any data from your current working controller and send it through...

http://www.cakephpforum.net/index.php?show...findpost&p=6529
marshalrosy
Thanks for this thread. All of you have given very helpful information.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2014 Invision Power Services, Inc.
Lo-Fi 1.1 iDS Beta, Originally written by Matt,
re-written by Shaun Harrison, Layer 04.com, for pre IPB2.0 versions.