简体   繁体   English

树枝{{base_url}}在codeigniter中不起作用

[英]twig {{ base_url }} not working in codeigniter

I'm using codeigniter 2x and I integrate twig properly. 我正在使用Codeigniter 2x,并且正确集成了树枝。 I create a simple web site and test it. 我创建一个简单的网站并对其进行测试。 my problem is when I call a page through a function my images are not loading properly.please help me. 我的问题是,当我通过函数调用页面时,我的图像无法正确加载。请帮助我。

this is my controller 这是我的控制器

function search_keyword()
{
    $keyword    =   $this->input->post('keyword');
    $data['result']    =   $this->mymodel->search($keyword);
    /*print_r($data);*/
    $this->twig->display('home.html',$data);
    //$this->load->view('content_view.html',$data);
}

this is my view 这是我的看法

<div class="container">
<div class="col-sm-12 col-md-12">
    <img src="{{ base_url }}images/footer.png" alt="Image" style="width: 100%;" />
</div>

I found error the controller 我发现控制器错误

$data['result'] = $this->mymodel->search($keyword); 
$this->twig->display('home.html',$data);

should change to this 应该改变为此

$this->data['result'] = $this->mymodel->search($keyword);
$this->twig->display('home.html', $this->data);

Put this additional variable into your controller: 将此附加变量放入控制器中:

$data['base_url'] = base_url("/");

Send all the data into Twig for rendering: 将所有数据发送到Twig中进行渲染:

$this->twig->display('home.html',$data);

Use {{ base_url }} in your home.html twig template - to get your base_url. 在您的home.html树枝模板中使用{{ base_url }} -获取您的base_url。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM