I like Django’s design philosophy

I was just looking at Django’s design philosophies and I agree on many of their points. It made me start to rethink the many mistakes that I made in coding. I often build things that are not loosely-coupled enough and when it comes to extending, things are a total mess. And I got used to working alone and I tend to get lazy and start to use the IF ternary operator (the question mark and colon) which is really messy.

  • Loose coupling
  • Less code – less code usually means less bugs for me.
  • Explicit is better than implicit – I don’t mind writing more code if it makes things clearer. The hardest thing about CakePHP is that it does quite a lot of behind the scenes things and I don’t really know what’s going on. CakePHP actually does a lot of automation for you and it’s harder for beginners to start understanding them.
  • Don’t repeat yourself (DRY) – Of course, of course.
  • Encourage best practices – Python forces you to indent things a particular way. Indentation is part of their code syntax. It would seem restrictive to begin with but it turns out to be some sort of bonus feature for me.

Continue reading “I like Django’s design philosophy”

How to get the controller’s action name from the view

You know sometimes, in CakePHP’s views, it is useful to check what is the controller’s action. It is quite useful when it comes to implementing selected tabs.

You can use the following expression to get the action name from your view:

[code lang=”php”]$this->controller->action[/code]

The following is a usage example:

[code lang=”php”]< ?php /* This is a view element file - nav_messages.thtml */ ?>
< ?php $s = $this->controller->action; ?>

  • Inbox
  • Sentbox



“messages_inbox” and “messages_sentbox” is the name of the action (function) in my controller. Continue reading “How to get the controller’s action name from the view”

How to do logging in CakePHP

Okay, I realized this long ago but it annoys me that every time I just forget this. Sometime, when debugging CakePHP, the most direct method is to simply log an error. It’s like ‘trace’ in Actionscript or just a println() in Java. Anyway, here it is:

[code lang=”php”]$this->log(“Log anything here.”);[/code]

This can be called from the controller. Continue reading “How to do logging in CakePHP”