Archive for March, 2007

Things you should know about cakePhp

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..

Advertisements

March 28, 2007 at 3:51 pm 10 comments

A question of ‘to bake or not to bake’

This question stucked me for some time now.. I even googled the question why use a framework before. (My framework of choice is MVC and cakePhp, so this will talk about the 2.)

There are many debates in determining if you need/want a framework or not. Here’s the opinion of Rasmus about MVC.

I don’t have much of a problem with MVC itself. It’s the framework baggage that usually comes along with it that I avoid. Parts of frameworks can be useful as long as you can separate the parts out that you need. As for MVC, if you use it carefully, it can be useful in a web application. Just make sure you avoid the temptation of creating a single monolithic controller.

It’s a matter of personal perspective in development, how well can you learn the framework in time and how patient are you to master this new tool to be able to use it wisely. As for me, I remember that I came to a point that I was so upset because I can’t do what I want. There are just so many things that I think are not useful and not possible in a framework. I like the simple call to query, I like the helpers a lot, I like the debugging tools, I like and dont like the foldering system, I like the team and the community who are very helpful at many times, I like the URL setup, I like and dont like the HABTM, I don’t like the documentation, etc. etc.. There are so many things that I like and don’t like just because they are new to me or they are hard to understand. But that’s how frameworks are, they teach you of something else out of your system. You may or may not like it at first but you’ll eventually learn and appreciate it. I didn’t like php at first because I have to learn a NEW environment again (I was a VB developer then, became a Mediawiki hacker(sort of)).

One important aspect that I liked in a framework, it guides you in a way everybody in your team will also follow. I am not the boss in our group so I can’t tell everyone that ‘hey, you should do this and that to make things clearer for me’ (in simple words, to please me and make my programming life easier). Rather, the framework tells us what to do and how to organize things. It is our manager. Eventhough frameworks acts like that, it should not limit you to do your job. I’ve learned from one of the cakephp team that once it makes your life harder, then just do it the way it’s easier. Frameworks should make our life easier, not the other way round. So today, I am not stucked to make it all ‘cakish’ unlike before when I was starting. As long as it works and it doesnt break anything especially the core, then I have no problem. I am still using php as my language and I should code like I used to be. To quote Rasmus, php always tries to find the shortest path to solving the Web problem, so cakePhp shouldn’t be a hindrance to that.

Again, frameworks should work as guidelines, not rules. Use it, dont make it use you. If you can do it in a better way, then just do it! If it doesnt help, move on and try something else. I am not stucked with how cakePhp should do it specially that it really lacks documentation right now. I’ll learn it on the way, while improving myself and my abilities in using it. As for now, just do it. (I am not a Nike fan, i read this in a blog before but can’t remember the url. I just love that line πŸ˜‰ )

I’ll leave you with another perspective of another baker:

After these experiences with two different applications using cake, I guess it’s not a question of when or when not to bake, but rather, how you would actually do the baking. You can always bake, complex application or not, you just have to have a well studied and structured approach on how to bake your cake πŸ™‚ .

March 15, 2007 at 11:24 am Leave a comment


Recent Posts

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