简体   繁体   English

base_url在codeigniter的php标签内未显示所需结果

[英]base_url not showing desired result inside php tag in codeigniter

i am trying to output the image inside php tag through base_url function. 我正在尝试通过base_url函数在php标签内输出图像。 it tried using different combination of quotes but nothing seems to be working here. 它尝试使用不同的引号组合,但在这里似乎没有任何作用。 can any point out exactly where i am doing wrong? 能指出我做错了什么吗?

$image_url =$this->input->get("image",true);
echo "<img src='base_url('uploads/add_pic/')'.$image_url /> "."<br>";

while in output i am getting

localhost/myproject/online_marketplace_controller/base_url(

kindly help me in this regard 请在这方面帮助我

used this type 使用这种类型

<img src="<?php echo base_url('uploads/add_pic/'.$image_url);?>">

OR 要么

echo "<img src='".base_url()."uploads/add_pic/".$image_url."'><br>  ";

Make sure you set your base url like 确保您将基本网址设置为

$config['base_url'] = 'http://localhost/myproject/';

Then on your view 然后在您看来

<img src="<?php echo base_url('uploads/add_pic/' . $this->input->get("image"));?>">

Also you can use the html helper https://www.codeigniter.com/user_guide/helpers/html_helper.html 您也可以使用html帮助器https://www.codeigniter.com/user_guide/helpers/html_helper.html

Make sure you load the helper in the controller or autoload it. 确保将帮助程序加载到控制器中或自动加载。

<?php

$image_properties = array(
   'src'   => 'uploads/add_pic/' . $this->input->get("image"), 
);

echo img($image_properties);

?>

你可以这样使用

<img src="<?php echo base_url();?>uploads/add_pic/<?php echo $image_url; ?>">

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

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