Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
begginer help me
  • This work public function action_view($id = null)
    {
    $data = Model_Post::find($id); $this->template->title = "Post $id";
    $this->template->content = View::forge('post/view', $data); } This does not work public function action_view($id = null)
    {
    $data = Model_Post::find($id); $this->template->title = "Post $title";
    $this->template->content = View::forge('post/view', $data); } I tried other methods but not works? How do I get second result??
  • $id in the first example has a value because it is passed as parameter to action_view().
    But where does $title in the second example come from? It isn't defined anywhere...
  • How do I do to make it work?
  • If this is Phils code, I guess you have to ask him...
  • Harro Verton wrote on Thursday 15th of December 2011:
    $id in the first example has a value because it is passed as parameter to action_view().
    But where does $title in the second example come from? It isn't defined anywhere...

    So you have to store your post first to access its members:
    public function action_view($id = null)
    {
    $post = Model_Post::find($id);
    
    $this->template->title = 'Post'.$post->title;
    $data['post'] = $post;
    $this->template->content = View::forge('post/view', $data);
    
    }
    
  • Thanks =)))) But why referring to this script orm\model.php [ public static function find($id = null, array $options = array()) ] when I wanted to get $title.
  • Vladimir Michalík wrote on Saturday 17th of December 2011:
    But why referring to this script orm\model.php [ public static function find($id = null, array $options = array()) ] when I wanted to get $title.

    Could you please rephrase your question? I'm not sure what you mean by this part of your post.
    The function Model_Post::find($id) is called to find a post in your database, which you then store in $post.
    By calling $post->title (assuming this field exists in your database/Model_Post) you can retrieve the title from the post and use it in $this->template->title

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion