I need help.
I tried integrating smarty template engine with doophp and my template test page is not displaying in the browser.
Here is what I have done
1. In template_engine demo folder I added smarty library in the
protected/class/smarty/ folder.
2. I created
SmartyController.php in the
protected/contoller/ folder:
- Code: Select all
<?php
class SmartyController extends DooController{
public function smartyView($smarty=true){
if($smarty){
//initiate Smarty
if($this->_view==NULL){
//include(Doo::conf()->SITE_PATH. 'protected/class/smarty/Smarty.class.php');
Doo::loadClass('smarty/Smarty.class');
$template = new Smarty;
$template->compile_check = false;
$template->force_compile = true;
//you can use this if you want to use smarty debugging
if(isset($_GET['debug'])){
$template->debugging = true;
}else{
$template->debugging = false;
}
//you can use this to clear template cache
if(isset($_GET['reset'])){
$template->clear_all_cache();
}
$template->template_dir = Doo::conf()->SITE_PATH . "protected/view";
$template->compile_dir = Doo::conf()->SITE_PATH . "protected/viewc";
$template->cache_dir = Doo::conf()->SITE_PATH . "protected/cache";
$template->config_dir = Doo::conf()->SITE_PATH . "protected/config";
$this->_view = $template;
}
}else{
if($this->_view==NULL){
Doo::loadCore('view/DooView');
$this->_view = new DooView;
}
}
return $this->_view;
}
}
}
?>
3. I created another
MysmartyController.php in the
protected/controller/ folder
- Code: Select all
<?php
/**
* Description of MySmartyController
*
* @author Peter
*/
Doo::loadController('SmartyController');
class MysmartyController extends SmartyController {
function test(){
$data['title'] = 'Smarty Test Template';
$data['name'] = 'Peter';
$this->smartyView()->assign('title', $data['title']);
$this->smartyView()->assign('name', $data['name']);
$this->smartyView()->display('mysmarty_template.tpl');
}
}
?>
4. I created the file
mysmarty_template.tpl file in
protected/view/ folder
- Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>{$title}</title>
</head>
<body>
<p>hello {$name}.</p>
</body>
</html>
5. I entered the following entry in the
protected/config/routes.conf.php file:
- Code: Select all
<?php
/**
* Define your URI routes here.
*
* $route[Request Method][Uri ] = array( Controller class, action method, other options, etc. )
*
* RESTful api support, *=any request method, GET PUT POST DELETE
* POST Create
* GET Read
* PUT Update, Create
* DELETE Delete
*/
$route['*']['/'] = array('MainController', 'index');
$route['*']['/url'] = array('MainController', 'url');
$route['*']['/example'] = array('MainController', 'example');
$route['*']['/error'] = array('ErrorController', 'index');
$route['*']['/html'] = array('HtmlController', 'test');
$route['*']['/php'] = array('PhpController', 'test');
$route['*']['/smarty'] = array('MysmartyController', 'test');
$route['*']['/about'] = $route['*']['/'];
//----------- Template routes ---------
$route['*']['/template.html'] = array('MainController', 'template_source');
?>
6. when i browse
http://localhost/doophp/demos/template_engine/index.php/smarty I get
webpage cannot be displayed message.
ANY ERRORS in my code??