<code>class AdminAction extends Action { private $uid_t; public function addassets(){ $uid = I('id'); $this->uid = $uid; $this->setuid_t($uid); $this->display(); } public function setuid_t($uid){ $this->uid_t = $uid; } public function getuid_t(){ return $this->$uid_t; } public function actaddassets(){ $data['uid'] = $this->getuid_t(); $data['assets_name'] = I('assets_name'); if ($id=M('device')->add($data)) { $this->redirect('index'); }else{ echo M('device')->getLastsql();exit; $this->redirect('addassets'); } } </code>
在addassets()中从前端获得了一个变量id,保存在本地的uid,然后display出addassets.html页面。但是这个页面中不用uid这个变量,而下一个页面(addassets.html中有一个button跳转到actaddassets.html)actaddassets.html中需要用到uid这个变量。通过上面的方法在actaddassets()中获得不了uid这个变量。
初次学习,还往大神指点,谢谢!
<code>class AdminAction extends Action { private $uid_t; public function addassets(){ $uid = I('id'); $this->uid = $uid; $this->setuid_t($uid); $this->display(); } public function setuid_t($uid){ $this->uid_t = $uid; } public function getuid_t(){ return $this->$uid_t; } public function actaddassets(){ $data['uid'] = $this->getuid_t(); $data['assets_name'] = I('assets_name'); if ($id=M('device')->add($data)) { $this->redirect('index'); }else{ echo M('device')->getLastsql();exit; $this->redirect('addassets'); } } </code>
在addassets()中从前端获得了一个变量id,保存在本地的uid,然后display出addassets.html页面。但是这个页面中不用uid这个变量,而下一个页面(addassets.html中有一个button跳转到actaddassets.html)actaddassets.html中需要用到uid这个变量。通过上面的方法在actaddassets()中获得不了uid这个变量。
初次学习,还往大神指点,谢谢!
<code>class AdminAction extends Action { static $uid_t=""; public function addassets(){ $uid = I('id'); $this->uid = $uid; self::$uid_t = $uid; $this->display(); //echo self::$uid_t; } public function actaddassets(){ echo self::$uid_t; /* $data['uid'] = $uid; $data['assets_name'] = I('assets_name'); if ($id=M('device')->add($data)) { $this->redirect('index'); }else{ echo M('device')->getLastsql();exit; $this->redirect('addassets'); } */ } </code>
做了一些尝试,定义一个static的$uid_t,然后在addassets()中不输出页面,直接echo self::$uid_t是有值的,但是紧接着在actaddassets()中再次echo self::$uid_t就没值了。。求教这是为什么。。?谢谢!