#1 youngqj
class admin extends spController{
function index(){
$tpl=$this->spArgs("template","admin");
}
function login(){
$tpl=$this->spArgs("template","admin");
}
function logout(){
$tpl=$this->spArgs("template","admin");
}
}
每次都要写一次 太重复 有没有其他写法谢谢了 问题很弱智 回复别太打击我信心啊 谢谢了
2010-04-11 11:05:17
#2 jake
是不是这样?
class admin extends spController{
var $tpl = null;
function __construct(){
parent::__construct();
$this->tpl=$this->spArgs("template","admin");
}
function index(){}function login(){}function logout(){>
这是写法是一个spController的技巧,也就是把相同的操作都放到构造函数内来进行。不过这也有个不好的地方:如果不是全部function都需要那个操作,那可能就有些浪费。
PS:重复写一段代码,不是问题,无论在什么开发中,首先要写的,是
符合需要的代码,等测试完毕,甚至是发布了,然后再是优化,重构。
2010-04-11 11:35:59