Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codeigniter-restserver and GET parameters #49

Closed
serazoli opened this issue Aug 31, 2015 · 12 comments
Closed

Codeigniter-restserver and GET parameters #49

serazoli opened this issue Aug 31, 2015 · 12 comments

Comments

@serazoli
Copy link

Hi.
The codeigniter-rest-server not accept the GET parameter from array (['name' => 'Mike'])

$output = $this->request('GET', 'query_string/index', ['name' => 'Mike']);

because rest-server don't use $_GET variable - if i saw good.
and

$output = $this->request('GET', 'query_string/index?name=Mike');

not work.
$output will be NULL
Sorry my bad English
Thanks.

@kenjis
Copy link
Owner

kenjis commented Aug 31, 2015

It seems you are right. But I don't know why codeigniter-restserver does not use CI_Input::get().

@kenjis
Copy link
Owner

kenjis commented Aug 31, 2015

How about this?

$output = $this->request('GET', 'query_string/index/name/Mike');

@serazoli
Copy link
Author

I have a little bit complicated parameters.
From client side I will get similar GET parameters

"page":"1","rows":"10",'filterRules':[{"field":"time","op":"between","value":["2015-08-01","2015-08-31"]}]

What will be from this parameter in the form proposed by you?
If I use "?" and "&" sign will be this

log?page=1&rows=10&filterRules=%5B%7B%22field%22%3A%22time%22%2C%22op%22%3A%22between%22%2C%22value%22%3A%5B%222015-08-01%22%2C%222015-08-31%22%5D%7D%5D

Thanks

@serazoli
Copy link
Author

have you any suggestion how I inject the above url to the codigniter?

@kenjis
Copy link
Owner

kenjis commented Aug 31, 2015

This is workaround for example 7 (User #1 - get it in XML (users/id/1?format=xml)):

        set_is_cli(FALSE);
        $this->warningOff();
        $_SERVER['REQUEST_URI'] = 'api/example/users/id/1?format=xml';
        $output = $this->request('GET', 'api/example/users/id/1');
        set_is_cli(TRUE);
        $this->warningOn();

        $this->assertEquals(
            '<?xml version="1.0" encoding="utf-8"?>
<xml><id>1</id><name>John</name><email>john@example.com</email><fact>Loves coding</fact></xml>
',
            $output
        );
        $this->assertResponseCode(200);

In your case, you set $_SERVER['REQUEST_URI'] like this:

$_SERVER['REQUEST_URI'] = 'log?page=1&rows=10&filterRules=%5B%7B%22field%22%3A%22time%22%2C%22op%22%3A%22between%22%2C%22value%22%3A%5B%222015-08-01%22%2C%222015-08-31%22%5D%7D%5D';

@kenjis kenjis added the discuss label Aug 31, 2015
@kenjis
Copy link
Owner

kenjis commented Aug 31, 2015

I posted issue to ask why.
chriskacerguis/codeigniter-restserver#544

@serazoli
Copy link
Author

Thanks.
I made a quick test for workaround you wrote above and is look like ok.

@kenjis
Copy link
Owner

kenjis commented Sep 1, 2015

I sent PR: #51

With this PR, we can write test like this:

        set_is_cli(FALSE);
        $this->warningOff();
        $output = $this->request(
            'GET',
            'api/example/users/id/1?format=xml'
        );
        set_is_cli(TRUE);
        $this->warningOn();

        $this->assertEquals(
            '<?xml version="1.0" encoding="utf-8"?>
<xml><id>1</id><name>John</name><email>john@example.com</email><fact>Loves coding</fact></xml>
',
            $output
        );
        $this->assertResponseCode(200);

But we can't remove below, because of implementation of codeigniter-restserver.

        set_is_cli(FALSE);
        $this->warningOff();

@serazoli
Copy link
Author

serazoli commented Sep 1, 2015

Thanks, I will try ASAP

@kenjis
Copy link
Owner

kenjis commented Sep 2, 2015

@kenjis
Copy link
Owner

kenjis commented Nov 15, 2015

@serazoli
The latest reset server (see master brach) is fixed. And I added a test you want:
kenjis/ci-app-for-ci-phpunit-test@308a47b

@serazoli
Copy link
Author

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants