#1 stalker
class test extends spController这样不提示出错 但是在视图中却接收不到设置的新值 正确的设置方法应该是?
{
public function __construct()
{
$this->var = array('a'=>1, 'b'=>2);
}
public function index()
{
$this->var['a'] = 3;
}
}
2013-04-04 00:31:05
class test extends spController这样不提示出错 但是在视图中却接收不到设置的新值 正确的设置方法应该是?
{
public function __construct()
{
$this->var = array('a'=>1, 'b'=>2);
}
public function index()
{
$this->var['a'] = 3;
}
}
2013-04-04 00:31:05
class test extends spController
{
var $tmp;
public function __construct()
{
$this->tmp = array('a'=>1, 'b'=>2);
}
public function index()
{
$this->tmp['a'] = 3;
$this->var = $this->tmp;
}
}
2013-04-04 08:16:00
class top extends spController我搜了下之前的帖子 感觉这位水哥的代码不错 既实现了在视图最终输出的时候才给视图赋值最后的成员变量值 也实现了通过给成员变量赋值的方式给视图类赋值 因为对于同一个成员变量相同的controller下不同的action可能需要不同的值(但大部分都是一样的) 所以希望认真考虑一下这种情况 相信以后遇到这个问题的人会越来越多
public function __set($name,$value)
{}
public function display($tplname, $output = TRUE)
{
//水哥新增加代码部分
//获得所有public成员变量,赋值给模板
$array=get_object_vars($this);
foreach($array as $name => $value){
if(TRUE == $GLOBALS['G_SP']['view']['enabled'] && false !== $value){
$this->v->engine->assign(array($name=>$value));
}
$this->__template_vals[$name] = $value;
}
//ends of 水哥
@ob_start();
if(TRUE == $GLOBALS['G_SP']['view']['enabled']){
$this->v->display($tplname);
}else{
extract($this->__template_vals);
require($tplname);
}
if( TRUE != $output )return ob_get_clean();
}
}
2013-04-04 11:12:36
2013-04-04 11:30:59
2013-04-04 11:52:19
class top extends spController
{
public function __construct()
{
parent::__construct();
$this->title = 'ZZZZZZ';
}
}
而某些页面的标题需要不太一样 按照现在的情况就需要以下两个步骤才能实现:
<{$title}>
....
class test extends top第二:在视图模板中修改smarty变量
{
public function index()
{
$this->abctitle = 'XXXXX - '.$this->title;
}
}
而如果在生成视图的时候再给视图类赋值的话这两步都不需要
<{$abctitle}>
....
2013-04-04 16:40:18
2013-04-04 16:47:06
2013-04-04 17:16:50
2013-04-04 17:41:35
2013-04-04 18:33:45
2013-04-05 05:05:41