我在routes.php文件的解决方案:
$route['news'] = 'news_controller';
$route['gallery'] = 'gallery_controller';
$route['(:any)'] = 'sites/$1';
,并在我的网站电脑板:
function index($site_id = '') {
//sanitize $site_id.
$this->site = $this->sites_model->get_site($site_id);
//etc.
}
THX严
问题:
所以我用CodeIgniter写了一个小CMS。管理员可以创建网站。当网段的段与DB中的网段相似时,网站会自动打开。例如mysite.com/sites/about会打电话给“关于”网站。这工作正常。
现在我的网址出现了问题。我希望这个网址
http://www.mysite.com/sites/about
变成这样:
的问题是,我无法使用routes.php文件,并为每个站点设置通配符。 (因为它们是动态的,我不知道该网站的客户将创建 - 我不想编辑他将创建的每个网站routes.php文件 - 这应该自动完成)
问题是我得到了其他修复控制器太像新闻,图库,或联系: mysite.com/news,mysite.com/gallery,......他们做工精细
所以这里是我的地盘控制器:
class Sites extends Public_Controller {
public $site;
public $url_segment;
public function _remap($method)
{
$this->url_segment = $this->uri->segment(2);
$this->load->model('sites_model');
$this->site = $this->sites_model->get_site($this->url_segment);
if($this->site !== FALSE)
{
$this->show_site($this->site);
}
else
{
show_404($this->url_segment);
}
}
public function show_site($data)
{
$this->template->set('site', FALSE);
$this->template->set('site_title', $data['name']);
$this->template->set('content',$data['content']);
$this->template->load('public/template','sites/sites_view', $data);
}}
这是检查数据库的Site_model ...如果url_segment符合DB中的标题:
class Sites_model extends CI_Model {
public function get_site($site_url)
{
if($site_url != ""){
$this->db->where('name', $site_url);
$query = $this->db->get('sites', 1);
if($query->num_rows() > 0){
return $query->row_array();
}
else
{
return FALSE;
}
}else{
return FALSE;
}
} }
我想我需要的东西,谁检查,如果存在控制器(URL的第一部分)时,不叫站点控制器,并检查该网站是在数据库中,当这是假的,然后拨打404
有什么建议如何解决这个问题?
BTW:SRY,我的英语
问候GN
SRY我的英语(奥地利) 耶这就是真的,那么他会叫其他的控制器坏了。但最后我不想要段“网站”。从mysite.com/sites/about到mysite /约 我喜欢隐藏段“网站” – gn90at