Welcome Guest, Not a member yet? Register   Sign In
URGENT!!! HELP ME!!!
#1

[eluser]Lima[/eluser]
I must using CI with config like this :

Code:
$config['enable_query_strings'] = TRUE;
$config['controller_trigger']     = 'c';
$config['function_trigger']     = 'm';

Some client hit my url like this
http://ipserver:8080/index.php?name=some...omeaddress

It should be http://ipserver:8080/index.php?c=search&...omeaddress

How do I automatically set URL with c=search parameter.

.htaccess file or config/route.php

Is there somebody can help me?
#2

[eluser]pistolPete[/eluser]
I don't use query strings, but can't you just set a default controller?
Code:
$route['default_controller'] = 'search';
#3

[eluser]Lima[/eluser]
Thanks pistolPete but it does work, it show Page Not Found

other solution please?
#4

[eluser]pistolPete[/eluser]
Put this on the top of your index.php:
Code:
<?php
if(!isset($_GET['c'])
{
   $_GET['c'] = 'search';
}
(...)
#5

[eluser]xwero[/eluser]
The problem is that there is no routing for query_strings build in CI. In the router there is this
Code:
// Are query strings enabled in the config file?
        // If so, we're done since segment based URIs are not used with query strings.
        if ($this->config->item('enable_query_strings') === TRUE AND isset($_GET[$this->config->item('controller_trigger')]))
        {
            $this->set_class(trim($this->uri->_filter_uri($_GET[$this->config->item('controller_trigger')])));

            if (isset($_GET[$this->config->item('function_trigger')]))
            {
                $this->set_method(trim($this->uri->_filter_uri($_GET[$this->config->item('function_trigger')])));
            }

            return;
        }
So in the default controller, default method you need to do the routing. For example
Code:
function index()
    {
        if( ! isset($_GET[config_item('controller_trigger')]) && in_array(array('name','address'),array_keys($_GET)))
        {
            header('Location: '.$this->config->site_url().'?c=search&'.$_SERVER['QUERY_STRING']);
            exit;
        }
#6

[eluser]Lima[/eluser]
Thanks for all

I think I must modify library/Router.php for general case like this :
Code:
function _set_routing()
    {
        // Load the routes.php file.
        @include(APPPATH.'config/routes'.EXT);
        $this->routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route;
        unset($route);

        // Set the default controller so we can display it in the event
        // the URI doesn't correlated to a valid controller.
        $this->default_controller = ( ! isset($this->routes['default_controller']) OR $this->routes['default_controller'] == '') ? FALSE : strtolower($this->routes['default_controller']);    
        
        // Are query strings enabled in the config file?
        // If so, we're done since segment based URIs are not used with query strings.
    if ($this->config->item('enable_query_strings') === TRUE)
    // AND isset($_GET[$this->config->item('controller_trigger')]))
    {
            $this->set_class(trim($this->uri->_filter_uri(isset($_GET[$this->config->item('controller_trigger')]) ? $_GET[$this->config->item('controller_trigger')] : $this->default_controller)));

            if (isset($_GET[$this->config->item('function_trigger')]))
            {
                $this->set_method(trim($this->uri->_filter_uri($_GET[$this->config->item('function_trigger')])));
            }
            
            return;
        }
        
        // Fetch the complete URI string
        $this->uri->_fetch_uri_string();
    
.
.
.

Is there anything wrong with my modification, it just my opinion, hope it will implement for next version.
#7

[eluser]xwero[/eluser]
[quote author="pistolPete" date="1235672589"]Put this on the top of your index.php:
Code:
<?php
if(!isset($_GET['c'])
{
   $_GET['c'] = 'search';
}
(...)
[/quote]
Using the index.php file as a router could turn out very ugly. if you want to do it at least use a separate file and include it.My solution loads a file that doesn't need to be loaded so that is not the best way either.

The best way would be to alter the router to load a get routes file like its done for the segment based routes.
#8

[eluser]xwero[/eluser]
Lima i think it's best not to mix query string and segment routes because they are not interchangeable.

This would be the route for what you want to achieve:
Code:
$routes['([name|address])(.+)'] = 'c=search&$1$2';
But if you have a rerouted querystring the url needs to be reloaded otherwise the right class and method will not be recognized. Or you need to change the way the class and method are fetched too.
So your change is too little to have effect.




Theme © iAndrew 2016 - Forum software by © MyBB