【问题标题】:function is not getting updated value of variable from another function in codeigniter函数未从 codeigniter 中的另一个函数获取变量的更新值
【发布时间】:2021-10-28 10:37:17
【问题描述】:

方法addNew()中变量$jwtoken的值为null。我想将auth() 方法值“some val”传递给addNew() 方法/函数。

class Employees extends CI_Controller
{
    public $jwtoken = null;
    
    public function __construct()
    {
        parent::__construct();
    }
            
    public function auth() {
        if(condition is true){
           $this->jwtoken = 'val1';
        }
        else{
          $this->jwtoken = 'val2';
        }
        
    }
    
    public function addNew()
    {
        $this->auth();
        echo $this->jwtoken;
    }
    // ..
}

【问题讨论】:

    标签: php codeigniter-3


    【解决方案1】:

    试试这个..

    员工类扩展 CI_Controller{

      public function __construct()
      {
        parent::__construct();
      }
    
      public function auth() {
           if(condition==true){
                return "some val";
            }else{
              return "some other val";
            }
      }
    
      public function addNew()
      {
         echo $this->auth();
        
      }
      
    

    }

    您的代码在 codeigniter 4 中运行良好。尝试删除构造函数。

    【讨论】:

    • $Hashan 请根据问题/帖子更改再次回复
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-18
    • 1970-01-01
    • 1970-01-01
    • 2012-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多