全部博文(921)
分类:
2007-01-03 09:25:22
php
/**
* FileName: newsController.php
* Introduce: 新闻控制类
*
* @author: 大师兄
* @Email: teacherli@163.com
* @version $Id$
* @copyright 2004-10-26
**/
include_once ("./controller/comm/controller.class.php");
include_once ("./model/news/newsModel.php");
class NewsController extends Controller
{
private $model;
/**
* 构造函数
*
**/
public function __construct()
{
parent::__construct();
$this->model = new NewsModel();
$this->setSmartyTemplate_dir("./view/news");
}
/**
* 显示新闻列表
*
**/
public function showList()
{
$newsList = & $this->model->getList();
$this->smarty->assign("newsList", $newsList);
unset($newsList);
$this->smarty->display("newsList.html");
}
}
?>
php
/**
* FileName: controller.class.php
* Introduce: Base class of controller
*
* @author: 李晓军
* @Email: teacherli@163.com
* @version $Id$
* @copyright 2004-10-26
**/
include_once ("./comm/smarty/Smarty.class.php");
include_once ("./comm/config.inc.php");
abstract class Controller
{
private $smarty;
/**
* 系统构建函数
* 初始化Smarty
**/
function __construct()
{
$this ->smarty = new Smarty();
$this->smarty->template_dir = "./view/templates";
$this->smarty->compile_dir = "./view/templates_c";
$this->smarty->cache_dir = "./view/cache";
$this->smarty->cache_lifetime = 60 * 60 * 24;
$this->smarty->caching = false;
$this->smarty->left_delimiter = "<{";
$this->smarty->right_delimiter = "}>";
}
/**
* 设置smarty模板路径
*
* @param string $template
**/
public function setSmartyTemplate_dir($template)
{
$this->smarty->template_dir = $template;
}
/**
* 设置smarty是否进行缓存
*
* @param boolean $cache
**/
public function setSmartyCache($cache = false)
{
$this->smarty->cache = $cache;
}
/**
* 设置smarty缓存时间
*
* @param string $cacheLifetime
**/
public function setSmartyCacheTime($cacheLifetime)
{
$this->smarty->cache_lifetime = $cacheLifetime;
}
/**
* 动作被执行后一个短暂的提示
*
* @param string $module 重新定向到的模块名称
* @param string $action 重新定向的动作名称
* @param string $params 参数名称
* @param string $message 提示信息
**/
public function redirect($module, $action, $params="", $message="动作已经被成功执
行")
{
$time = WAIT_FOR_TIME;
$params = ("" == $params) ? "" : "&$params";
$URL = "?module=" . $module . "&action=" . $action . $params;
//重新定Smarty模板目录至公用目录
$this->setSmartyTemplate_dir("./view/templates");
$this->smarty->assign("URL", $URL); //重定向的目录
$this->smarty->assign("message", $message); //提示信息
$this->smarty->assign("time", $time);
$this->smarty->display("wait.html");
}
/**
* 调用本类不存在的方法时进行的处理
*
* @param string $name
* @param string $parameter
**/
public function __call($name, $parameter)
{
throw new ActionNotAllowException("对不起,你所请求的动作 $name 没有定义
...
");
}
/**
* 析构函数
*
**/
public function __destruct()
{
unset($this->smarty);
}
}
?>