• 6

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191


File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

I'm using various modules and a parent controller to keep consistancy.

My parent controller has a bunch of common actions that each of the subsequent child controllers need to have access to. I'm finding it difficult to make this default action render a correct view.

I do NOT want to have to add the same view to each of my modules - that would defeat the object - but i would like to have a default view somewhere.

I have tried:

$this->_forward('commonaction', 'baselayout', 'default');

This doesnt work for me - as it tries to process the action again - when i've already populated the variables needed within my parent controller.

Any help would be awesom.


To clarify i want to be able to use a common view from a different module. All exampels and solutions currently assume a common module. THis doesnt work for me.

      • 1
    • I've updated my answer. Aurelio was on the right track but setting adding the script path is required for the use of view script outside of the current module.

Use this statement in your controller:

// Render 'foo' instead of current action script

// render form.phtml to the 'html' response segment, without using a
// controller view script subdirectory:
$this->_helper->viewRenderer('form', 'html', true);

from the official doc http://framework.zend.com/manual/en/zend.controller.actionhelpers.html

It is not possible (at the best of my knowledge) to show view of different module. Besides there's no trace of this question in the official doc.

  • 5
Reply Report
      • 1
    • Hey Aurelio - thanks the major problem with this solution is that it still looks for the view within the same module that i'm currently in. Which is wrong. I need to be able to say i want view X rendered from Module Y.

Like you, I have multiple modules and wanted to render an arbitrary view (residing in one module) in the controller of a different module.

This was the only way that I could get it to work, after trying many approaches:

Controller action:

public function xyzAction()
    $view = new Zend_View();
    $view->setScriptPath(APPLICATION_PATH . '/modules/moduleB/views/scripts/abcBlahBlah');
    echo $view->render('yadaYada.phtml');
  • 2
Reply Report

Try the following in your action:

  • First you specify the path to the module where your view script is stored
  • Then you specify the name of the view script to the view renderer

See the following code:

// Add a script path to the directory in the other module
$this->view->addScriptPath(APPLICATION_PATH . '/modules/baselayout/views/scripts');
// Tell the viewRenderer to use the view script 'scriptname'
  • 2
Reply Report

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions