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

Recent Comments

Posted 14/12/2008 10:02pm
Using include/require in Cake apps is generally a Bad Idea, as there's always a better way.

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.
Posted 17/11/2008 02:58pm
Since this relates to data output, it might better fit as a Helper.

Then it's usage would be like:

{{{
DIRTY HTML =

CLEAN HTML = purify($dirty_html));?>
purify($dirty_html);?>
}}}
Posted 05/08/2008 09:54am
Gallery2 is itself a pretty complete application, but your integration is simple and clean. For someone so new to cake, it's a bold article!

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!
Posted 11/10/2007 11:23am
For those of you have not used tinyMCE before tinyMCE.init is declared in the of your page (in your layout). Yes, although that makes for cleaner html, it is not necessary. As jtreglos' original article points out, this can be done in the view.

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:
<?php 
if(isset($javascript)):
    ...
    echo 
$javascript->link('prototype');
    echo 
$javascript->link('tiny_mce/tiny_mce');
    echo 
$javascript->link('scriptaculous');
    ...
endif;
?>
in your layout with:
<?php echo $scripts_for_layout ?> Then, in the view that needs Tiny and Ajax loaded, do:
<?php echo $javascript->link('prototype'false); ?>
<?php 
echo $javascript->link('tiny_mce/tiny_mce' false); ?>
<?php 
echo $javascript->link('scriptaculous'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_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!
Posted 04/10/2007 08:58am
I Get The User with the $id and his Avatar and his Friends.

The PROBLEM Is That I Dont Get The Avatar From The Friends :(


So please help me when somebody has an idea....

Thank u very much!
The answer lies in recursion. Since User->Friend->Avatar is one layer deeper than User->Avatar and User->Friend, you simply need to set your recursive value a little higher.