2017-04-18 36 views
0

尝试将网页路由为website.com/'schoolname'。如果有一个名字相同的控制器,它会通过它..否则它会检查数据库中是否有这样的学校名称,如果有一个它将会进入它的档案页面。如果没有档案,它将返回一个404页。如何在codeigniter w/0 db中执行动态路由db

代码

路线

$wind =  array("app.php","assignment.php","backup.php","book.php","bulkimport.php","category.php","classes.php","conversation.php","dashboard.php","eattendance.php","event.php","exam.php","examschedule.php","exceptionpage.php","expense.php","feetypes.php","grade.php","hmember.php","holiday.php", "hostel.php","index.html" , "install.php","invoice.php" , "issue.php" ,"language.php", "lmember.php" , "mailandsms.php" ,"mailandsmstemplate.php", "mark.php" , "markpercentage.php", "media.php", "menu.php", "migration.php" ,"notice.php" , "parents.php", "paymenthistory.php" , "paymentsettings.php" , "permission.php", "profile.php", "promotion.php" , "report.php" , "reset.php", "resetpassword.php" , "routine.php" , "sattendance.php", "school.php" ,"schoolyear.php" ,"section.php", "setting.php" , "signin.php" , "signup.php" , "smssettings.php" ,"student.php" , "subject.php" , "syllabus.php" , "systemadmin.php", "tattendance.php", "teacher.php" ,"tmember.php" ,"transport.php" , "update.php" , "user.php" , "usertype.php" , "visitorinfo.php"); 



foreach ($wind as $win) 
{ 
$controllers[] = $win; 
    } 

    $id = $this->uri->segment(1); 


    if (in_array($id.'.php', $controllers)){ 


    $route[$id] = $id; 


    }else{ 

$route[$id] = 'school/index/'.$id; 

} 

控制器

public function index($id = null) 
{ 

    $a = $this->systemadmin_m->get_fnall($id); 




    if($a != null){ 

    $this->load->view('front/header'); 
    $this->load->view('front/includes'); 
    $this->load->view('front/sindex'); 
    $this->load->view('front/footer'); 

}else{ 


     $this->load->view('errors/notfound'); 
} 


} 
+0

对不起,这是在foreach我从某处复制该部分的错误。它完美的作品.. –

回答

0

使用一个真正的路由组件!尝试使用symfony或zend框架路由器,可以使用作曲家安装!

+0

修复它现在..将尝试那些 –