CodeIgniter 方法无法正确获取文件路径
CodeIgniter method Cannot get File Path Correctly
我将 html 解析为页眉、侧边栏、内容、页脚等。和主视图放在一起。当我从 mycontroller/index 调用视图时它工作正常,但当我调用视图时它不工作从 mycontroller/method.. 调用视图下面的伪代码;
控制器;
class welcome extends CI_Controller{
public function index(){
$data['content'] = "**main**_page";
$this->load->view('welcome_message',$data);
}
public function deneme(){
$data['content'] = "**another**_page";
$this->load->view('welcome_message',$data);
}
}
查看;
<html>
<head>
<?php $this -> load -> view("includes/head_view");?>
</head>
<body>
<?php $this -> load -> view("includes/navbar_view");?>
<?php $this -> load -> view($content);?>
<?php $this -> load -> view("includes/footer_view"); ?>
</body>
</html>
示例子视图
<img src="<?php base_url(); ?>assets/img/image1.jpg">
当我打开以下地址时,一切正常,图片正在加载
但是在下面打开时,图片没有加载
http://localhost/myproject/welcome/deneme
我检查了来自 Google Chrome> 页面源代码的图像 url..
link 这样写;
localhost/myproject/welcome/assets/img/image1.jpg
而不是
localhost/myproject/assets/img/image1.jpg
它正在向所有 link 添加控制器名称如何解决它
谢谢
在你定义 base_url
的地方它说 "URL to your CodeIgniter root. Typically this will be your base URL, WITH a trailing slash":
$config['base_url'] = 'http://localhost/myproject/';
我将 html 解析为页眉、侧边栏、内容、页脚等。和主视图放在一起。当我从 mycontroller/index 调用视图时它工作正常,但当我调用视图时它不工作从 mycontroller/method.. 调用视图下面的伪代码;
控制器;
class welcome extends CI_Controller{
public function index(){
$data['content'] = "**main**_page";
$this->load->view('welcome_message',$data);
}
public function deneme(){
$data['content'] = "**another**_page";
$this->load->view('welcome_message',$data);
}
}
查看;
<html>
<head>
<?php $this -> load -> view("includes/head_view");?>
</head>
<body>
<?php $this -> load -> view("includes/navbar_view");?>
<?php $this -> load -> view($content);?>
<?php $this -> load -> view("includes/footer_view"); ?>
</body>
</html>
示例子视图
<img src="<?php base_url(); ?>assets/img/image1.jpg">
当我打开以下地址时,一切正常,图片正在加载
但是在下面打开时,图片没有加载
http://localhost/myproject/welcome/deneme
我检查了来自 Google Chrome> 页面源代码的图像 url.. link 这样写; localhost/myproject/welcome/assets/img/image1.jpg
而不是
localhost/myproject/assets/img/image1.jpg
它正在向所有 link 添加控制器名称如何解决它 谢谢
在你定义 base_url
的地方它说 "URL to your CodeIgniter root. Typically this will be your base URL, WITH a trailing slash":
$config['base_url'] = 'http://localhost/myproject/';