我最近更新了我的网站,但我在数据库中有很多旧数据要在存档中显示。我不是Codeigniter的专家。如果可能的话,请尽可能详细解释我的细节。我目前的网站是使用Codeigniter构建的。
我的数据库表
我想显示此结构化网址的数据。
www.example.com/(如果cat_one不为空 - > gt; category_name)/(如果cat_two 不是空的 - > category_name)/id-slug.html
答案 0 :(得分:0)
在您的控制器中执行此操作
public function Get_allcat(){
$this->load->model('model-name');
$cat_one = $this->model-name->Get_CatOne(); //it will give an array in return. if you want to handle one by one then use foreach loop as well
$cat_two = $this->model-name->Get_CatTwo(); //if you want to get specific category_name in return then pass some parameter to model function for where condition in database
$old_archive = $this->model-name->Get_Old_Archive();
if(!empty($cat_one))
{
if(!empty($cat_two))
{
if(!empty($old_archive))
{
redirect('www.example.com/'.$cat_one.'/'.$cat_two.'/'.$old_archive['id'].'/'.$old_archive['slug'].'.html');
}
}
}
在你的模特中
public function Get_CatOne(){
$this->db->select("category_name");
$this->db->from("cat_one");
$query = $this->db->get();
return $query->row();
}
public function Get_CatTwo(){
$this->db->select("category_name");
$this->db->from("cat_two");
$query = $this->db->get();
return $query->row();
}
public function Get_Old_Archive(){
$this->db->select("id, slug");
$this->db->from("old_archive");
$query = $this->db->get();
return $query->row();