在我看来我试图这样做:
$accountLogin = new AccountLogin;
应创建在我的供应商库中定义的该类的新实例。
class AccountLogin extends CFormModel
{
..
}
但我得到了unable to open stream('AccountLogin')
。
我做错了什么?我应该在某处指定目录所在的位置吗?
答案 0 :(得分:2)
您必须先导入课程。
野兽以及在yii中导入任何类的简单方法是将它放在这样的组件中:
类别:
class RegionSingleton extends CApplicationComponent
{
private $_model=null;
public function setModel($id)
{
$this->_model=Region::model()->findByPk($id);
}
public function getModel()
{
if (!$this->_model)
{
if (isset($_GET['region']))
$this->_model=Region::model()->findByAttributes(array('url_name'=> $_GET['region']));
else
$this->_model=Region::model()->find();
}
return $this->_model;
}
public function getId()
{
return $this->model->id;
}
public function getName()
{
return $this->model->name;
}
}
在config main中包含此类,然后您可以在所有应用中快速调用它:
'components'=>array(
'region'=>array('class'=>'RegionSingleton'),
...
)
现在,我们可以这样称呼它:
Yii::app()->region->model;
有模型,还是
Yii::app()->region->id
用于检索ID。
我们也可以使用
设置模型Yii::app()->region->setModel($id)
参考: link1