Kohana PHP question

I have a database with a table named shoppingcarts

. this table has the following 3 columns:

id, sessionid, date

      

I have a function ( AddProductToCart

) in my controller ( ShoppingCart

). Inside my function, I have this call:

$obj = ORM::factory('shoppingcart')->where('sessionID',session_id())->find();

      

Now this operator works on a table shoppingcarts

and returns a string that sessionid

matches the current session id (PHP session_id()

). But sometimes it sessionid

doesn't exist in the table.

So how can I check the value returned by this operator to see if the value was returned or not?

I'm confused.

0


a source to share


1 answer


You are looking for the "loaded" property. Docs

It will look something like this:



$obj = ORM::factory('shoppingcart')->where('sessionID',session_id())->find();

if($obj->loaded == TRUE)
{
  // user has a shopping cart
}
else
{
  // no shopping cart found
}

      

+4


a source







All Articles