Fernando Pombeiro
Fernando Pombeiro

Reputation: 51

Zend framework, View

Small mystery: can't seem to pass views between my Index controller (chartAction) and my view. When I go to my localhost it is not accessing the view phtml- instead it is just showing the controller every time (i.e: if I write "echo "HELLO WORLD!""; in my controller I get that echoed...but if I do a $this->view->test = "Hello World!" then access the index.phtml and type in echo $this->test; I get nothing (it still defaults to the controller action). Is there a step that I'm missing here? Why is my $this->view not functioning? I used the command line to create the view so I'm pretty sure that should be set up correctly. Do I need to register something? Thanks for any help!

Upvotes: 0

Views: 109

Answers (3)

RockyFord
RockyFord

Reputation: 8519

Assuming a standard MVC setup of ZF1.x, there is a definite relationship between the url, the controller and the action.

The url http://mydomain.com/index would call the index action of the index controller, typically the index action is the default action and is called automatically. the view script would be /application/views/scripts/index/index.phtml

The url http://mydomain.com/index/chart would call the chart action of the index controller and the view script would be /application/views/scripts/index/chart.phtml

Keep in mind that this behavior is changeable based on configuration and routing options.

It sounds like you may be fairly new at working with ZF. So something like the following may help demonstrate the relationship :

// application/controllers/IndexController.php
class IndexController extends Zend_Controller_Action
{
    public function init()
    {

    }

    public function indexAction()
    {
        $this->view->test = "Hello World, from the indexAction().";
    }
    public function chartAction()
    {
        $this->view->test = "Hello World, from the chartAction().";
    }


// application/views/scripts/index/index.phtml
<?php echo $this->test ?>


// application/views/scripts/index/chart.phtml
<?php echo $this->test ?>

now test your application by calling the url's:

http://yourDomain.com/index/index
http://yourDomain.com/index/chart

If your setup is correct you will see the proper response in your pages.

Upvotes: 2

coolguy
coolguy

Reputation: 7954

Your view is disabled..check these lines of code in your action or init of your controller or even the class your controller may be extending

$this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender();

UPDATE

You are doing it in your chartAction and echoing in your index.phtml you must do that in your chart.phtml

Upvotes: 1

janenz00
janenz00

Reputation: 3310

Case 1: View disabled for just one action:

Look for the following code in your action.

   $this->_helper->viewRenderer->setNoRender(true);

Case 2: View disabled for all actions in a specific controller: Look for the above line in either the init() or preDispatch() functions of the controller.

Case 3: View disabled for all actions in all controllers: Check case 1 and 2. Also, look for something like the following in your Bootstrap.php:

   $frontController->setParam("noViewRenderer", true);

If you find the code like above, you will have to comment it out to get the view working. I am sure there are more possibilities to disable view. Those are to be checked after this.

Upvotes: 2

Related Questions