SoWhat
SoWhat

Reputation: 5622

Zend Framework is using html files as view script instead of phtml

We had a developer code for us, and he did it in php. When we were studying the code, we noticed that all the views have html as their extension instead of phtml. We checked by renaming a file to phtml, and it gives an error. What's amazing is that they have not done this in the app, they have done it at Zend Level.

IF I replace the zend framework in the library directory with a fresh download, the app stops working. saying that the view was not found

Does anyone know how they did this (modified ZF to search for html instead of phtml files)?

One more thing: all over the place, he's using a variable $this->baseURL (not $this->baseUrl() as provided by zF) which holds the base url. Its not a helper, I checked and can't seem to find the declaration anywhere in the code, but still magically it is available through all the controllers and views. How did they implement? I did a search through all the files, but nowhere is baseURL defined or the option baseURL written to AUTH, STORAGE, or anything. So how did he get to this? Modify the zf again?

Upvotes: 1

Views: 1316

Answers (2)

Ludwig
Ludwig

Reputation: 3729

Have a look at Zend/Controller/Action/Helper/ViewRenderer.php where you should find

protected $_viewSuffix = 'html'

Better ways to change the view suffix is adding this to the application/Bootstrap.php

/**
 * Set default view suffix to .html (see http://framework.zend.com/issues/browse/ZF-5301)
 */
protected function _initViewSuffix()
{
    Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->setViewSuffix('html');
}

Or you can change it by this init method in all controllers

public function init()
{
    $this->_helper->viewRenderer->setViewSuffix('html');
}

Zend_Layout as mentioned by drew010 only changes the suffix of layouts and not of views.

Upvotes: 2

drew010
drew010

Reputation: 69937

They may have changed the Zend Layout class file Zend/Layout.php.

You can check for protected $_viewSuffix = 'html'; instead of phtml which is the default.

You can fix this by adding the following to your bootstrap so you can upgrade the Zend Framework files.

protected function _initViewSuffix()
{
    Zend_Layout::getMvcInstance()->setViewSuffix('html');
}

As for the $baseURL variable, this could have been set via a plugin, or action helper.

If you get the view object you can do something like $view->baseURL = 'xxx'; to make it available. This can be done from a plugin or action helper.

Hope that helps.

Upvotes: 2

Related Questions