我使用密码调子。
我想做的是,
如果访问网页不存在
例如:com/idontexist
然后,我想首先核对一个数据库,看idontexist
是否在数据库中。
如果是这样,我就想把用户带往用户。
例如:com/action/idontexist。
我如何能够这样做?
我使用密码调子。
我想做的是,
如果访问网页不存在
例如:com/idontexist
然后,我想首先核对一个数据库,看idontexist
是否在数据库中。
如果是这样,我就想把用户带往用户。
例如:com/action/idontexist。
我如何能够这样做?
One solution would be to extend the CI_Router class with your own in application/core/MY_Router.php and just copy the method _set_routing() in your class. Your changes would go somewhere after routes.php file is included and set to $this->routes property, you can add your custom routes.
include(APPPATH. config/routes .EXT); ... $this->routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route; unset($route); //Get your custom routes: $your_routes = $this->_get_custom_routes(); foreach($your_routes as $custom_route) { $this->routes[$custom_route[ your_regex_match ]] = $custom_route[ controller ]. / .$custom_route[ action ]; }
Of course you might not need this, but I hope it gives you some idea. This way you can add custom routes and since you will have to fetch them from database, consider caching them for better speed.
我感到,每星期都会问这个问题。
Open up your application/config/routes.php
, then add something like this:
$route[ ^(:any) ] = "my_controller/get_article/$1";
Please note that it will route everything to a controller called action
. If you have other controllers then you should add a route for them too (preferably placed before this one).
// EDIT: Using this you can goto http://your-site.com/secrets-of-internet-marketing
and it will call the get_article
function in the my_controller
controller, and pass "secrets-of-internet-marketing"
as the first argument. Which can then process with something like this:
public function get_article($article_name) {
// something like this:
$article = $this->article_model->get_model_by_name($article_name);
$this->load->view( article , $article);
}
I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...
<?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 = ...
我把我的用心从使用QQL转向MySQL。 它与凯科特合作,现在不工作,因为我已经改变,使用MySQL。 这里的错误信息是:
We have a restaurant table that has lat-long data for each row. We need to write a query that performs a search to find all restaurants within the provided radius e.g. 1 mile, 5 miles etc. We have ...
Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...
Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...
What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...
My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...