On Sep 20, 12:01 pm, Miles J <[email protected]> wrote:
> Ok but what if you needed to add more attributes besides the id?
One example would be:
div('foo',
'bar',
aa('style', 'float:left'))
> Also what would you do when you need to echo PHP variables and loops within a
> div?
Your point is taken here and in the above that that these helper
functions can be less flexible. Right now when I have to loop, I do
div('foo');
foreach(...)
... echo
tag('/div');
which eats away at some of the advantages of using the helper. One
workaround is to wrap your loop in a PHP 5.3 anonymous function:
// not tested
echo
div('foo').
(function () { $acc = '';
foreach(...) $acc .= ...;
return $acc; })().
tag('/div');
Evan
> On Sep 20, 9:38 am, "Evan R. Murphy" <[email protected]> wrote:
>
>
>
> > > My three reasons are less characters (-> file size)...
>
> > To be sure, seeking fewer characters was the impetus for my original
> > post. I wanted to eliminate the "$html->" boilerplate from all my
> > calls to HtmlHelper. div('foo', 'bar') is shorter than <div
> > class="foo">bar</div>. :)
>
> > The HTML filesize is equal or greater, but the source filesize is
> > less.
>
> > Evan
>
> > On Sep 19, 11:39 pm, Jeremy Burns | Class Outfit
>
> > <[email protected]> wrote:
> > > I guess this could ramble on for ever and who really cares anyway. My
> > > three reasons are less characters (-> file size), code performance and
> > > readability/maintainability. I don't think I'm mistaken for a heartbeat.
> > > Performance might not be *the* reason you shouldn't do this, but it is a
> > > factor.
>
> > > Jeremy Burns
> > > Class Outfit
>
> > > [email protected]http://www.classoutfit.com
>
> > > On 20 Sep 2010, at 03:04, nurvzy wrote:
>
> > > > You're mistaken.
>
> > > > While i agree its overkill using the helper for basic markup,
> > > > performxe wise its negligible at worse, no difference at best. This
> > > > is because you are already loading php as a module, youre already
> > > > loading the html helper and your ctp is being parsed through the php
> > > > interpreter. Performance is not the reason you should code it in html
> > > > in thia case, its the maintainability of it. Only a cakephp programmer
> > > > will undersand what youre doing. If you work in any team based
> > > > environments your boss would scuff and throw that back in your face
> > > > because a designer will have no idea what to do with it.
>
> > > > Clean and readable code is important.
>
> > > > Hope that helps,
> > > > Nick
>
> > > > On Sep 19, 12:55 am, Jeremy Burns | Class Outfit
> > > > <[email protected]> wrote:
> > > >> Nope - it's a great tool but in my opinion (and other experienced Cake
> > > >> developers too, it seems) it has to be used with caution. Just because
> > > >> it CAN do some things doesn't mean that you HAVE to use them. I can't
> > > >> see any sense in doing this:
>
> > > >> <?php echo $this->Html->tag('div', $this->html->tag('h1', 'Here is my
> > > >> heading.', array('class' => 'main-heading')), array(class =>
> > > >> 'my-class')); ?>
>
> > > >> ...when this does the same thing:
>
> > > >> <div class="my-class"><h1 class="main-heading">Here is my
> > > >> content.</h1></div>
>
> > > >> Its less characters, easier to read (especially for non-Cake people)
> > > >> and it doesn't use the component (so will perform better).
>
> > > >> So if you have conceded on the performance angle, why would you still
> > > >> want to code this up? If wrap the html helper code up in another
> > > >> wrapper you are just adding complexity and slowing everything down. I
> > > >> don't have any data, but I'd bet that straight html beats coded html
> > > >> in any race.
>
> > > >> It definitely has its uses; but to a man with a hammer in his hands
> > > >> everything looks like a nail.
>
> > > >> No attitude on my part; just passing on my opinion. Sharing is caring.
>
> > > >> Jeremy Burns
> > > >> Class Outfit
>
> > > >> [email protected]http://www.classoutfit.com
>
> > > >> On 19 Sep 2010, at 07:28, Evan R. Murphy wrote:
>
> > > >>> I had already conceded that there may be performance issues with this
> > > >>> approach, I just wanted more data on the severity of it. I'll do some
> > > >>> profiling myself, but if anyone has knowledge about this they can
> > > >>> share, I'd really appreciate it.
>
> > > >>> I'm puzzled by this attitude I'm reading (perhaps I'm misreading?)
> > > >>> that it's a ridiculous proposition to use the HtmlHelper. The thing
> > > >>> ships with CakePHP, and it's promoted pretty heavily in the Cookbook.
> > > >>> If it's such a bad tool, isn't this at least a common misunderstanding
> > > >>> among new Cake programmers?
>
> > > >>> Thanks,
> > > >>> Evan
>
> > > >>> On Sep 19, 12:30 am, Jeremy Burns | Class Outfit
> > > >>> <[email protected]> wrote:
> > > >>>> You are focussing your efforts in the wrong place. Your time spent
> > > >>>> pressing keys on the keyboard is a fraction of the time that your
> > > >>>> code will be rendered across the interweb. If you have a library
> > > >>>> that you are loading up which in turn loads up a component and then
> > > >>>> runs some functions just to output a simple <div
> > > >>>> class="foobar"></div> statement you are introducing massive overhead
> > > >>>> at run time (caching and so on set aside). What is the problem with
> > > >>>> just doing the job right in the first place, or even better using an
> > > >>>> IDE that helps you with this shortcuts?
>
> > > >>>> To build a good program the efficiency has to be in the finished
> > > >>>> product, not in use of your time.
>
> > > >>>> Jeremy Burns
> > > >>>> Class Outfit
>
> > > >>>> [email protected]http://www.classoutfit.com
>
> > > >>>> On 19 Sep 2010, at 02:58, Evan R. Murphy wrote:
>
> > > >>>>> On Sep 18, 7:50 pm, cricket <[email protected]> wrote:
> > > >>>>>> Better to extend HTMLHelper.
>
> > > >>>>> I like that idea. Could you help me understand how you might extend
> > > >>>>> HtmlHelper to make available these global functions (or perhaps even
> > > >>>>> better, put them in some kind of namespace)? I'm new to PHP, so it
> > > >>>>> wasn't clear to me how to write such functions in a class. Public
> > > >>>>> methods seem to be the default.
>
> > > >>>>> Thank you,
> > > >>>>> Evan
>
> > > >>>>> Check out the new CakePHP Questions
> > > >>>>> sitehttp://cakeqs.organdhelpotherswiththeir CakePHP related
> > > >>>>> questions.
>
> > > >>>>> You received this message because you are subscribed to the Google
> > > >>>>> Groups "CakePHP" group.
> > > >>>>> To post to this group, send email to [email protected]
> > > >>>>> To unsubscribe from this group, send email to
> > > >>>>> [email protected] For more options, visit this
> > > >>>>> group athttp://groups.google.com/group/cake-php?hl=en
>
> > > >>> Check out the new CakePHP Questions
> > > >>> sitehttp://cakeqs.organdhelpotherswith their CakePHP related
> > > >>> questions.
>
> > > >>> You received this message because you are subscribed to the Google
> > > >>> Groups "CakePHP" group.
> > > >>> To post to this group, send email to [email protected]
> > > >>> To unsubscribe from this group, send email to
> > > >>> [email protected] For more options, visit this
> > > >>> group athttp://groups.google.com/group/cake-php?hl=en
>
> > > > Check out the new CakePHP Questions sitehttp://cakeqs.organdhelpothers
> > > > with their CakePHP related questions.
>
> > > > You received this message because you are subscribed to the Google
> > > > Groups "CakePHP" group.
> > > > To post to this group, send email to [email protected]
> > > > To unsubscribe from this group, send email to
> > > > [email protected] For more options, visit this
> > > > group athttp://groups.google.com/group/cake-php?hl=en
Check out the new CakePHP Questions site http://cakeqs.org and help others with
their CakePHP related questions.
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
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