Phalcon模型关系..ToMany()不起作用

时间:2015-03-17 08:55:28

标签: php model-view-controller model phalcon

我试图通过Users_Group使用不同的方法,使用和不使用命名空间,使用hasManyToMany和hasMany等设置模型用户和组之间的关系。没有任何作用,并给我错误: Fatal error: Class 'Users_Groups' not found ... 这是我的UserController部分:

    public function registerAction()
{
    $user = new Users();
    $password = $this->security->hash($this->request->getPost('password'));
    $signup = array(
        'name'=>$this->request->getPost('name'),
        'username'=>$this->request->getPost('username'),
        'email'=>$this->request->getPost('email'),
        'password'=>$password,
        'active'=>'Y',
        'datetime'=>date('Y-m-d H:i:s', time())
        );
    //Store and check for errors
    $success = $user->save($signup, array('name', 'username', 'email', 'password', 'active', 'datetime'));
    $group = Groups::findByName('user');
    $userGroup = new Users_Groups();
    $userGroup->user_id = $user->getId();
    $userGroup->group_id = $group->getId();
    $groupSuccess = $userGroup->save();
    if ($success && $groupSuccess) {
        echo "Thanks for registering!";
    } else {
        echo "Sorry, the following problems were generated: ";
        foreach ($user->getMessages() as $message) {
            echo $message->getMessage(), "<br/>";
        }
    }

    $this->view->disable();

}

以下是用户型号:

    public function initialize()
{
    $this->hasMany(
        'id',
        'Users_Groups',
        'user_id'
        );

    $this->hasMany('id','Qsos','user_id');

    $this->hasMany('id','Configs','user_id');
}

以下是群组模型:

    public function initialize()
{
    $this->hasMany(
        'id',
        'Users_Groups',
        'group_id'
        );
}

最后是Users_Groups模型

    public function initialize()
{
    $this->belongsTo('user_id','Users','id');
    $this->belongsTo('group_id','Groups','id');
}

请帮忙!它让我发疯了!

0 个答案:

没有答案