That may be, but it seems to me that you then are performing two
queries for each need to retrieve a record, first to ask if there is
any records, and then to ask for the records! (Maybe I am wrong
here!!)

I think that querying for the records, checking for the number
retrieved, should be the optimal way :) Then always pass the number to
the view, and let the view show some message for the user to stop
messing around :D or some kinder message like "No information found".

Enjoy,
   John

On Oct 16, 9:03 am, "Dave Maharaj :: WidePixels.com"
<[email protected]> wrote:
> There is another that I found.
>
> Model::hasAny
>
> Returns true if a record that meets given conditions exists.
>
> function hasAny($conditions = null) {
> return ($this->find('count', array('conditions' => $conditions, 'recursive'
> => -1)) != false);
>
> }
>
> Which I guess is pretty much the same as my validPost($id) except cleaner.
>
> public function validPost($id)
>       {
>           $valid = false;
>           $params = array(
>                         'contain' => false,
>                         'conditions' => array(
>                                 'Post.id' => $id),
>                         'fields' => array(
>                                 'Post.id'));
>
>           $q = $this->find('first', $params);
>
>           if (!empty($q)) {
>               $valid = true;
>           }
>           return $valid;
>       }
>
> Dave
>
> -----Original Message-----
> From: John Andersen [mailto:[email protected]]
> Sent: October-16-09 2:57 AM
> To: CakePHP
> Subject: Re: Check Valid
>
> I think you can use the models method getNumRows() which returns the number
> of rows returned in the last query!
> Enjoy,
>    John
>
> On Oct 16, 12:19 am, "Dave Maharaj :: WidePixels.com"
> <[email protected]> wrote:
> > If you have posts 1, 2, and 3 for example and you type in view/4 and
> > there is no 4 the page still renders but it has no data. How can you
> > prevent this ?
>
> > I have
>
> > if ($this->Post->validPost($id) == true) {
>
> > which checks the DB for that id if found then do as normal
>
> > } else {
>
> > return them back to index
>
> > }
>
> > Is there an easier way to do that that i over looked?
>
> > Thanks,
>
> > Dave
--~--~---------~--~----~------------~-------~--~----~
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