dongrongdao8902 2012-12-22 19:16
浏览 54
已采纳

将控制器中定义的变量传递给CodeIgniter下的模型

I defined a variable in a method inside controller e.g.

class test extends CI_Controller {
    function tester() {
    $variable = 'value'
    }
}

Now I want to call this variable in my model. How is that possible?

Edit: I use CodeIgniter.

  • 写回答

2条回答 默认 最新

  • douqianni4080 2012-12-22 19:31
    关注

    Model:

    class your_model extends CI_Model {
        var $variable;
    
        function __construct() {
            parent::__construct();
        }
    
        function set_variable($variable) {
            $this->variable = $variable;
        }
    
    }  
    

    Controller:

    class test extends CI_Controller {
        function tester() {
            $this->load->model('your_model');
            $variable = 'value'
            $this->your_model->set_variable($variable); 
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?