doudiyu1639 2015-03-17 08:55
浏览 78

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

I tried to setup relationships between models Users and Groups via Users_Group using different methods, with and without namespace, with hasManyToMany and hasMany etc. nothing works and gives me error: Fatal error: Class 'Users_Groups' not found ... Here is my UserController portion:

    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();

}

Here is Users model:

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

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

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

Here is Groups model:

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

And finally Users_Groups model

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

Please help! It drives me crazy!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?