Iftikhar uddin
Iftikhar uddin

Reputation: 3182

How to Force Phalcon to pick view from another module instead of defined?

Currently I am loading all users on URL/Route /admin/config/users which is picking this view ( private/apps/Admin/Views/user/users.volt ) from Admin module.

Now I have set a flag for custom layout. So if custom layout is enabled I want the phalcon to pick view from AdminExtension module i.e ( private/apps/Admin/Extension/Views/user/users.volt )

How can I achive this? I want both views. Because private/apps/Admin/Views/user/users.volt is default view for listing all users. However private/apps/Admin/Extension/Views/user/users.volt is customised view for client where a lot of design changes are done.

Here is how dispatcher code looks like:

/**
 * @param Dispatcher $dispatcher
 */
public function afterExecuteRoute(Dispatcher $dispatcher) {

    // Check if Json response is required
    if ($this->_isJsonResponse) {
         //if body
    } else {

        if(CxSettingCustomLayout::loadFromDb()->isCustomLayout()) {
            //pick custom view here" `private/apps/Admin/Extension/Views/user/users.volt`
        }

        // Build current module configuration settings section name
        $moduleConfigName = 'app_' . $this->dispatcher->getModuleName();
        // Include assets configuration file where assets collections are defined
        if(file_exists($this->config[ $moduleConfigName ]['assetsFile']))
            include $this->config[ $moduleConfigName ]['assetsFile'];

        // Set a view variable with the current language code
        $this->view->setVar('current_language_code', $this->CxTranslation->getLanguage()->getCode());
    }
}

Upvotes: 0

Views: 330

Answers (1)

rabudde
rabudde

Reputation: 7722

As @num8er said already, try to use setViewsDir. I'm using Phalcons Simple view class in the following way

use Phalcon\Mvc\View\Simple;

$view = new Simple();
$view->setViewsDir(BASE_PATH . '/app/views/');
echo $view->render('admin/users');

Upvotes: 1

Related Questions