Hello All,

I am using Zend Framework, and had a left a project for a while, when I returned to it I've added a new Controller, (for arguments sakes CustomController) and created a view for the controller (/applications/views/scripts/custom/index.phtml).

When I attempt to visit the site (http://site/custom) I get an error:

Fatal error: Uncaught exception 'Zend_Session_Exception' with message 'Session must be started before any output has been sent to the browser; output started in /web/site/CustomController.php:36) 

Note: Line 36 is EOF.

Can anyone give me any idea on where I should begin to look? I've tried to check IF sessions have been initialized (and start if not) under the ControllerClass' Init, preDispatch, and as well in the bootstrap (yes, I was desperate).

Can anyone recommend any places I should check? This is Zend Framework 1.7.

I have created a login/ controller which works perfectly.

    I've figured out my own issue.

    The solution was that the Zend Studio was appending to Carriage Returns after the php close "?>".

    Those two blank lines needed to be removed so that the close was the last item.

      If the last token in the file is going to be "?>", then it can be left off. Any trailing whitespace at the end of the file would then be parsed as PHP code and therefore not included in the output.

      I think there's some mention somewhere in the Zend Framework's documentation about this being the preferred coding style. One of the appendices.

        If the last token in the file is going to be "?>", then it can be left off. Any trailing whitespace at the end of the file would then be parsed as PHP code and therefore not included in the output.

        Oddly enough - I was/am using Zend Studio for Eclipse IDE, and it made the file like that with the closing ?>, plus the whitespace.

        Thanks for the tip though.

          Another tip then: instead of just selecting the "Plain PHP" template for your ZF files, use the "Zend Framework" template file. If you've picked a plain PHP project then you'll probably need to go to the template preferences, find the "Zend Framework" template, and change its context.

          Or you could just edit the Plain PHP template.

            Write a Reply...