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

[NFR] Please consider to change the behaviour with default values in the getQuery() function of the Http\Request object #1226

Closed
bensbox opened this issue Sep 13, 2013 · 4 comments

Comments

@bensbox
Copy link

bensbox commented Sep 13, 2013

Currently the getQuery() function of the Http\Request object only returns the default value, when the requested parameter is not being used at all.

Examplecode:

<?php

$di = new Phalcon\DI\FactoryDefault();
$app = new Phalcon\Mvc\Micro();

$app->setDI($di);

$app->get('/', function () use ($app) {
    echo("->".$app['request']->getQuery('id', 'int', 100));
});

$app->handle();

Requests

Example 1
Request: http://localhost/test.php?id=aa
Returned value: ""
Example 2
Request: http://localhost/test.php?id=a11a
Returned value: "11"
Example 3
Request: http://localhost/test.php?id=
Returned value: ""
Example 4
Request: http://localhost/test.php
Returned value: "100"

As in example 4 i would expect to get the default value in the examples 1 and 3 as well, since the given values have been removed by the "int" filter.

A default value is suppose to be returned as soon as there is nothing to return - this is regardless if there is no parameter given, a parameter is empty or the filter emptied the parameter.
The result is always the same - i do not get any value back and i need my default value.

In my case i need to implement additional checks every time i use that funtion, because i can not rely on it to at least return my default value. That will result into additional unnecessary lines of code.

Related forum thread: http://forum.phalconphp.com/discussion/877/error-message-when-using-integer-filter-in-getquery-function-of-

@dreamsxin
Copy link
Contributor

I fix it, Adding a parameter to control the use of default values.

<?php

$di = new Phalcon\DI\FactoryDefault();
$app = new Phalcon\Mvc\Micro();

$app->setDI($di);

$app->get('/', function () use ($app) {
    echo("->".$app['request']->getQuery('id', 'int', 100, FALSE));
});

$app->handle();

@bensbox
Copy link
Author

bensbox commented Sep 16, 2013

Just to make sure - i understand, that i need to add "false" to get the desired behaviour.
This would be quite nice, even though i would prefer not to do add the parameter, but the backwards compatibility needs to be ensured of course!

Thanks for the nice work - looking forward to the approval :)

@dreamsxin
Copy link
Contributor

@bensbox I change param allowEmpty to notAllowEmpty, So you must use "TRUE"

$app->get('/', function () use ($app) {
    echo("->".$app['request']->getQuery('id', 'int', 100, TRUE));
});

@phalcon
Copy link
Collaborator

phalcon commented Oct 2, 2013

This is implemented in 1.3.0

@phalcon phalcon closed this as completed Oct 2, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants