yitznewton
yitznewton

Reputation: 810

Lithium: load view from library

I am working on a 3rd party library in PROJECTROOT/libraries/mylib. have a controller in mylib/controllers, which is working. li3 tells me it expects a view in PROJECTROOT/app/views/ -- how can I load a view from mylib/views instead of app ?

Upvotes: 1

Views: 391

Answers (1)

d1rk
d1rk

Reputation: 358

That can be easily achieved by setting the render paths in a controller. You probably want to do that for every controller in mylib, so a BaseController that all controllers extent from is a good idea. You can then use lithiums default called method _init() to setup the configurtion like that:

class BaseController extends \lithium\action\Controller {

    public function _init() {
        parent::_init();

        $this->_render['paths'] = array(
            'template' => array(
                LITHIUM_APP_PATH . '/views/{:controller}/{:template}.{:type}.php',
                '{:library}/views/{:controller}/{:template}.{:type}.php',
            ),
            'layout' => array(
                LITHIUM_APP_PATH . '/views/layouts/{:layout}.{:type}.php',
                '{:library}/views/layouts/{:layout}.{:type}.php',
            ),
            'element' => array(
                LITHIUM_APP_PATH . '/views/elements/{:template}.{:type}.php',
                '{:library}/views/elements/{:template}.{:type}.php',
            ),
        );
    }

You can have a look at it here: https://github.com/bruensicke/radium/blob/master/controllers/BaseController.php

Please note, that i set it up that way, so the application can overwrite specific views in order to customize it further.

Also, there is an issue/pull-request on github regarding that topic, have a look here:

https://github.com/UnionOfRAD/lithium/pull/650

Upvotes: 1

Related Questions