thinkphp variable Saving problem

Source: Internet
Author: User
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');        }    }

A variable ID is obtained from the front end in Addassets (), stored in the local UID, and then the Display addassets.html page. However, this page does not use the UID variable, and the next page (Addassets.html has a button to jump to actaddassets.html) actaddassets.html need to use the UID this variable. The UID is not available in Actaddassets () by the above method.
First study, but also to the great God guidance, thank you!

Reply content:

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');        }    }

A variable ID is obtained from the front end in Addassets (), stored in the local UID, and then the Display addassets.html page. However, this page does not use the UID variable, and the next page (Addassets.html has a button to jump to actaddassets.html) actaddassets.html need to use the UID this variable. The UID is not available in Actaddassets () by the above method.
First study, but also to the great God guidance, thank you!

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');        }        */    }

Do some experimenting, define a static $uid_t, and then do not output the page in Addassets (), Directly echo Self:: $uid _t is a value, but then echo self again in Actaddassets ():: $uid _ T is not worth it. Why is this ...? Thank you!

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.