FuelPhp解码视图中的HTML实体

Right now I am displaying HTML in my view by using html_entity_decode:

<strong>Body:</strong>
<?php echo html_entity_decode($post->body); ?></p>

But is there another way to do in when I am passing data to my view, in:

public function action_view($id = null)
    {
        $data['post'] = Model_Post::find($id);

        is_null($id) and Response::redirect('Post');

        $this->template->title = "Post";
        $this->template->content = View::forge('post/view', $data);
    }

I read the documentation and tried:

public function action_view($id = null)
    {
        $data['post'] = Model_Post::find($id);

        is_null($id) and Response::redirect('Post');

        $this->template->title = "Post";
        $this->template->content = View::forge('post/view', $data);
                View::$auto_encode = false;
    }

But this just gave me an "access to undeclared static property". Clearly I am doing something wrong...

As I can see you are not setting auto_encode correctly.

Try this and see if it's what you are looking for.

public function action_view($id = null)
{
    $view = View::forge('post/view');
    is_null($id) and Response::redirect('Post');

    $post = Model_Post::find($id);
    $view->set('post', $post, false); //Here the auto_encode is set to false

    $this->template->title = "Post";
    $this->template->content = $view;
}

Hope this helps

There are abunch of ways to do this:

protected $this->auto_encode = false;

That property in the controller will stop ALL assigned values from being encoded.

Otherwise, use this:

$this->template->set('title', "Post", false);
$this->template->set('content', $view, false);

That'll stop the specific value being encoded.