2

I am looking to make a custom route using the CodeIgniter framework. I am trying to make the URL like so:

http://localhost/accounts/Auth.dll?signin

So far I have tried adding the following to my routes.php config file:

$route['accounts/Auth.dll?signin'] = "accounts/signin";

but as you would guess, it doesn't work. I have also tried escaping the characters like this:

$route['accounts/Auth\.dll\?signin'] = "accounts/signin";

and that doesn't work either. I've also tried including the leading and trailing slashes .. that didn't work either. Anyone know by chance what could solve my issue?

Hashem Qolami
  • 97,268
  • 26
  • 150
  • 164
Andrew Butler
  • 1,060
  • 2
  • 14
  • 31

2 Answers2

3

I highly recommend to use a SEF routing.

But if for any reason you're not eager to, you could check the query string inside the Accounts Controller, and then invoke the proper method, as follows:

Router:

$route['accounts/Auth.dll'] = "accounts";

Controller:

class Accounts extends CI_Controller
{
    public function __construct()
    {
        # Call the CI_Controller constructor
        parent::__construct();

        # Fetch the query string
        if ($method = $this->input->server('QUERY_STRING', TRUE)) {
            # Check whether the method exists
            if (method_exists($this, $method)) {
                # Invoke the method
                call_user_func(array($this, $method));
            }
        }
    }

    protected function signin()
    {
        # Your logic here
    }
}

This allows you to invoke the methods by query string automatically.

Hashem Qolami
  • 97,268
  • 26
  • 150
  • 164
  • thanks for the suggestion of recommending SEF urls, but this is just for a small team, no one will be using a search engine to find this. – Andrew Butler Feb 06 '14 at 20:54
  • You have saved my Time! I have been trying to achieve this by Apache mod_rewrite rules. – kta Apr 17 '17 at 14:06
0

I am not sure, that its okay to use GET-params in routes.php config. Try such way:

routes.php

$route['accounts/Auth.dll'] = "accounts/index";

accounts.php

public function index() {
     if ($this->input->get('signin') != false) {
          $this->signin();
     }
}

private function signin() {
    // some code
}

But, as for me, it's bad way.

I recommend you just use another routing:

/accounts/Auth.dll/signin

And etc.