tags:

views:

387

answers:

3

I just finished the "15 min Blog Post tutorial" included in the documentation for cakephp. I was asked for another tutorial to change the layout for first tutorial.

However, I am fairly new to MVC programming/Cakephp and I have no real clue how to do so. Well, I know I need "default.ctp" placed in app/views/layouts/ and I presume I need to include to include my data? . . .

I am really at a loss of what to do. I set up my default.ctp as I mentioned above, but when I go to localhost:9999/posts the layout is still the same. I guess I need to include a stylesheet (and if so, where?)

I guess if someone can point me in the right direction to a beginner's guide to layout styling or how to use it I would greatly appreciate any help.

A: 

I really recomend the CakePHP CookBook, easily found from the CakePHP homepage. Modifying default.ctp should edit your applications layout.

A more specific question (eg. code samples of your default.ctp, expected results etc) might help people provide a better answer than mine.

thomasfedb
Ah yes, I am sorry. Well I take it you are familiar with the 15 min blog post tutorial. I was asked to complete the said tutorial as well as create categories for theabove mentioned tutorial, which leaves me with localhost:9999/posts as well as localhost:9999/ categories (all with their own controllers, views, etc).. SO in the cookbook, I found where they were talking about how to use the layout structure by adding <?php echo $content_for_layout ?> to default.ctp . However, it doesnt seem to change anything.. DO you know how to add styling to this?
Louis Stephens
You will need to edit the default CSS file. Inside the 'webroot' directory i beilve, at least i think it was last time i used CakePHP (quite a while)...
thomasfedb
A: 

Lack of stylesheets has no impact here.

How MVC works in CakePHP:

  • The router dispatches an incoming request to an appropriate Contoller.

  • The appropriate Controller function executes (no output, just fetching data, setting up variables).

  • The appropriate view is rendered. In fact, the output of the view is just contained in $content_for_layout.

  • What you really get back in the browser is in the layout. Therefore you can put your view's output into the layout by echo $content_for_layout in default.ctp. (Of course you can also have different layouts.) In addition, the layout can be enhanced with elements.

sibidiba
Thanks guys. I got it working fairly quickly. As it turns out, Coda was set to hide extensions, so when I saved the file as default.ctp, it automatically was trying to save it as default.ctp.ctp (which I have had this issue before, and Coda likes to reset this on me).@Travis Leleu, Thanks! Yeah, I have been rereading the book quite frequently. I thank I might just switch to another editor for my cakephp usage to avoid these issues in the future.
Louis Stephens
Try Eclipse PDT http://bakery.cakephp.org/articles/view/setting-up-eclipse-to-work-with-cake
bancer
+1  A: 

I would advice you to read the following from the cookbook: Layouts and CSS. Then copy the layout from /cake/libs/view/layouts/ to /app/views/layouts/ and modify it to your needs. After that create you stylesheet (or modify existing one) in /app/webroot/css/ and include it in your layout.

bancer