0

現在、html_entity_decode を使用してビューに HTML を表示しています。

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

しかし、ビューにデータを渡すときに行う別の方法はありますか?

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);
    }

ドキュメントを読んで試しました:

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;
    }

しかし、これにより、「宣言されていない静的プロパティへのアクセス」が得られました。明らかに私は何か間違ったことをしている...

4

2 に答える 2

3

ご覧のとおり、auto_encodeが正しく設定されていません。

これを試して、それがあなたが探しているものであるかどうかを確認してください。

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;
}

お役に立てれば

于 2012-04-30T14:00:00.560 に答える
1

これを行う方法はたくさんあります。

protected $this->auto_encode = false;

コントローラのそのプロパティは、割り当てられたすべての値のエンコードを停止します。

それ以外の場合は、これを使用します。

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

これにより、特定の値のエンコードが停止します。

于 2012-06-11T15:21:19.503 に答える