Html::link() arguments

54 views
Skip to first unread message

euromark

unread,
Jun 12, 2012, 11:06:41 AM6/12/12
to cakeph...@googlegroups.com
For 3.0 we should definitely correct the long overdue argument order of Html::link()
It should read:

  public function link($url, $title = null, $options = array(), $confirmMessage = false) {}

or is this already planned for 3.0? I didn't find it on the 3.0 roadmap.

maybe there are other argument orders that havent been touched for BC and that could be corrected at this point, as well.

mark_story

unread,
Jun 13, 2012, 5:01:42 PM6/13/12
to cakeph...@googlegroups.com
Why is that the correct argument order?  Seems better the other way around to me.  With long url definitions it could be harder to find the link text.   Also url as the first arg would mean we'd need to update all the other similar methods like PaginatorHelper::link(), JsHelper::link() and so on.

-Mark

Graham Weldon

unread,
Jun 13, 2012, 5:40:45 PM6/13/12
to cakeph...@googlegroups.com
I also feel that its probably more likely that you'll have a link with a null url than a link with a null title.

This proposed change doesn't make much sense to me.

Cheers,
Graham Weldon
Skype: grahamweldon

euromark

unread,
Jun 13, 2012, 8:10:42 PM6/13/12
to cakeph...@googlegroups.com
isnt it always the case that at least an url must be provided - even if cloaked as title due to the name of the first argument?
the current workaround inside the method is to switch the title and url if no title is necessary
but there is always an url present (not the other way around), otherwise a link() helper wouldnt make sense.

ok, I didnt take a look at other link methods.
Just stumpled upon the weird "switching fix" inside the link method.

For me it seems like the argument order hasn't been touched due to BC.
A simple example where the order would be helpful as proposed:

    $this->Html->link('/yourpage');

where the url also is used as the title (second argument)
right now the url is passed as the title and then made the url again inside. kind of counter-inituitive

Thiago Belem

unread,
Jun 13, 2012, 8:20:08 PM6/13/12
to cakeph...@googlegroups.com
Imagine the following:

<li><?php echo $this->Html->link(array('controller' => 'posts', 'action' => 'index'), 'Posts') ?></li>
<li><?php echo $this->Html->link(array('controller' => 'long_controller_name', 'action' => 'long_action_name'), 'Products') ?></li>
<li><?php echo $this->Html->link('/blog', 'Blog') ?></li>

And compare with this:

<li><?php echo $this->Html->link('Posts', array('controller' => 'posts', 'action' => 'index')) ?></li>
<li><?php echo $this->Html->link('Products', array('controller' => 'long_controller_name', 'action' => 'long_action_name')) ?></li>
<li><?php echo $this->Html->link('Blog', '/blog') ?></li>

I would totally go with the 2nd option.

Maybe they should use the title param (first) as url (second) if the url isn't defined/null.

So we can do:

<li><?php echo $this->Html->link('Blog', '/blog') ?></li> == <a href="/blog">Blog</a>

And

<li><?php echo $this->Html->link('/blog') ?></li> == <a href="/blog">/blog</a>

But I don't think that changing params order is the solution here.

Regards,
--
Thiago Belem
Desenvolvedor
Rio de Janeiro - RJ - Brasil

Assando Sites - Curso online de CakePHP

Andy Hobbs

unread,
Jun 13, 2012, 5:07:21 PM6/13/12
to cakeph...@googlegroups.com
+1 to leave as it is.

Link "this text"  to "this location" seems to make more sense to me than: link "to this location" from "this text"

Andy

euromark

unread,
Jun 14, 2012, 4:50:01 AM6/14/12
to cakeph...@googlegroups.com
all right
Reply all
Reply to author
Forward
0 new messages