Check out this great story about the end of XHTML by Felix over at Debuggable. Watch the plot thicken when JSON enters the game.
Filed under: Development, General | Leave a Comment
Custom drop down options in Cake
Ever wanted custom options in a dropdown for your model? Let’s say you have a table called “posts” with a column called “status” and you want the following values: Published, Draft, Archived.
The way the form helper looks at options is like an array, where the array key is the option value, and the array value is the option text. So, if you pass an array that looks like this: array(‘Published’, ‘Draft’, ‘Archived’) to the options key, then the value you’ll get for “Published” will be 0 since that is its key in the array. Normally this is not what we want. You’d probably want “Published” to be the text and the option value.
A simple way to get around this and to create custom drop down options for certain tables is to stick an options variable in your model.
This is what I normally do.
In the app_model.php I would add the following function:
function getOptions() {
foreach ($this->options as $key =>$values) {
$options[$key] = array_combine($values, $values);
}
return $options;
}
In my models, if I have certain fields with custom options I would write:
class Post extends AppModel {
var $name = 'Post';
var $options = array(
'status' => array('Published', 'Draft', 'Archived');
'type' => array('Article', 'Video', 'Audio');
);
}
Now, whenever I want to set those options I would write in the controller:
$this->set('options', $this->Post->getOptions());
In your view you would then just need to write this line to set the options to the form input:
echo $form->input('status', array('options' => $options['status']));
echo $form->input('type', array('options' => $options['type']));
All done.
This would basically save the time of writing a bunch of array_combine’s in your views and it also organizes your model’s custom options.
Filed under: CakePHP, Development | Leave a Comment
CakePHP books
It’s a good sign for a framework when books are being published in it’s name. Along with the expanding list of official resources and blogs discussing CakePHP, several books have been published to help newcomers and intermediate level programmers learn and use Cake to there advantage.
Daniel Hofstetter published an article several months back with books that are available covering CakePHP. His list has last been updated on August. Maybe you didn’t get any of these books in your Christmas stocking, but with the New Year coming up perhaps it’s time for you to buy yourself one and dedicate 2009 to upgrading your development skills.
The guys behind CakePHP Application Development have just released 2 lengthy articles which give you an idea of what you would get.
The first article covers simple associations, while the second article dives into more complex associations. Jonathan Snook has also written a review that you may want to check out.
Learning model associations is critical in using CakePHP to your advantage and I suggest anyone who is learning Cake to get a good grasp of how associations work and how they’ll speed up your development time. Even if you don’t plan on buying the book, check out those articles because I’ve seen a lot of questions on IRC showing lack of understanding on how associations work.
Another book review was written on Daniel Hofstetter on Beginning CakePHP: From Novice to Professional.
So, with the new year coming you may want to pickup a book to help yourself learn CakePHP. After learning the basic concepts, you’ll be surprised at how easy it is.
Update: Daniel Hofstetter has just recently reviewed Practical CakePHP Projects. Check it out.
Filed under: General | 2 Comments
CakePHP 1.2 stable released!
CakePHP 1.2 stable has now been officially released! Check it out along with a list of features 1.2 has to offer.
Filed under: CakePHP, Development | Leave a Comment
If you’re not satisfied with the way Cake’s flash method works, you can easily override it in your AppController class. At the moment, the default flash method takes you to a blank page only displaying the flash message. You are then redirected to the redirect url you provided. The way I prefer flash to work is to immediately redirect the user and show the flash message on that page. This can be easily achieved by by going into app_controller.php and adding the following couple of lines:
function flash($message, $url="/")
{
$this->Session->setFlash($message);
$this->redirect($url);
}
You will then need to modify your layout.ctp to display the flash message whenever it is set. To do this, you’ll need to add the following lines:
if ($session->check('Message.flash')) : $session->flash(); endif;
That’s it. No need to hack cake’s core files and no need to create a custom method when you can override the existing one.
Filed under: CakePHP, Development | Leave a Comment
Organizing your thoughts
I’m always looking for more efficient ways to organize my thoughts and notes. The old pen and paper doesn’t do it for me any more (save the trees!) and trying to find something when you have hundreds of notes to browse through would take up much of your valuable time. It’s 2008 and by now we’ve found new ways to organize ourselves. Whether it’s through text files, Outlook or related software, or organizer software, we’ve definitely come along way. These methods are usually good for keeping you organized, but what about keeping your thoughts organized?
There’s buzz about mind mapping and, while it’s not a new technique, there is now a lot of mind mapping software making it easier to map your mind. While it definitely looks interesting, it didn’t interest me enough to learn how to use it. So I kept looking until I came across wikidPad. What is wikidPad you ask? Well, it’s like notepad on drugs. Ok, that wasn’t very helpful, so let’s quote the wikidPad website.
WikidPad is a wiki-like notebook for storing your thoughts, ideas, todo lists, contacts, or anything else you can think of to write down.
If you’ve used Wikipedia, you’ll begin to understand what wikiPad is all about. Essentially, it’s a “wikipedia” of your thoughts. You start off with a main idea, branch off to sub-ideas, ad infinitum. What you end up with is a web of ideas all linked with each other. To continue with the Wikipedia example, let’s say you look up apples. In the apples article you may have a sub article called “apple juice“. It would then be linked the sub article. Jumping from one idea to a related one is extremely simple. The same applies with wikiPad. If you have a ideas on how to develop your next application, within this section you may have sub sections such as “user system”, “post system”, etc. From there you can continue to build your linked database of thoughts. When you create new ideas (ie: a new application) you can always reuse old concepts like the user system and so on.
To give you a non-programming example, let’s take a field of study. Philosophy, since this is currently what I am studying. I can make documents for notes on the books I read, papers I write, etc. However, the idea that I can link notes, common ideas, and concepts together makes it much easier for me to find what I’m looking for when I look back at my notes.
The best way to see if the software is for you is to try it out. It is free and open source and you can download it off their homepage. If you’re using Linux, you can follow these instructions on how to install it, or simply use their windows version under Wine until they release linux binaries. The learning curve isn’t too difficult, but if you haven’t worked with any wiki software then it may take you a while to get used to wiki formatting.
Filed under: General | Leave a Comment
Sexy Ubuntu
I’ve finally reskinned Ubuntu using a GTK theme from Ubuntu-Art.org. The skin is called Shiki-Colors and it’s a mix of the dark and light themes. I’ve also installed the Gnome-Colors Icons to spice up the look. Installing the theme was pretty easy, but it wasn’t without problems. After applying the new theme, I noticed borders on every division within a window, but after apply the following comment, the theme is working correctly.
This is not a theme problem, it’s a user/root permissions problem. It will happen to any theme/icons you download from the internet and install through the appearance preferences.
To fix this, there are two solutions:
-When installing a theme/icon set, install to usr/share/themes or usr/share/icons as root user, respectively.- Or for an easier solution, run the following commands in a terminal:
sudo ln -s ~/.icons /root
sudo ln -s ~/.themes /root
And now for some screenshots of this sexy theme.
Filed under: General | 1 Comment
CakePHP 1.2 RC2 is available!
The cake team is working rather quickly. They have released Cake 1.2 release candidate 2 on June 27th. Time to upgrade once again! The goodness just keeps coming.
Filed under: CakePHP, Development | Leave a Comment
Playing with Cake RC1
CakePHP RC1 was released on June 4th. At the moment I haven’t had much time to play with it as I wrap up a few projects using 1.2 beta. One thing I did notice was their inclusion of the Containable Behaviour. This is a powerful behaviour that helps in limiting the data you want to grab from your models. I’ve used both Mariano’s and Felix’s behaviours and I’m glad those forces were combined to produce this, and then some.
This weekend I’ll be upgrading my client sites to RC1 and hopefully all will go well. For information on what’s new in RC1, visit the bakery
Filed under: CakePHP, Development | Leave a Comment
Search
-
General
Web Programming
Recent Entries
- An epic XHTML tragedy by Felix Geisendörfer
- Custom drop down options in Cake
- CakePHP books
- CakePHP 1.2 stable released!
- CakePHP RC4 released!
- Overriding CakePHP’s controller::flash() method
- Organizing your thoughts
- Sexy Ubuntu
- CakePHP 1.2 RC2 is available!
- Playing with Cake RC1
- CakePHP ACL Behavior modified
Categories
- CakePHP (10)
- Development (16)
- General (14)