【发布时间】:2017-10-27 16:50:12
【问题描述】:
好的,所以我使用位于我的视图文件夹中的 index.php 作为我的主视图。我在其中加载了所有其他视图(正如您从下面的代码中看到的那样)。
现在,当我创建一个类似 about/(:any) 的路由时,它不会加载我的任何 CSS 或类似的......
路线
$route['about'] = 'about'; // works fine
$route['about/(:any)'] = 'about/get_specific_about/$1'; //problematic one
现在这是我的 index.php
<!DOCTYPE HTML>
<html>
<head>
<link rel="stylesheet" type="text/css" href="public/css/partials/header.css" />
<link rel="stylesheet" type="text/css" href="public/css/partials/footer.css" />
<link rel="stylesheet" type="text/css" href="public/css/<?php echo $meta['css']; ?>.css" />
</head>
<body>
<?php $this->load->view("partials/header"); ?>
<?php $this->load->view($meta['page']); ?>
<?php $this->load->view("partials/footer"); ?>
</body>
</html>
现在每当我使用带有 (:any) 的路由时,代码都会加载视图,但它无法找到例如 footer.css 或 header.css .. 如果我使用例如 ../public/css /header.css 然后它会...
关于控制器的代码
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class About extends CI_Controller {
private $data = [
'meta' => [
'page' => "pages/about",
'css' => "about",
'description' => "test"
],
];
public function index()
{
$this->load->helper('html');
$this->load->view('index', $this->data);
}
public function get_specific_about($user) {
$tmp_data = [];
$tmp_data['meta']['css'] = "profiles/".$user;
$tmp_data['meta']['page'] = "profiles/".$user;
$tmp_data['meta']['description'] = "test";
$tmp_data['meta']['extended'] = true;
$this->load->view('index', $tmp_data);
}
}
【问题讨论】:
-
我认为问题不在于路线;这是您使用资产的相对路径。尝试通过在它们前面加上
$this->config->site_url()将资产路径锚定到根目录
标签: php codeigniter