public function index()
{
//$this->load->view('welcome_message');
$data['title'] = '标题';
$data['num'] = '123456789';
//$this->cismarty->assign('data',$data); // 也可以
$this->assign('data',$data);
$this->assign('tmp','hello');
//$this->cismarty->display('test.html'); // 也可以
$this->display('test.html');
}
<?php
if(!defined('BASEPATH')) EXIT('No direct script asscess allowed');
require_once( APPPATH . 'libraries/Smarty-2.6.26/libs/Smarty.class.php' );
class Cismarty extends Smarty {
protected $ci;
public function __construct(){
$this->ci = & get_instance();
$this->ci->load->config('smarty');//加载smarty的配置文件
//获取相关的配置项
$this->template_dir = $this->ci->config->item('template_dir');
$this->complie_dir = $this->ci->config->item('compile_dir');
$this->cache_dir = $this->ci->config->item('cache_dir');
$this->config_dir = $this->ci->config->item('config_dir');
$this->template_ext = $this->ci->config->item('template_ext');
$this->caching = $this->ci->config->item('caching');
$this->cache_lifetime = $this->ci->config->item('lefttime');
}
}
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$config['theme'] = 'default';
$config['template_dir'] = APPPATH . 'views';
$config['compile_dir'] = FCPATH . 'templates_c';
$config['cache_dir'] = FCPATH . 'cache';
$config['config_dir'] = FCPATH . 'configs';
$config['template_ext'] = '.html';
$config['caching'] = false;
$config['lefttime'] = 60;
$autoload['libraries'] = array('Cismarty');
//目的是:让系统运行时,自动加载,不用人为的在控制器中手动加载
<?php if (!defined('BASEPATH')) exit('No direct access allowed.');
class MY_Controller extends CI_Controller { // 原文这里写错
public function __construct() {
parent::__construct();
}
public function assign($key,$val) {
$this->cismarty->assign($key,$val);
}
public function display($html) {
$this->cismarty->display($html);
}
}
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends MY_Controller { // 原文这里写错
public function index()
{
//$this->load->view('welcome_message');
$data['title'] = '标题';
$data['num'] = '123456789';
//$this->cismarty->assign('data',$data); // 亦可
$this->assign('data',$data);
$this->assign('tmp','hello');
//$this->cismarty->display('test.html'); // 亦可
$this->display('test.html');
}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>{ $test.title}</title> //( 原文是 <title>{$test['title']}</title>,是错误的写法,也有可能是Smarty版本的原因)
<style type="text/css">
</style>
</head>
<body>
{$test.num|md5} // 原文这里也写错了
<br>
{$tmp}
</body>
</html>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有