vlucas / bulletphp

A resource-oriented micro PHP framework
http://bulletphp.com
BSD 3-Clause "New" or "Revised" License
416 stars 50 forks source link

$request->param('inputfield','default_value') always return default_value #76

Closed tablecell closed 6 years ago

tablecell commented 7 years ago

test.php

$app->path('/TestPostParam', function($request) use($app) {  
    $this->post(function($request) use($app){
        echo '<PRE>';print_r($request->params());
        echo '<HR/>';
                print_r($request->param()); 
        echo '<HR/>';

            echo $request->AA;
        echo '<HR/>';
        $aa= $request->param('AA','1111');
        var_dump($aa);
    });

    $this->get(function($request) use($app){

        return <<<T
        <style>
        input{height:32px;}
        </style>
        <form action="/TestPostParam?cc=&bb=100" method="post">
        <input name="AA"   />
        <input name="BB" value="someValue" />
        <input type="submit" value="SEND">

        </form>
T;

    });

});

neither input AA field or not, $aa is always got default value i assume the correct logic of $request->param('inputfield','default_value') is that if input field AA has value ,then get the input value ,if value of field AA omit ,then set default value but the result is $aa always return default value just like statement $aa ='default value';

tablecell commented 7 years ago

if querystring has a key ,but no value given just like /testGetParam? aa=&bb=11000 vendor\vlucas\bulletphp\src\Bullet\Request.php Line 416

    return (isset($this->_params[$key])) ? $this->_params[$key] : $default;

$request->param('aa','defautValue') return NULL

i change to

        if( isset($this->_params[$key] )){

            if (NULL  != $this->_params[$key]){

                return $this->_params[$key];

            }

        }

        return $default;

it works ok for $_GET but do nothing with $_POST

netom commented 6 years ago

$request->param(s)() doesn't store query or post params, as stated in the documentation: http://bulletphp.com/docs/request/. Using the proper query() and post() methods will give the proper result.