Harro Verton wrote on Friday 10th of February 2012:That doesn't get anything, that just returns the query object. You have to do either get() or get_one() to execute the query.
Harro Verton wrote on Friday 10th of February 2012:You can only get a query. The way find() works is explained in the documentation. In short, 'first', 'last' and 'all' do an implicit get(), find() without parameters creates a query object that you can use to chain additional methods to. A query object has to be executed using get() or get_one() to get a result.
Harro Verton wrote on Friday 10th of February 2012:get() returns an array of objects. Did you actually look at the documentation? This is all explained including examples.
// find all users (returns an array of Model_Blog_User objects) $users = Model_Blog_User::find('all'); // find the first user (returns a Model_Blog_User object) $user = Model_Blog_User::find('first'); // find all users called 'John' (returns an array of Model_Blog_User objects) $users = Model_Blog_User::find()->where('first__name', '=', 'John')->get(); // find the first user called 'John' (returns a Model_Blog_User object) $user = Model_Blog_User::find()->where('first__name', '=', 'John')->get_one();
Harro Verton wrote on Friday 10th of February 2012:If $post is an ORM model object, you can't get() it! You can only get() find queries. So:// find all users (returns an array of Model_Blog_User objects) $users = Model_Blog_User::find('all'); // find the first user (returns a Model_Blog_User object) $user = Model_Blog_User::find('first'); // find all users called 'John' (returns an array of Model_Blog_User objects) $users = Model_Blog_User::find()->where('first__name', '=', 'John')->get(); // find the first user called 'John' (returns a Model_Blog_User object) $user = Model_Blog_User::find()->where('first__name', '=', 'John')->get_one();
The queries that return a single model object will return NULL if nothing is found. The queries that return multiple objects return an empty array if nothing is found.
$post = Model_Blog_User::find()->where('user_login', Input::post('user_login')); $user_data = $post->get();It executes, returns the array into $user_data. but how do i read the objects inside the array?? When i get some values like
$post = Model_Blog_User::find($user_id);, I can read the fields like
$post->user_email. But doing
$user_data->user_emaildoesn't work cause its a not object. So how do i get the values from
$user_data?? print_r($user_data) returns the following but how to read the values?
Array ( [13] => Model_Blog_User Object ( [_is_new:Orm\Model:private] => [_frozen:Orm\Model:private] => [_data:Orm\Model:private] => Array ( [user_id] => 13 [user_login] => KickB [user_pass] => 5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8 [user_name] => kick bottowski [user_email] => kick@awesome.com [user_url] => [user_activation_key] => 36bb6dcb8bf4e07fe50a76be29cc31b8 [user_status] => 1 [user_last_login] => 1328898667 [created_at] => 1328898667 [updated_at] => 1328898691 ) [_original:Orm\Model:private] => Array ( [user_id] => 13 [user_login] => KickB [user_pass] => 5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8 [user_name] => kick bottowski [user_email] => kick@awesome.com [user_url] => [user_activation_key] => 36bb6dcb8bf4e07fe50a76be29cc31b8 [user_status] => 1 [user_last_login] => 1328898667 [created_at] => 1328898667 [updated_at] => 1328898691 ) [_data_relations:Orm\Model:private] => Array ( ) [_original_relations:Orm\Model:private] => Array ( ) [_view:Orm\Model:private] => [_iterable:protected] => Array ( ) ) )
Harro Verton wrote on Saturday 11th of February 2012:As I wrote, get() returns an array of objects. The array has an index value equal as the primary key. How do you access array values? That has nothing to do with ORM, that's PHP 101. You can use foreach to iterate over it. You can use $arrayname to access an array element, ...
It looks like you're new here. If you want to get involved, click one of these buttons!