yii 2011-02-28 09:47:47 7145次浏览 4条回复 0 0 0

请教高手,现在我有这样的需求。内容表中ID不是自增的整型,而是字符型。生成GUID,我现在有一个GUID类,请教高手我该如何做?

多谢:P

  • 回复于 2011-02-28 14:03 举报

    在models/User.php下添加如下代码:

    /*
    * 生成GUID
    */
    protected function beforeSave(){
      $computer_name = $_SERVER["SERVER_NAME"];  
      $ip = $_SERVER["SERVER_ADDR"];  
      $guid = new Guid($computer_name, $ip); 
      $id= $guid->toString(); 
      $this->id = $id;  
    }
    

    表单提交不成功,没有插入数据库数据,也无错误提示信息。请舰长明察,多谢

  • 回复于 2011-02-28 14:28 举报

    照样做了,还是显示:

    PHP Error
    
    Non-static method NetAddress::getHost() should not be called statically, assuming $this from incompatible context
    
    \protected\components\Guid.php(10)
    
    function getGuid($coumputer_name, $ip){  
    10  $address = NetAddress::getHost($coumputer_name, $ip);
    11  $this->valueBeforeMD5=$address->toString().':'.System::currentTimeMillis().':'.Random::nextLong();  
    12  $this->valueAfterMD5 = md5($this->valueBeforeMD5);  
    }
    
  • 回复于 2011-02-28 14:41 举报

    第11行,改成 static function getHost($coumputer_name, $ip)

  • 回复于 2011-02-28 14:58 举报

    已解决,多谢舰长关注,呵呵

您需要登录后才可以回复。登录 | 立即注册