控制器:
class Welcome extends CI_Controller {
public function __construct()
{
parent::__construct();
if(!is_logged_in()){
redirect('admin');
}
}
public function index()
{
$this->load->view('templates\sub_header');
$this->load->view('welcome_message');
$this->load->view('templates\footer');
}
}
当被调用的控制器应该只按顺序加载三个视图。相反,我不断收到错误"无法加载请求的文件:templates \ sub_header.php"。
需要注意的重要一点是,此代码在localhost上工作得很好,但在godaddy子域上给出了问题。
我在配置文件中定义了一个基本网址,似乎运行正常。
另一方面,另一个控制器在任何地方工作都很好:
public function index()
{
if( is_logged_in() )
{
redirect('welcome');
}
$this->form_validation->set_error_delimiters('<div class="text-danger">', '</div>');
$this->form_validation->set_rules('username', 'UserName', 'required');
$this->form_validation->set_rules('password', 'Password', 'required|min_length[4]');
$this->load->view('templates/header');
if($this->form_validation->run() == FALSE)
{
$this->load->view('auth/login_view');
}
else
{
// Check the entered value against db
$this->load->model('auth/admin_model');
$result = $this
->admin_model
->verify_user($this->input->post('username'),$this->input->post('password'));
if($result != false)
{
$username = $this->input->post('username');
$status = $result->status;
if($status == 1)
{
$user_roles = $this->admin_model->get_user_access_roles($result->id);
$this->session->set_userdata('username', $username);
$this->session->set_userdata('user-management',$user_roles->user_management);
$this->session->set_userdata('client-information',$user_roles->client_information);
$this->session->set_userdata('master-metadata',$user_roles->master_metadata);
$this->session->set_userdata('reports',$user_roles->reports);
redirect('welcome');
}
else
{
$data['error_message'] = "Account is disabled. Get in touch with system administrator !";
$this->load->view('auth/login_view',$data);
}
}
else
{
$data['error_message'] = "Invalid UserName or Password. Try Again !";
$this->load->view('auth/login_view',$data);
}
}
$this->load->view('templates/footer');
}
视图在管理员控制器中完美加载,但在管理员重定向到欢迎控制器后登录后,视图停止加载。控制器之间的唯一区别是在Admin控制器中我正在调用header而在welcome中我正在调用sub_header但是这两个文件都存在于views文件夹中。
答案 0 :(得分:0)
将\
更改为此/
public function index()
{
$this->load->view('templates/sub_header'); # Changed
$this->load->view('welcome_message');
$this->load->view('templates/footer'); # Changed
}
和 确保文件存在