Wednesday, October 5, 2011

Re: Html helper - stop adding prefix unless explicitly specified

On 5 Paź, 03:31, rchavik <rcha...@gmail.com> wrote:
> You could create a custom helper inheriting HtmlHelper, then use the joeb'sAnalogue plugin<https://github.com/joebeeson/analogue>to masquerade your helper as core HtmlHelper. This way, you don't have to
> modify your view files

Thanks... that got me thinking so I dug into the whole thing and I
found out the solution... Long story short - I overrode Router's url()
method and set it to explicitly set 'admin'=>false for urls in
prefixed routes...

Here's the code that goes into app_helper.php:

class AppHelper extends Helper {

function url($url = null, $full = false) {
if(isset($this->params['prefix'])){
$prefix = $this->params['prefix'];

if($this->params[$prefix] && (!isset($url[$prefix]) || !
$url[$prefix])){
$url[$prefix] = false;
}
}
return parent::url($url, $full);
}
}

So far it works like a charm... we'll see how it goes...

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: