I have a problem with CodeIgniter showing images in the function detail
. In the function index
, they are shown. Can someone show me where the problem is?
class Reference extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('reference_model');
}
public function index()
{
$data['work'] = $this->reference_model->getList();
$menu['page'] = "Reference";
$menu['pages'] = $this->pages->getPages();
$this->basic_template->set('title','Reference | DSVision');
$this->basic_template->menu('menu_view',$menu);
$this->basic_template->script('reference_script_view');
$this->basic_template->view('basic_script', 'reference_view',$data);
}
public function detail($number)
{
if($this->reference_model->exist($number) == 0)
redirect('reference');
$data['id'] = $number;
$data['work'] = $this->reference_model->getWork($number);
$menu['page'] = "Reference";
$menu['pages'] = $this->pages->getPages();
$this->basic_template->set('title','Reference | DSVision');
$this->basic_template->menu('menu_view',$menu);
$this->basic_template->view('basic', 'detail_view',$data);
}
}
This problem occurs when you give the image src as src="/images/logo.png"
.
When giving a path, do it like this:
src="<?php echo $this->config->item('base_url'); ?>/image/logo.png"
Take note that you must set the in inside the folder.文件夹内的设置 。
This problem occured because the browser is trying to find the image directory inside your controller directory as if you are loading a function!
u have to put every images, js etc. in your root-dir of CI. Example:
/yourapp/css/style.css
In your view you write eg the following:
<link type="text/javascript" src="<? echo base_url() ?>css/style.css" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.