public function action_view($slug) { // $post = Model_Post::find_by_slug($slug); $post = Model_Post::find_by_slug($slug, array('related' => array('user'))); echo"<pre>"; print_r($post); echo"</pre>"; die(); $this->template->title = $post->title; $this->template->content = View::forge('blog/view', array( 'post' => $post, )); }
<?php class Model_User extends \Orm\Model { protected static $_has_many = array('posts'); protected static $_properties = array( 'id', 'username', 'password', 'group', 'email', 'last_login', 'login_hash', 'profile_fields', 'created_at', 'updated_at' ); protected static $_observers = array( 'Orm\Observer_CreatedAt' => array( 'events' => array('before_insert'), 'mysql_timestamp' => false, ), 'Orm\Observer_UpdatedAt' => array( 'events' => array('before_save'), 'mysql_timestamp' => false, ), ); }
<?php class Model_Post extends \Orm\Model { protected static $_belongs_to = array('user'); protected static $_properties = array( 'id', 'title', 'slug', 'summary', 'body', 'user_id', 'created_at', 'updated_at', ); protected static $_observers = array( 'Orm\Observer_CreatedAt' => array( 'events' => array('before_insert'), 'mysql_timestamp' => false, ), 'Orm\Observer_UpdatedAt' => array( 'events' => array('before_save'), 'mysql_timestamp' => false, ), ); public static function validate($factory) { $val = Validation::forge($factory); $val->add_field('title', 'Title', 'required|max_length[255]'); $val->add_field('slug', 'Slug', 'required|max_length[255]'); $val->add_field('summary', 'Summary', 'required'); $val->add_field('body', 'Body', 'required'); $val->add_field('user_id', 'User Id', 'required|valid_string[numeric]'); return $val; } }
$ curl get.fuelphp.com/oil | sh $ oil create blog
$post = Model_Post::query()->where('slug', $slug')->related('user')->get_one(); // or $post = Model_Post::find('first', array('where' => array('slug' => $slug), 'related' => array('user')));
It looks like you're new here. If you want to get involved, click one of these buttons!