1

I can not find a solution to my problem, if my question is a duplicate, please provide a reference link. so I need your help. Here's for example:

localhost/ci/index.php/search/?song=sheila+on+7

to be

localhost/ci/index.php/search/sheila_on_7

or

localhost/ci/index.php/search/song/sheila_on_7

Thanks.

Hendrik Eka
  • 145
  • 3
  • 14

2 Answers2

1

CodeIgniter optionally supports this capability, which can be enabled in your application/config.php file. If you open your config file you'll see these items:

$config['enable_query_strings'] = FALSE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';

If you change "enable_query_strings" to TRUE this feature will become active. Your controllers and functions will then be accessible using the "trigger" words you've set to invoke your controllers and methods:

index.php?c=controller&m=method

More Information can be found in the CodeIgniter URLs users guide

Ilanus
  • 6,690
  • 5
  • 13
  • 37
0

You have to change form method from GET to POST. Inflector helper has function you can use, or you can use str_replace() PHP function too. Than something like this:

<?php defined('BASEPATH') OR exit('Not your cup of tea');

class Search extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->helper('inflector');
    }

    public function song($song)
    {
        $song = underscore($this->input->post('song'));//name of field in view which becomes sheila_on_7

        //use variable for DB search or what ever you need

        //$data['song'] = $this->Song_m->get('title', $this->input->post('song'));

        //$this->load->view('search', $data);

    }
}
Tpojka
  • 6,996
  • 2
  • 29
  • 39
  • I need to use the get method on my website, because I want to display it on the search engines, something like (http:**mysite.com/search/what_do_you_mean). But now I have found another way, I still use (http:**mysite.com/search/?query=keyword), because before I get 404 when I used '?query=keyword', and after replacing uri_protocol with auto everything goes well. thanks by the way – Hendrik Eka Jan 09 '16 at 17:28
  • Np. Happy coding. ;) – Tpojka Jan 09 '16 at 17:30