Archive for the ‘Cake-Toppings’ Category

Displaying custom error message with the right HTTP response codes

I’m building an RESTful API with CakePHP now. That is great stuff. Very easy and quick for the basics. Some more info on how to in the book and here.

But I wanted a custom XML error message with the right HTTP respond code like the Twitter API does. I knew it could be done with overwriting the AppError class and make my own custom method.

This is how I did it: (more…)

Cache duration and configuration tips

320gb-werstern-digital-hard-drive-7200-rpm-cache-8mb-hd-w3200jbAs you know you can cache several elements in you application. When I wrote a value to the cache I did it by setting the duration in the third parameter of write:

Cache::write('cache_key', 'value to cache',array(
    'config'=>'default',
    'duration'=>'+1 day')
);

But today I learned a lesson from Mark Story that this was a bug and it is fixed and doens’t work anymore. It is ignored.

So how do I set the duration before read/write for specific data in my code? (more…)

Mapping content over domains with Apache

Using ‘Dynamic Mirror‘ in Apache you can map content from one domain to another. This was useful for a customer who had two very old domains from 1993 and built-up a nice SEO ranking.

We have two domains a-domain.com and b-example.com. The last one has a new design and some different links and is an application built in CakePHP. 
The other domain ‘a-domain.com’ had its purpose to serve the same content. (more…)

Writers invite

Hi all,

rp-pencil-tipAs you see I don’t write very often. That is because I have a lot todo and I sometimes I really don’t know what to write about! And if I do teknoid or someone else beats me to it … (keep doing that you guys!)

My intention with this blog was that more writers join in and write together with me tips and insights of cake and other tech stuff. 
So… If you thought of writing articles, short tips and tricks but never had the time to setup your own blog? Or are you someone like me that doesn’t write much but sometimes want to?

Come in, register and write! Or leave a comment on this post. Join me to write (great) stuff about what’s keeping us busy.

Cheers!
- primeminister

Yii and CakePHP

what-do-you-look-for-in-a-php-framework-graphI like working with CakePHP because it saved me a lot of time when it comes to roll-out new features for an existing app. Now I’m working on new features in markt.nl and it saves me like days to get going again and change some search results look and feel.

I also sometimes think CakePHP framework is a little bit bloated and I miss the lazy loading a lot. In some apps I use the (un)bindModel methods and containable behaviour a lot and often have to read the whole method again and wonder how I did it. (/em is asheamed of writing code without comments) ;)

So I stumbled against a blog post by Jonah while writing about the Yii framework in comparisment to CakePHP. I liked what I read but always have to try it out myself. So I will do that in the future. Maybe on Christmass because I hate such holidays (sorry all…)

Speaking of frameworks… Chris Hartjes made a shop with a nice t-shirt. I like the drawing but not gonna buy the shirt. The collar of those things always kill me ;)

Checking out the CakeBot

I had a spare moment which is very rare and immediately took the opportunity to do what I wanted to do for ages… Check out the CakeBot!

With a couple of friends we have our own IRC server and I wanted more flexibility then the modules they use now.
CakeBot is an IRC bot written in cake and you can check it out at https://svn.cakefoundation.org/irc/branches/cakebot_1.0.x.x. I think achew22 and kabturek wrote the cakeBot but not sure.

The most of you people who has been on IRC channel of CakePHP knows what it is but here are some of the features when checked out on your own server:

  • It has a web interface to add users, channels and tells.
  • Web interface for the logs for each channel and can be searched
  • Adding commands (= hooks) is as easy as writing simple shell tasks
  • Adding simple commands by everyone to the database (~tell)

Some disadvantages I’ve encountered:

  • ~help, ~seen and ~forget commands are not Tasks but are in the Bot Task.
  • Passing the channel name and other params from the Bot to the commands is not very easy. Only the params you passed from the client are now available.
  • Missed the users_controllers.php for the web interface

Hacked all that bit still not satisfied abouth passing other parameters that are only available in the bot Task.

Sending url parameter through _GET and Cake convention

Yesterday I tried to pass an ‘url’ GET parameter to cake but I got a ‘Http controller missing‘ error. Here is the url:
http://www.example.com/images/notify?myid=456&time=782638762863&url=http%3A%2F%2Fwww.cakephp.org
After a while I remembered that CakePHP uses the ‘url’ parameter when using mod_rewrite:

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

This means that every request after the domain name is added to the url parameter. F.e.:
http://www.example.com/items/view/1234 will be transformed to http://www.example.com/index.php?url=items/view/1234. This means we cannot use the ‘url’ parameter ourselfs. (more…)