Page 1 of 1
Using PHP/HTML Files in ZendFramework
Posted: Mon Mar 31, 2008 10:42 pm
by smartcoderin
Hello,
I have started learning Zend Framework. I think the default template/view files are of phtml extension. Tell me how can i use php/html files instead of the phtml files for view.
When i used render('index.html') ,, it shows view error..... Is anyother settings exists?
Pls reply ...
Re: Using PHP/HTML Files in ZendFramework
Posted: Mon Mar 31, 2008 11:41 pm
by Christopher
.phtml files can contain HTML, PHP or both. They are only included, never accessed by the web server directly.
Re: Using PHP/HTML Files in ZendFramework
Posted: Tue Apr 01, 2008 12:09 am
by smartcoderin
The question is how can i render a file with html extension using view's render method,,
I know phtml contain html and php tags,,, But designing is tedious with phtml files..
Re: Using PHP/HTML Files in ZendFramework
Posted: Tue Apr 01, 2008 12:46 am
by Christopher
You can set the default extension, see the manual.
Re: Using PHP/HTML Files in ZendFramework
Posted: Wed Apr 02, 2008 3:44 am
by anto91
There are two simple ways of doing this
Type 1:
Code: Select all
class youClassController extends Zend_Controller_Action {
// add this function to each controller
public function init() {
$this->viewSuffix = 'php';
}
}
I personaly hate this way of doing it
Type 2: the way i do it
in your bootstrap add
Code: Select all
Zend_Loader::loadClass('ApplicationController', '../application/controllers');
Create a class in controllers called ApplicationController
Example contents:
Code: Select all
<?php
class ApplicationController extends Zend_Controller_Action {
protected $db;
public function init() {
$this->db = Zend_Registry::get('db');
// Default variables
$this->view->title = $this->_request->getControllerName();
$this->view->baseUrl = $this->_request->getBaseUrl();
// This adds a user object to view if user not logged in user class uses default values
$this->view->user = new User(Zend_Auth::getInstance()->getIdentity());
}
// Redirect all unknown actions to default to avoid stupid errors
public function __call($method, $arguments) {
$this->_redirect('/error');
}
}
?>
Then in the init function you add
then replace the extended class in your controller
Example
Code: Select all
class fooController extends ApplicationController {
}
Re: Using PHP/HTML Files in ZendFramework
Posted: Thu Apr 03, 2008 9:42 am
by staar2
This is really good example i am going to use your second type example, it is good to have main controller.

But one simple question what does the $this->viewSufix?
Re: Using PHP/HTML Files in ZendFramework
Posted: Thu Apr 03, 2008 4:46 pm
by anto91
If you would have read the thread starters problem you would know.
What it does is that it change the extension of the view that includes, so it includes ".php" instead of ".phtml"