0

Maybe I dont understand the MVC convention well enough, but I'm trying to include a file to the index.phtml view for the main Index Controller, and it keeps giving me an Application Error. I have no idea what this error is or why its not working. But I'm using a standard include_once(...) in the view.

Is this even allowed?

1
  • So how do you create views for like templates that are used across pages?
    – qodeninja
    Jan 28, 2011 at 0:31

5 Answers 5

3

A view in Zend is still just a php file. If you are getting errors in a view using include_once(), they are probably because the file you want can't be found in your include path. Trying dumping get_include_path() into the view and you will see what directories PHP is searching to find your included file.

As an alternative to include_once, you could use

<? echo $this->render('{module}/{action}.phtml') ?>

to pull in the file.

2

There are partial views for such purpose

http://framework.zend.com/manual/en/zend.view.helpers.html (ctrl+f Partial Helper)

2

The view is only the HTML that will be rendered. It's the very last thing that is processed. The controller is called first, then it calls whatever models are needed within. After passing all the data to the view, the view's HTML is rendered.

In short: whatever you include in the view, the controller isn't aware of it. You need to run your PHP includes earlier in the code. If you do it in the controller, it should work OK, I suppose (not tested, so I don't guarantee anything).

0

You can use Zend View Helpers for this purpose

0

last time this works fine for me. You can try this:

    <?php echo $this->partial('common/left_menu.phtml'); ?> 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.