English 中文(简体)
识别——隐秘控制器
原标题:CodeIgniter - hidden controller

I m building a CMS based on CodeIgniter. It stores "views" and its data in a database and gathers the proper one when needed. As you might have guessed - I can t generate a physical controller and matching view for each pages.

我现以数字表示,routes将非常精干,因为我更愿意不使用在《欧洲刑法》中可见的管制器。 解释不严:I m 寻求一种办法,将所有实际存在的控制人员撤回到习惯上的要求——没有出现在URL.。 当然,这名控制员将处理404名控制员。

Bad: .com/handler/actual-view/> 良好:<条码>(......com/actual-view/)(无实际概览控制器,或相反所示)

I ve 增添了404_override 路标:handler/。 现在,我只想找到一种办法,以找到所要求的观点(即:.com/actual-view)。 实际情况是我所期望的。

I ve tried

$route[ 404_override/(:any) ] =  handler/$1 ;

同样,这将完全消除404岁以上人口。

最佳回答

我的解决办法是,在《国际不动产业法典》承认一个非常繁琐的论坛和圣克韦罗斯热爱的会员的一些指导下,把所有404个错误传给我的海关控制员,我在那里确保它拥有真正的404个(无人看管)。 在控制器的晚些时候,我从我的数据库“URI”中收集了我所需要的其余信息:

//Route
$route[ 404_override ] =  start/handler ;

//Controller
function handler($path = false) {

   //Gather the URI from the URL-helper
   $uri_string = uri_string();

   //Ensure we only get the desired view and not its arguments
   if(stripos($uri_string, "/") !== false) {
      //Split and gather the first piece
      $pieces = explode("/", $uri_string);
      $desired_view = $pieces[0];
   } else {
      $desired_view = $uri_string;
   }

   //Check if there s any view under this alias
   if($this->site->is_custom_view($desired_view)) {

      //There is: ensure that the view has something to show
      if(!$this->site->view_has_data($desired_view)) {
         //No data to show, throw an error message
         show_custom_error( no_view_data );
      } else {
         //Found the views data: show it
      }

   } else {
      //No view to show, lets go with 404
      show_custom_404();
   }
}
问题回答

最好有rel=“nofollow”_exring the base Liner or Chief.

通过这样做,你允许你的申请具有灵活性,并且仍然符合 CI的工作方式。

您需要界定您路线上的所有有效路线。 php config file, 然后在最后一行,

$routes["(:any)"] = "specific controller path";

如果我举一个例子:

$route[ u/(:any)/account ] = "user_profile/account/$1";
$route[ u/(:any)/settings ] = "user_profile/settings/$1";
$route[ u/(:any)/messages ] = "user_profile/messages/$1";
$route[ u/(:any) ] = "user_profile/index/$1";

正如这里所看到的那样,在头三只罐头赶上电灯后,我把所有电灯转至用户简介。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签