开发者

Cakephp saving 10 new rows after checking id of the user

I'm trying to create 10 new rows in controller if the userid is not found in the user_id row. I tried create() function and then save() function but it doesn't seem to do the job. Below is the code, is there a way we can solve this issue?

function invite_fellows(){

        //Read userid
        $userid = $this->Session->read('Auth.User.id');

        $invite_table = $this->User->Invite->findbyUserId($userid);
开发者_如何学运维
        if(empty($invite_table)){
            $code_limit = 10;
            //Save 10 unique codes for the user
            for($i=0; $i<$code_limit;$i++){
                $unique_id = $this->_unique($userid); // Unique id with userid as initial prefix
                $this->data['Invite'] = array('user_id' => $userid, 'code' => $unique_id);
                $this->User->Invite->create();
                $this->User->Invite->save($this->data['Invite']);
            }
        }


        //Find user in users and associated tables
        $user = $this->User->findbyId($userid);

        //Find user in invite table
        $confirmed = $this->User->Invite->find('count', array('conditions' => array('user_id' => $userid,'invited_user >' => 0)));
        $this->set(compact('user','confirmed'));
    } 

Thank you.


Most likely there's a validation rule that blocks the save. Try adding debug( $this->User->Invite->validationErrors ); after the save() to check for that. Make sure debug level is set to at least 1 in core.php.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜