0

我试图在我的 Code Igniter 模型中重用变量,但我不能完全理解语法。我遇到的问题在第 4 行。

class Products_model extends CI_Model {

var $gcsServerIpAddress = "11.22.33.44";
var $gcsServerAddress = "http://".$this->gcsServerIpAddress."/eft/"; 

我尝试过对象语法:$this->foo。我也尝试过使用变量名:$foo。他们都没有工作。有什么建议么?

4

1 回答 1

1

尝试在构造函数中设置值。

class Products_model extends CI_Model {
    var $gcsServerIpAddress;
    var $gcsServerAddress;

    function __construct(){
        $this->gcsServerIpAddress = "11.22.33.44";
        $this->gcsServerAddress = "http://".$this->gcsServerIpAddress."/eft/"; 
    }
}
于 2012-05-01T20:33:38.300 回答