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 ...
Using PHP/HTML Files in ZendFramework
Moderator: General Moderators
-
smartcoderin
- Forum Newbie
- Posts: 2
- Joined: Mon Mar 31, 2008 10:39 pm
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Using PHP/HTML Files in ZendFramework
.phtml files can contain HTML, PHP or both. They are only included, never accessed by the web server directly.
(#10850)
-
smartcoderin
- Forum Newbie
- Posts: 2
- Joined: Mon Mar 31, 2008 10:39 pm
Re: Using PHP/HTML Files in ZendFramework
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..
I know phtml contain html and php tags,,, But designing is tedious with phtml files..
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Using PHP/HTML Files in ZendFramework
You can set the default extension, see the manual.
(#10850)
Re: Using PHP/HTML Files in ZendFramework
There are two simple ways of doing this
Type 1:
I personaly hate this way of doing it
Type 2: the way i do it
in your bootstrap add
Create a class in controllers called ApplicationController
Example contents:
Then in the init function you add
then replace the extended class in your controller
Example
Type 1:
Code: Select all
class youClassController extends Zend_Controller_Action {
// add this function to each controller
public function init() {
$this->viewSuffix = 'php';
}
}
Type 2: the way i do it
in your bootstrap add
Code: Select all
Zend_Loader::loadClass('ApplicationController', '../application/controllers');
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');
}
}
?>
Code: Select all
$this->viewSuffix = 'php';
Example
Code: Select all
class fooController extends ApplicationController {
}
Re: Using PHP/HTML Files in ZendFramework
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
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"
What it does is that it change the extension of the view that includes, so it includes ".php" instead of ".phtml"