我需要在模型中创建一个新属性,并且发生一些奇怪的事情:
这段代码,工作正常:
class Person extends CActiveRecord {
public $test = "xxx";
public function getRandomToken() {
$temp = $this->test;
return $temp;
}
Run Code Online (Sandbox Code Playgroud)
这段代码不会:
class Person extends CActiveRecord {
public $test = md5(uniqid(rand(), true));
public function getRandomToken() {
$temp = $this->test;
return $temp;
}
Run Code Online (Sandbox Code Playgroud)
为什么?我得到一个带有第二个代码的空白页面,没有错误.
我需要使用create view-page中的随机令牌,我这样做:
echo $model->getRandomToken();
Run Code Online (Sandbox Code Playgroud)
感谢您的支持!
我对CActiveRecord.rules有疑问
public function rules(){
return array(
array('photo_path', 'required', 'on'=>'insert'),
array('photo_path', 'file', 'types'=>'jpg, gif, png', 'allowEmpty'=>true),
);
}
只有在创建模型时才需要Photo_path,在更新视图中它可以为空.
我不知道发生了什么,但一小时前它有效,但现在却没有.当我选择文件时,我得到'照片路径不能为空'
请帮忙 :)