You need to put your verifyReserve method into your Reserve model, not
your controller. Also, I'm pretty sure your verifyReserve method would
always return true, as query() returns a resultset, not a single
field.

This is more cake-like...


class Reserve extends AppModel {

    $name = 'Reserve';

    function verifyReserve($official_id, $reserve_date, $reserve_time)
{
        return $this->hasAny(compact('official_id', 'reserve_date',
'reserve_time'));
    }

}


However having said that, a custom validation method may fit this
better and require less code, but one step at a time :)

Hope that helps,
Adam

On Sep 25, 11:01 pm, Fernando Mendonça <[EMAIL PROTECTED]> wrote:
> Hello everybody,
>
> I've a problem... I'm starting to learn how to use CakePHP and I'm
> trying to write a new Action in one of my Controllers. I need to
> recuperate values sent by a View and validate them.
>
> The idea is: The user makes a reserve to one Official in one Date and
> Time. I've to verify if this reserve already exists in my database
> when he tries to make another one.
>
> So, I wrote this Action in Reserve Controller:
>
> function verifyReserve($official, $date, $time) {
>         if($this->Reserve->query("SELECT COUNT(reserves.id) FROM reserves
> WHERE official_id='$official' AND reserve_date='$date' AND
> reserve_time='$time'") != 0) {
>                         return true;
>                 } else {
>                         return false;
>                 }
>         }
>
> And into the Action "Add" of the Reserve Controller I wrote this
> validade:
>
> if(($this->Reserve->verifyReserve($this->data['Reserve']
> ['official_id'], $this->data['Reserve']['reserve_date'], 
> $this->data['Reserve']['reserve_time'])) == true)
>
> {
>         $this->Session->setFlash(Already exists an reserve for this official
> on this date and time.');
>         $this->set('officials', $this->Reserve->Official->generateList(null,
> 'name', null,'{n}.Offical.id','{n}.Official.name'));
>         $this->set('customers', $this->Reserve->Customer->generateList(null,
> 'name', null,'{n}.Customer.id','{n}.Customer.name'));
>
> }
>
> However, when I try to make a reserve an error occurs:
>
> Query: verifyReserve
> Warning: SQL Error: 1064: You have an error in your SQL syntax; check
> the manual that corresponds to your MySQL server version for the right
> syntax to use near 'verifyReserve' at line 1 in C:\xampp\htdocs\cake
> \cake\libs\model\datasources\dbo_source.php on line 440
>
> Warning: Cannot modify header information - headers already sent by
> (output started at C:\xampp\htdocs\cake\cake\basics.php:697) in C:
> \xampp\htdocs\cake\cake\libs\controller\controller.php on line 447
>
> Help me, please.
>
> Thanks :o)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
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