我创建了一个没有数据库表的yii模型,但现在的问题是,每当我试图在视图文件中调用模型函数时,它都无法识别
class blah extends CActiveRecord() public static function model($className=__CLASS__) { return parent::model($className); } public function tableName() { return '{{UNVETTED}}'; } public function sayHello() { echo "hello world"; } }
在视图中我称之为这样
blah :: model() – > sayHello(),然后我得到了死亡白页,为什么会这样?
如果要创建没有表的Yii模型,可以使用
CFormModel创建.您可以定义模型变量,规则和属性标签.
使用CFormModel创建的更改密码表单的示例代码.
<?PHP class ChangePassword extends CFormModel { public $password; public $verifyPassword; public $currentPassword; public function rules() { $rules[] = array('currentPassword','safe'); $rules[] = array('currentPassword','required'); $rules[] = array('password,verifyPassword','required'); $rules[] = array('verifyPassword','compare','compareAttribute' =>'password','message' => 'Retyped password is incorrect'); return $rules; } /** * Declares attribute labels. */ public function attributeLabels() { return array( 'password'=>'New password','verifyPassword'=>'Retype your new password','currentPassword'=>'Your actual password',); } }