我在MYSQL中创建一个表。我将一些数据插入表中。
我的问题是关于ID为NULL时的错误。
当URL为“ .com / blog / post / 1”时,内容具有完美可见的ID 1和其他ID的内容。但是问题是当URL为“ .com / blog / post”时,我无法解决(因为我是Codeigniter的新手)。
我认为问题“ post /”本身需要ID号,但是如何通过如下所示的页面更改错误
禁止的
您无权访问此服务器上的/ post /。
在您的blog
控制器中,当有人要求a时,post
您可以检查是否id
存在,如果不存在,则可以将其重定向到博客索引。
该blog
控制器将这个样子。
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Blog extends CI_Controller {
function __construct()
{
parent::__construct();
}
function index()
{
//List posts with title and excerpts and a read more link
}
function post($id=NULL)
{
if($id)
{
//Show detailed post
}
else
{
redirect('blog');
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句