[英]How to create custom 404page
I want to create custom 404 page for my site.I mean when i type url as 我想为我的网站创建自定义404页面。
http://example.com/anydummytext
need to redirect to custom 404page 需要重定向到自定义404页面
How to create custom page for this 如何为此创建自定义页面
The simple way is create a controller you can name the error controller to any what you want. 简单的方法是创建一个控制器,您可以将错误控制器命名为所需的任何名称。
Example 例
<?php
class Not_found extends CI_Controller {
public function index() {
// some content
$this->load->view('not_found');
}
}
Then on another controller you can redirect it 然后在另一个控制器上,您可以将其重定向
redirect('not_found');
<?php
class Home extends CI_Controller {
public function index() {
$result = $this->some_model->get();
if ($result) {
// content
$this->load->view('home');
} else {
redirect('not_found');
}
}
}
The other option is in config/routes.php you can use codeigniter 另一个选项在config / routes.php中,您可以使用codeigniter
$route['404_override'] = 'not_found'; // Note will not work in a subfolder
You can create a new controller or use existing controller to write down a function for loading the VIEW for 404 . 您可以创建一个新的控制器,也可以使用现有的控制器写下用于加载404的VIEW的函数。
class Nopage extends CI_Controller
{
/* Index function
*
* return void
*/
public function index()
{
$this->load->view('nopage_404');
}
}
}
Call the controller function in config->routes as below. 如下所示在config-> routes中调用控制器功能。
$route['404_override'] = 'nopage';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.