Things you should know about cakePhp

March 28, 2007 at 3:51 pm 10 comments

21 things I learned about cakePhp almost covers all the basics to intermediate lessons a beginner should know about.. check them one by one and you’ll surely get some good points even if you have used it for a long time. I did and got a lot of new lessons!

I have some more things to add or comment to.

Easily creating static pages
This is a great solution! if you want to rename it, you can use the route.php to configure the names. example, i have an about page, you can point http://www.example.com/pages/about to http://www.example.com/about.. quite neat. Read this tutorial for more options on how to do it.

Viewing the SQL queries that are running behind the scenes
I use this code to hide and unhide those sql queries (which i really love)

Multiple sources of documentation
Add the bakery to that. More resources here.

Using bake.php
Do try this one, you’ll surely love cakePhp more..

Mind permissions when moving cake around
This is one of the most common error
Warning: file_put_contents(/home/directory/app/tmp/cache/models/default_gcsbox_list) [function.file-put-contents]: failed to open stream: Permission denied in /home/directory/cake/basics.php on line 822

Just do the chmod -R 777 to /app/tmp as suggested.

Creating a controller that uses other models
I use this most of the time but you should also not forget that you can use the $this->Post->User->function();

There is another method where you can use another model in the Model class but can’t find that link yet.. I will update this once i found it.

Call exit() after redirecting
if you are using cakePhp1.2, you do the ffg:

$this->redirect('controller/action', null, true);

According to this post, the latter makes the app testable than using the exit or return. Return would also be a good option but be careful when using it in the beforeFilter(). Read more here.
Some more additional info

  1. Use debug() to display an array covered by the pre tag so you can check the array clearly.
  2. bindModel and unbindModel on the fly. I also found this code very helpful and provide cleaner interface for the controllers

I also notice among my friends that uses xampp, after the installation, the sample page has a very basic html look. You should atleast see the colors of the cakePhp main site to know its really working (aside from the database message). If you experienced this problem, check your Apache configuration. My conf has the ffg codes

<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>

I just change the AllowOverride None to AllowOverride All and things work perfectly.

If you have common things you use that you want to share, please inform me and I’ll be happy to add them to the list..

About these ads

Entry filed under: baking tips, cakephp. Tags: .

A question of ‘to bake or not to bake’ Internet in your toilet!

10 Comments Add your own

  • 1. Jen  |  May 7, 2007 at 4:34 am

    Cool! I’m just getting started learning CakePHP and I took at look at the “21 things” article, and this one as well. Lots of helpful tips for a newbie to CakePHP!

    Thanks a bunch

    Reply
  • 2. isaacw  |  July 24, 2007 at 10:16 pm

    Just do the chmod -R 777 to /app/tmp as suggested.

    Thanks for the tip! I spent a couple hours trying to fix this before I found your post. Cheers!

    -isaacw

    Reply
  • 3. OmiYang  |  August 10, 2007 at 9:24 am

    hi
    i am sorry my english is not good.
    now, i have a trouble. i used cakePHP develop a website ,but the apache server not allowed to use .htaccess file.
    i set the VirtualHost like this,but it not work well. when i open the page ,it show error 400.

    i need your help,thank you.

    DocumentRoot “\data\www\…\app\webroot”
    ServerName http://www.XXX.com

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all

    Reply
  • 4. rageonline  |  August 10, 2007 at 9:32 am

    Hi OmiYang,

    Try AllowOverride All and let me know how that goes.

    Reply
  • 5. OmiYang  |  August 10, 2007 at 10:18 am

    hi rageonline

    on my pc i set AllowOverride All ,it’s ok
    but on the server , Manager said can’t set AllowOverride All ,he doesn’t want to use .htaccess file,so i only can set AllowOverride None.
    now i want to know how to run the cakePHP project well without use .htaccess
    can you give me some advice or sample.

    thank you.

    Reply
  • 6. cakensoda  |  August 10, 2007 at 10:43 am

    Hi OmiYang,

    Try this:

    If you don’t want or can’t get mod_rewrite (or some other compatible module) up and running on your server, you’ll need to use Cake’s built in pretty URLs. In /app/config/core.php, uncomment the line that looks like:
    define (‘BASE_URL’, env(‘SCRIPT_NAME’));

    This will make your URLs look like http://www.example.com/index.php/controllername/actionname/param rather than http://www.example.com/controllername/actionname/param.

    Found it here: http://manual.cakephp.org/appendix/blog_tutorial

    Reply
  • 7. OmiYang  |  August 14, 2007 at 8:38 am

    thank you everyone help me
    i copy the RewriteRule from .htaccess to VirtualHost

    <VirtualHost *:80>
    DocumentRoot "E:\workspace\…\app\webroot"
    ServerName http://www.XXX.com

    <Directory "E:\workspace\…\app\webroot"&gtOptions Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

    </Directory>

    </VirtualHost>

    Reply
  • 8. OmiYang  |  August 14, 2007 at 8:40 am

    now it run well
    (“,)

    Reply
  • 9. Lobo tuerto  |  May 28, 2008 at 7:00 pm

    Hello cakensoda,

    There is another method where you can use another model in the Model class but can’t find that link yet.. I will update this once i found it.

    Any ideas about the name of that method?

    Reply
  • 10. hariharan  |  September 12, 2008 at 5:29 am

    This is hariharan from TCS organization,serving in web2.0 labs.I am trying to develop one web application
    using cakephp. When i use redirect i get the following error,

    Warning (2): Cannot modify header information – headers already sent by (output started at /opt/lampp/htdocs/cakephp2/app/controllers/tasks_controller.php:83) [CORE/cake/libs/controller/controller.php, line 578]

    I have tried my best to resolve it, but in vain.

    can u help me to resolve this issue?

    Thanks,
    Hariharan

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Recent Posts

March 2007
M T W T F S S
« Feb   Apr »
 1234
567891011
12131415161718
19202122232425
262728293031  

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: