Codeigniter - configure enable_query_strings and form_open

I want users to be able to query strings this way. Domain.com/controller/function?param=5&otherparam=10

In my configuration file I have

$config['base_url'] = 'http://localhost:8888/test-sites/domain.com/public_html';
$config['index_page'] = '';
$config['uri_protocol'] = 'PATH_INFO';
$config['enable_query_strings'] = TRUE;

The problem I'm getting is that it form_openautomatically adds a question mark (?) To my url.

So, if I say:

echo form_open('account/login');

he spits out: http://localhost:8888/test-sites/domain.com/public_html/?account/login

Pay attention to the question mark added immediately before the "account".

How can i fix this?

Any help would be greatly appreciated!

+3
source share
3 answers

Core Config.php, CI_Config. site_url() , form_open. . CI < 2.0 /library/MY _Config.php, CI >= 2.0, application/core/MY_Config.php. site_url().

class MY_Config extends CI_Config
{
   function __construct()
   {
      parent::CI_Config();
   }

   public function site_url($uri='')
   {
      //Copy the method from the parent class here:
      if ($uri == '')
      {
         if ($this->item('base_url') == '')
     {
        return $this->item('index_page');
     }
     else
     {
        return $this->slash_item('base_url').$this->item('index_page');
     }
      }

      if ($this->item('enable_query_strings') == FALSE)
      {
         //This is when query strings are disabled
      }
      else
      {
         if (is_array($uri))
     {
        $i = 0;
        $str = '';
        foreach ($uri as $key => $val)
        {
           $prefix = ($i == 0) ? '' : '&';
           $str .= $prefix.$key.'='.$val;
           $i++;
        }
            $uri = $str;
         }
         if ($this->item('base_url') == '')
     {
            //You need to remove the "?" from here if your $config['base_url']==''
        //return $this->item('index_page').'?'.$uri;
            return $this->item('index_page').$uri;
     }
     else
     {
            //Or remove it here if your $config['base_url'] != ''
        //return $this->slash_item('base_url').$this->item('index_page').'?'.$uri;
            return $this->slash_item('base_url').$this->item('index_page).$uri;
     }
      }
   }
}

, , , CI 2.0, , CI 2.0

+2

, follwing config.php

$config['enable_query_strings'] = FALSE;

.

+2

url, URL- :

<domain.com>?c={controller}&m={function}&param1={val}&param2={val}

$_GET['param1']

:

form_open(c=account&m=login&param1=val)

, , .

+1
source

All Articles