Hey guys,

i am new to cakephp and fail at saving data. I got a model Profile
which contains many user-profile information. In one action i want to
rate the profile using ajax and save the rating to the database:
(unrelated stuff commented)

    function rate($id = null, $points=null) {
//        Configure::write('debug', 0);
//        $this->autoRender = false;
//        $this->disableCache();
//        $this->RequestHandler->setContent('json', 'text/x-json');
//        if ($this->RequestHandler->isAjax()) {
//            if ( $this->Profile->exists($id) && preg_match('#^[0-9]+
$#',$points) && (int)$points >=1 && (int)$points <= 10 ) {
//                $canVote = $this->Profile->Rating->canVote($id);
//                if ($canVote) {
                    $profile = $this->Profile->read(null, $id);

                    $saveData = array('Profile' => array());
                    $saveData['Profile']['rating'] =
$profile['Profile']['rating'] + $points;
                    $saveData['Profile']['raters'] =
$profile['Profile']['raters'] + 1;
                    $saveData['Profile']['avgrating'] =
$saveData['Profile']['rating']/$saveData['Profile']['raters'];

                    var_dump($this->Profile->save($saveData));

//                    $this->Profile->Rating->create();
//                    $this->Profile->Rating->set('ip',
$_SERVER['REMOTE_ADDR']);
//                    $this->Profile->Rating->set('profile_id', $id);
//                    $this->Profile->Rating->save();

                    $jsonData = $saveData['Profile'];

                    echo json_encode($jsonData);
                    exit(0);
//                }
//            }
//        }
//        echo '0';
//        exit(0);
    }

Well if i call this page in browser, the output is:

bool(false) {"rating":20,"raters":4,"avgrating":5}

Obviously the saving failed, but why?
The Profile model has no validation rules for the fields used here,
however it has rules for other fields...

If i use something like this:
 $this->Profile->saveField('raters', $this->Profile->field('raters') +
1 );
it works but causes too many mysql querys :(

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to