Re: Action-Specific Helpers

2008-12-18 Thread Adam Royle

What you are doing is perfectly fine, I personally use $this-helpers
[] = 'Blah'; since it's quick and easy.

Cake will only load your helper once even if it appears multiple times
in your helpers array, so don't even worry about checking for this.

Heck, just include it twice to make sure it gets loaded!

$this-helpers[] = 'Textile';
$this-helpers[] = 'Textile';
$this-helpers[] = 'Javascript';
$this-helpers[] = 'Javascript';

(j/k on that last bit by the way)

On Dec 16, 11:31 pm, Rob Wilkerson r...@robwilkerson.org wrote:
 How should I add multiple action-specific helpers?  Originally I had:

 $this-helpers[] = 'Textile';

 When I wanted to include the Javascript helper for this action, I
 couldn't find the right syntax (if there is a right syntax) to do
 so. I want to retain the default helpers, too.  I've made it work
 using traditional PHP array syntax, but am wondering if that's going
 to cause me any problems down the line.  For now, at least, I have:

 array_push ( $this-helpers, 'Textile' );
 array_push ( $this-helpers, 'Javascript' );

 Total noob question, I know, but I _am_ a noob so it probably won't be
 the last time while I get a grip on what's possible and the best
 practices. :-)

 Thanks.

 Rob
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Action-Specific Helpers

2008-12-18 Thread Rob Wilkerson

On Thu, Dec 18, 2008 at 10:08 AM, Adam Royle a...@sleekgeek.com.au wrote:
 What you are doing is perfectly fine, I personally use $this-helpers
 [] = 'Blah'; since it's quick and easy.

Thanks for verifying. Native syntax within frameworks can sometimes
behave unpredictably, so even though this seemed to work, I wanted to
be sure I wasn't inviting problems down the road.

-- 
Rob Wilkerson
http://robwilkerson.org

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Action-Specific Helpers

2008-12-16 Thread Rob Wilkerson

How should I add multiple action-specific helpers?  Originally I had:

$this-helpers[] = 'Textile';

When I wanted to include the Javascript helper for this action, I
couldn't find the right syntax (if there is a right syntax) to do
so. I want to retain the default helpers, too.  I've made it work
using traditional PHP array syntax, but am wondering if that's going
to cause me any problems down the line.  For now, at least, I have:

array_push ( $this-helpers, 'Textile' );
array_push ( $this-helpers, 'Javascript' );

Total noob question, I know, but I _am_ a noob so it probably won't be
the last time while I get a grip on what's possible and the best
practices. :-)

Thanks.

Rob
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Action-Specific Helpers

2008-12-16 Thread grigri

The best place to look for advice would be the core code itself. In
libs/controller/controller.php, at the end of the paginate() function,
it ensures that the paginator helper will be loaded with this code:

if (!in_array('Paginator', $this-helpers)  !array_key_exists
('Paginator', $this-helpers)) {
  $this-helpers[] = 'Paginator';
}

If that seems long-winded, add a method to AppController:

function useHelper($helper) {
  $helpers = func_get_args();
  foreach($helpers as $helper) {
if (!in_array($helper, $this-helpers)  !array_key_exists
($helper, $this-helpers)) {
  $this-helpers[] = $helper;
}
  }
}

Then in your action you can do

$this-useHelper('Textile', 'Javascript');

hth
grigri

On Dec 16, 1:31 pm, Rob Wilkerson r...@robwilkerson.org wrote:
 How should I add multiple action-specific helpers?  Originally I had:

 $this-helpers[] = 'Textile';

 When I wanted to include the Javascript helper for this action, I
 couldn't find the right syntax (if there is a right syntax) to do
 so. I want to retain the default helpers, too.  I've made it work
 using traditional PHP array syntax, but am wondering if that's going
 to cause me any problems down the line.  For now, at least, I have:

 array_push ( $this-helpers, 'Textile' );
 array_push ( $this-helpers, 'Javascript' );

 Total noob question, I know, but I _am_ a noob so it probably won't be
 the last time while I get a grip on what's possible and the best
 practices. :-)

 Thanks.

 Rob
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---