debuggable

 
Contact Us
 

Problems with base Path in Layouts when using Plugins

Posted on 18/3/06 by Felix Geisendörfer

Deprecated post

The authors of this post have marked it as deprecated. This means the information displayed is most likely outdated, inaccurate, boring or a combination of all three.

Policy: We never delete deprecated posts, but they are not listed in our categories or show up in the search anymore.

Comments: You can continue to leave comments on this post, but please consult Google or our search first if you want to get an answer ; ).

Update: The problem was solved shortly after it appeared by updating to the latest version. So this should only be interesting to you if you are forced to run an older version of the core for some reasons.

If you have worked with cakephp plugins so far you might have notices this little problem: If you use the html helpers link() function to create your navigation menu in your layout the path will change if you call a plugin controller. The reason is that $this->base becomes base_url/plugin instead of the default base_url.

I have talked with PhpNut_ about it but haven't heard anything about it since then. So for those who need to work around the problem this will do it for now:

/**
* This overwrites View::renderLayout in order to make the base path consistent for the layouts
*
* @param string $content_for_layout
* @return string
*/

function renderLayout($content_for_layout)
{
    $dispatcher =& new Dispatcher();
   
    $pluginBase = $this->base;
    $defaultBase = $dispatcher->baseUrl();        
   
    $this->__changeBase($this->loaded, $defaultBase);                
    $rtrn = parent::renderLayout($content_for_layout);  
    $this->__changeBase($this->loaded, $pluginBase);        
   
    return $rtrn;
}

/**
* This changes recursivley the base path of any given object/array
*
* @param mixed $object
* @param string $base
*/

function __changeBase(&$object, $base)
{
    if (is_array($object))
    {
        foreach ($object as $id => $subObject)
        {
            $this->__changeBase($object[$id], $base);
        }
    }
    else
    {
        if (isset($object->base))
        {
            $object->base = $base;
        }
    }
}

 
&nsbp;

You can skip to the end and add a comment.

Nate  said on Mar 18, 2006:

Just FYI, your title rollover is a little messed on Safari.

gwoo  said on Mar 18, 2006:

you should test the latest trunk

Felix Geisendörfer said on Mar 18, 2006:

Nate: I have no way to test this page with Safari. And if I did, Safari would be very low on my browser importance list : /. Any specific reason you are not using Firefox?

This post is too old. We do not allow comments here anymore in order to fight spam. If you have real feedback or questions for the post, please contact us.