Re: Custom html helper

2008-04-04 Thread grigri

There should be an official solution sometime involving aliased
helpers.

In the meantime, check out my hack here:

http://groups.google.com/group/cake-php/browse_thread/thread/1c1c370160cb467f

On Apr 4, 3:02 pm, Greg Baker [EMAIL PROTECTED] wrote:
 I want to create a custom HTML helper that extends htmlhelper..
 However because of the code I have already that I don't want to
 change, I want to name this helper so that I can use $html-... in my
 views.

 Any way I can do this?
 Normally if this was a new project I'd just create a new class and use
 that in my views, but I have a lot of code changing to do in this one
 if I do that.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Custom html helper

2008-04-04 Thread Greg Baker

Very interesting fixexactly what I was looking for.  Thanks

On Apr 4, 12:26 pm, grigri [EMAIL PROTECTED] wrote:
 There should be an official solution sometime involving aliased
 helpers.

 In the meantime, check out my hack here:

 http://groups.google.com/group/cake-php/browse_thread/thread/1c1c3701...

 On Apr 4, 3:02 pm, Greg Baker [EMAIL PROTECTED] wrote:

  I want to create a custom HTML helper that extends htmlhelper..
  However because of the code I have already that I don't want to
  change, I want to name this helper so that I can use $html-... in my
  views.

  Any way I can do this?
  Normally if this was a new project I'd just create a new class and use
  that in my views, but I have a lot of code changing to do in this one
  if I do that.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Custom html helper

2008-04-04 Thread Matias Lespiau
I'm not sure but I think you can provide an alias to the helper this way:

$helpers = array('CustomHtml' = 'Html');

On Fri, Apr 4, 2008 at 11:32 AM, Greg Baker [EMAIL PROTECTED]
wrote:


 Very interesting fixexactly what I was looking for.  Thanks

 On Apr 4, 12:26 pm, grigri [EMAIL PROTECTED] wrote:
  There should be an official solution sometime involving aliased
  helpers.
 
  In the meantime, check out my hack here:
 
  http://groups.google.com/group/cake-php/browse_thread/thread/1c1c3701...
 
  On Apr 4, 3:02 pm, Greg Baker [EMAIL PROTECTED] wrote:
 
   I want to create a custom HTML helper that extends htmlhelper..
   However because of the code I have already that I don't want to
   change, I want to name this helper so that I can use $html-... in my
   views.
 
   Any way I can do this?
   Normally if this was a new project I'd just create a new class and use
   that in my views, but I have a lot of code changing to do in this one
   if I do that.
 



-- 
Matias Lespiau
http://www.gignus.com/

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



Re: Custom html helper

2008-04-04 Thread grigri

Looks like you're right!

https://trac.cakephp.org/changeset/6453

Nate sneaked it in without mentioning it. I'm going to play around
with this now...

On Apr 4, 5:37 pm, Matias Lespiau [EMAIL PROTECTED] wrote:
 I'm not sure but I think you can provide an alias to the helper this way:

 $helpers = array('CustomHtml' = 'Html');

 On Fri, Apr 4, 2008 at 11:32 AM, Greg Baker [EMAIL PROTECTED]
 wrote:





  Very interesting fixexactly what I was looking for.  Thanks

  On Apr 4, 12:26 pm, grigri [EMAIL PROTECTED] wrote:
   There should be an official solution sometime involving aliased
   helpers.

   In the meantime, check out my hack here:

  http://groups.google.com/group/cake-php/browse_thread/thread/1c1c3701...

   On Apr 4, 3:02 pm, Greg Baker [EMAIL PROTECTED] wrote:

I want to create a custom HTML helper that extends htmlhelper..
However because of the code I have already that I don't want to
change, I want to name this helper so that I can use $html-... in my
views.

Any way I can do this?
Normally if this was a new project I'd just create a new class and use
that in my views, but I have a lot of code changing to do in this one
if I do that.

 --
 Matias Lespiauhttp://www.gignus.com/
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: custom html helper

2006-12-04 Thread Ryders

Hi Thomas,

I don't know in what order dirs are looked up for helpers, but after
what you said, I would assume the helpers directory from the core is
looked at first. However I ran into the same problem, the html helper
had a few things I wanted to improve and so what I did is creating my
own html helper;

I still didn't figure out how to 'extend' a helper... but I hope this
will help;

First I created a file called eo_html.php in my application helpers
dir. it looks like this; (partial)

code
?php
class eoHtmlHelper extends Helper {
var $helpers = array('Html');
}
?
/code

the var $helpers = array('Html'); line ensures I'll be able to call the
html helper when needed.

Then I whenever I run into something in the html helper that makes no
sense in my app, I 'override' (sort of). For instance the
html-selectTag will not select the default value (from the object)
unless $selected is specified... so instead of modifying the
htmlhelper, I added the following to my helper;

code
function selectTag($fieldName, $optionElements, $selected = null,
$selectAttr = array(), $optionAttr = null, $showEmpty = true, $return =
false) {
if (!$selected) $selected = $this-Html-tagValue($fieldName);
return $this-Html-setFormTag($fieldName, $optionElements,
$selected, $selectAttr, $optionAttr, $showEmpty, $return);
}
/code

notice how I call the original html helper with '$this-Html-...'

Finally, in my view, instead of going $html-selectTag, I use
$eoHtml-selectTag, of course after I added eoHtml to my $helpers array
in my controller!

I cannot say that's the best solution ever (and would appreciate any
comment in re to that!), but so far it's worked quite well!

Hope this helps!

Seb.


On Dec 5, 5:47 am, [EMAIL PROTECTED] [EMAIL PROTECTED]
wrote:
 Hi all,

 I want to have a custom HTML Helper in my helpers dir and it seems like
 it's always the one belonging to the core that is used, it doesn't seem
 to be the same with the form helper for instance.

 any idea what i' doing wrong ?
 
 is it an intended behaviour ?
 
 tia
 
 thomas


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



RE: custom html helper

2006-12-04 Thread Mariano Iglesias

Extend the helper this way:

1. Create a file called myhtml.php on your app/views/helpers directory.

2. Have its contents be something like the following. I'm overriding method
selectTag as in your example, with some small changes, like... PLEASE USE
BRACES! :)

?php

loadHelper('html');

class MyhtmlHelper extends HtmlHelper 
{
function selectTag($fieldName, $optionElements, $selected = null,
$selectAttr = array(), $optionAttr = null, $showEmpty = true, $return =
false) 
{
if (!$selected)
{
$selected = parent::tagValue($fieldName);
}

return parent::setFormTag($fieldName, $optionElements,
$selected, $selectAttr, $optionAttr, $showEmpty, $return);
}
}

?

So you see whenever you need to call cake's html helper you just do
parent::method()

3. Then on your controllers add the helper:

var $helpers = array ( 'Myhtml' );

4. And use it on your views:

$myhtml-selectTag(...)

-MI

---

Remember, smart coders answer ten questions for every question they ask. 
So be smart, be cool, and share your knowledge. 

BAKE ON!


-Mensaje original-
De: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] En nombre
de Ryders
Enviado el: Lunes, 04 de Diciembre de 2006 06:35 p.m.
Para: Cake PHP
Asunto: Re: custom html helper

I still didn't figure out how to 'extend' a helper... but I hope this
will help;


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



Re: custom html helper

2006-12-04 Thread Seb

Dude!!

loadHelper('html'); is what I was missing! cheers for that!

Braces... I'll take a good note of it! ;)

Cheers!


Seb.

On Dec 5, 9:04 am, Mariano Iglesias [EMAIL PROTECTED]
wrote:
 Extend the helper this way:

 1. Create a file called myhtml.php on your app/views/helpers directory.

 2. Have its contents be something like the following. I'm overriding method
 selectTag as in your example, with some small changes, like... PLEASE USE
 BRACES! :)

 ?php

 loadHelper('html');

 class MyhtmlHelper extends HtmlHelper
 {
 function selectTag($fieldName, $optionElements, $selected = null,
 $selectAttr = array(), $optionAttr = null, $showEmpty = true, $return =
 false)
 {
 if (!$selected)
 {
 $selected = parent::tagValue($fieldName);
 }

 return parent::setFormTag($fieldName, $optionElements,
 $selected, $selectAttr, $optionAttr, $showEmpty, $return);
 }

 }?

 So you see whenever you need to call cake's html helper you just do
 parent::method()

 3. Then on your controllers add the helper:

 var $helpers = array ( 'Myhtml' );

 4. And use it on your views:

 $myhtml-selectTag(...)

 -MI

 ---

 Remember, smart coders answer ten questions for every question they ask.
 So be smart, be cool, and share your knowledge.

 BAKE ON!

 -Mensaje original-
 De: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] En nombre
 de Ryders
 Enviado el: Lunes, 04 de Diciembre de 2006 06:35 p.m.
 Para: Cake PHP
 Asunto: Re: custom html helper

 I still didn't figure out how to 'extend' a helper... but I hope this
 will help;


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



Re: custom html helper

2006-12-04 Thread [EMAIL PROTECTED]

thanks to both of you

I really thought if I had a html.php in helpers folder it would be used
instead of the core one like it seems to happen for form.php for
instance ...

if anyone is able to clarify ... :)

tia

thomas


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