There should be many projects in this case, through the http://pc.local can be accessed, if through the http://localhost/pc/public will appear some pictures, style display, hyperlink error situation, the project is not very good transplant, The main reason is that the URL created is not flexible enough to see how the CI is handled.
The configuration file has several configurations about URLs that affect routing, parameter fetching, and URL creation, which are:
1234567891011121314151617 |
$config
[
‘base_url‘
] =
‘‘
;
$config
[
‘index_page‘
] =
‘index.php‘
; $config
[
‘uri_protocol‘
] =
‘AUTO‘
;
$config
[
‘url_suffix‘
] =
‘‘
;
$config
[
‘allow_get_array‘
] = TRUE;
$config
[
‘enable_query_strings‘
] = FALSE;
$config
[
‘controller_trigger‘
] =
‘c‘
;
$config
[
‘function_trigger‘
] =
‘m‘
;
$config
[
‘directory_trigger‘
] =
‘d‘
;
|
$config [' Uri_protocol ']
Uri_protocol options available are auto, Path_info, query_string, Request_uri, Orig_path_info
The meanings were as follows:
query_string: query string;
path_info: The path information provided by the client, which is what is trailing after the actual execution of the script, removes the query String;
Request_uri: contains the URI content defined in the HTTP protocol.
Visit: Http://pc.local/index.php/product/pc/summary?a=1
Path_info for/product/pc/summary;request_uri to/index.php/product/pc/summary?a=1;query_string for a=1
The actual configuration is also somewhat related to the server configuration, and some servers are configured with Orig_path_info, most of them are not.
The value of Uri_protocol determines the way in which CI routes and parameters are obtained, and CI uses these values to determine which controller to resolve, so it is necessary to ensure that the server is configured with the correct values. In most cases, auto is set, and auto detects the value of Request_uri Path_info query_string $_get in turn until the content is read.
There are enable_query_strings parameters that affect route resolution, and when this parameter is true, and the Controller_trigger parameter is passed in, the arguments are obtained in the form of a query string, such as Index.php?c=products The &m=view&id=345 resolves to the view method in the product controller.
$config [' Allow_get_array ']
The $this->input->get () method is encapsulated in CI to get the Get parameter, which is set to true to indicate that the parameter is also allowed in $_get way, otherwise the value in $_get is emptied.
$config [' Base_url ']
The setting of this parameter affects the URL created by the Base_url () Site_url () function, which automatically gets the current address when empty, otherwise the URL is created based on the address set.
$config [' index_page '] default home page, using Site_url () is created with this parameter, if you need to remove the index.php set to empty.
$config the [' url_suffix '] suffix, which is also taken when created with Site_url ().
The settings of the above two parameters are not valid for Base_url (), that is, the values of Index_page and Url_suffix are not appended.
12345 |
//pc.local/bootstrap/js/bootstrap.min.js echo base_url( ‘bootstrap/js/bootstrap.min.js‘ ); //pc.local/login.htm(设置了index_page=‘‘ url_suffix=‘.htm‘) echo site_url( ‘login‘ ); |
So it can be found that base_url () is used to create the address of static resources, such as JS, CSS and other addresses need to use this function to generate. Site_url () is used to create a URL associated with the controller address.
URL addresses created using the Base_url () and Site_url () functions have better portability, and it is recommended that the system URL-related addresses be created uniformly using this function.
The site_url provided by CI is not flexible enough to handle parameters, so you can extend a Create_url function to create the address associated with the controller. The following is a way to implement.
Expand Url_helper, create my_url_helper.php in helpers, with the following content:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
function create_url(
$route = NULL,
$params =
array
(),
$ampersand =
‘&‘
)
{
$route = site_url(
$route
);
if
(!
empty
(
$params
)) {
return $route
.
‘?‘
.http_build_str(
$params
, NULL,
$ampersand
);
}
return $route
;
}
if
(! function_exists(
‘http_build_str‘
))
{
function http_build_str(
$query
,
$prefix
=
‘‘
,
$arg_separator
=
‘‘
)
{
if (!
is_array
(
$query
)) {
return null;
}
if (
$arg_separator ==
‘‘
) {
$arg_separator =
ini_get
(
‘arg_separator.output‘
);
}
$args =
array
();
foreach (
$query as $key =>
$val
) {
$name =
$prefix
.
$key
;
if (!
is_numeric
(
$name
)) {
if
(
is_array
(
$val
)){
http_build_str_inner(
$val
,
$name
,
$arg_separator
,
$args
);
}
else
{
$args
[] = rawurlencode(
$name
).
‘=‘
.urlencode(
$val
);
}
}
}
return implode(
$arg_separator
,
$args
);
}
}
if
(! function_exists(
‘http_build_str_inner‘
))
{
function http_build_str_inner(
$query
,
$prefix
,
$arg_separator
, &
$args
)
{
if (!
is_array
(
$query
)) {
return null;
}
foreach (
$query as $key =>
$val
) {
$name =
$prefix
.
"["
.
$key
.
"]"
;
if (!
is_numeric
(
$name
)) {
if
(
is_array
(
$val
)){
http_build_str_inner(
$val
,
$name
,
$arg_separator
,
$args
);
}
else
{
$args
[] = rawurlencode(
$name
).
‘=‘
.urlencode(
$val
);
}
}
}
}
}
|
--eof--
Transfer from http://itopic.org/codeigniter-config-url.html
Reproduced URL of codeigniter configuration