User Profile
- User
- TommyO
Recent Articles
An Akismet Behavior
There have been a lot of tools written in the past to help CakePHP apps deal with comment spam. This is yet another.
- Published by TommyO 03/09/09 - 08:55
- 9387 views
- 2 comments
Sharing One Table amongst different Models using a Type
Sometimes it is necessary to link one data set(the child) to different data sets(the parent) based on a 'type' field. Often this is done through data manipulation and a combination of child Model and Controller code. This behavior helps to simplify table design, and moves all of the manipulation code to a single location: a parent Model.
- Published by TommyO 01/28/07 - 11:23
- 1730 views
- 0 comments
Keeping bindModel and unbindModel out of your Controllers
Sometimes you need to fine-tune your associations: binding to other Models only when needed or unbinding exisiting relations to minimize the size of your result set. With a very simple method and a slight change in how you write some associations, this can be done cleanly and efficiently right from your controller.
- Published by TommyO 12/06/06 - 05:45
- 39807 views
- 13 comments
Using TinyMCE with CakePHP and AJAX
jtreglos wrote an excellent article for integrating TinyMCE into your applications. This takes it one step further, making it possible to have powerful wysiwyg features almost anywhere.
- Published by TommyO 11/08/06 - 05:35
- 57311 views
- 12 comments
Passing Named Parameters
This simple tutorial will add the ability to pass named parameters to your actions.
Named Parameters are beneficial because they:
* Make for much prettier URLs
* Allow passing of a variable number of parameters easier
* Allow passing of parameters in any order
* Remove the need to pass placeholders in URLs
A URL containing named parameters may look like:
http://example.com/controller/action/param1:value1/param2:value2/
- Published by TommyO 11/01/06 - 13:46
- 49880 views
- 10 comments







In this case read the notes in your app's config/bootstrap.php file. Cake already has a way of supporting this.
If you do insist on doing this with a prewritten script, then vendors/codelib.php combined with the proper App::import() call within bootstrap.php, using the available methods as described in bootstrap.php, is the best way to go.
Then it's usage would be like:
{{{
A few comments:
1. You never need include() or require() in Cake as there is always a better way. /vendors exists specifically for that.
2. Generally you can use the path constants that Cake defines to get to webroot and most paths, although really this isn't necessary here. And yeah, your comment about putting the path in config or elsewhere makes for a much more reusable component, but that's just me nitpicking.
3. Since this is output related it feels slightly more like a Helper. Converting this to a helper would be a trivial exercise. Then using it would be as simple as:
echo $gallery->imageBlock(array('blocks' => 'randomImage'));Congrats on a good article and welcome to CakePHP!
1.2 now makes it possible to put the load in the view, but have the code rendered in the page head tags by passing false in as a second parameter to JavascriptHelper::link() To do this, replace:
<?phpin your layout with:if(isset($javascript)):
...
echo $javascript->link('prototype');
echo $javascript->link('tiny_mce/tiny_mce');
echo $javascript->link('scriptaculous');
...
endif;
?>
<?php echo $scripts_for_layout ?>Then, in the view that needs Tiny and Ajax loaded, do:<?php echo $javascript->link('prototype', false); ?>As you can see, this is much cleaner, and your scripts only end up in the pages that need it. If you really care about having the tinyMCE.init in the head, you should be able to make a webroot/js/tiny_mce/tiny_init.js file, and add this after the above:<?php echo $javascript->link('tiny_mce/tiny_mce' false); ?>
<?php echo $javascript->link('scriptaculous', false); ?>
<?php echo $javascript->link('tiny_mce/tiny_init', false); ?>Maybe once 1.2 is released, we can rewrite these two articles using the new, cleaner, 1.2 methods. But unitl then, enjoy!