Just started using Kohana... Have a few questions
I just started using Kohana a couple days ago, and I have a few questions that I cant seem to find an answer to anywhere.
Using ORM, how can you package information before you send it off? If I have a user model, and each user has a username, email, date of birth, etc... how can I package information (like add the users age as a property) before I send it to the controller?
Using ORM again, I see that if you select a user, you can also select all things related to that user (ie: articles, comments, etc.). How can you order that related information before sending it to the controller?
ie:
<?php
$user = ORM::factory('user', $id);
$user->articles; // holds all articles belonging to a user.
// how can you order those articles dynamically?
In the view, how can you get information about a user who is logged in? Do you use Auth (Auth::instance()->get_user())
, or is there any other way?
Also, If you know any other tips/advice/qwerks about Kohana, please drop a line or two, you may answer a future question of mine.
Thanks.
Edit: Another question. Using the ORM, I want to be able to load all articles that posted, in which a user has made a comment.
comments table
comment_id
user_id
article_id
etc....
Using ORM, I can access all articles posted by a user, but how would I be able to access all开发者_StackOverflow articles in which the user has commented on?
Thanks
If you are using Kohana v3, you can order records like so:
$articles = ORM::factory('user', $id)->articles
->order_by('date', 'DESC')
->find_all();
If you are using Kohana v2, the same thing can be achieved using:
$articles = ORM::factory('user', $id)->orderby('date', 'DESC')
->articles;
And you were correct about accessing the user record through Auth::instance()->get_user()
(if you are using the ORM Auth driver)
精彩评论