2012-05-01 18 views
0

我想在我的代码点火器模型中重用变量,但我无法完全理解语法。我遇到的问题是在第4行。CodeIgniter模型中正确的语法

class Products_model extends CI_Model { 

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

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

回答

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/"; 
    } 
} 
+0

感谢您的回答!我花了太多时间输入宽松的php而不是做面向对象的事情。我很感激提醒。 :) – BFTrick

+0

很高兴我可以帮助:) –