yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.24k stars 6.91k forks source link

\Yii::$app->requestedParams not compatible with currently running action! #18494

Open djidji01 opened 3 years ago

djidji01 commented 3 years ago

What steps will reproduce the problem?

I have this controller as application controller:

class TestController extends Controller
{
    public function actionNum($numOne, $numTwo, $numThree)
    {

    }

    public function actionLtr($ltrOne, $ltrTwo, $ltrthree)
    {
    }
}

Then execute:

$paramsNum = ['numOne' => 1, 'numTwo' => 2, 'numThree' => 3];
$result = $app->controller->runAction('num', $params);
$requestedParamsNum = \Yii::$app->requestedParams;

then

$paramsLtr = ['ltrOne' => 'A', 'ltrOne' => 'B',  'ltrOne' => 'C'];
$result = $app->controller->runAction('ltr', $params);
$requestedParamsLtr = \Yii::$app->requestedParams;

What is the expected result?

$requestedParamsNum === $paramsNum and $requestedParamsLtr === $paramsLtr

What do you get instead?

$requestedParamsNum === $paramsNum and $requestedParamsLtr === $requestedParamsNum

Additional info

note that even though $requestedParamsLtr and $requestedParamsNum are obtained after complete execution of runAction(), the issue is the same even during its execution process because , during \Yii::$app whole lifetime, \Yii::$app->requestedParams stays attached to the arguments of the very first action executed!!??

I would suggest refactoring this for web and this for console also here and here for both , unless \Yii::$app is assigned to run only one action during its lifetime!!!

Q A
Yii version 2.0.?
PHP version
Operating system
bizley commented 3 years ago

Well, yes, by default Yii::$app handles one life-cycle. Some things apparently need to be adjusted.

djidji01 commented 3 years ago

Well, yes, by default Yii::$app handles one life-cycle. Some things apparently need to be adjusted.

I meant running only one action during this one life-cycle, which I think is not! sure some thing need to be adjusted.

bizley commented 3 years ago

No, it is one action per life-cycle by default.

djidji01 commented 3 years ago

The logic here and here prove that the door is open to more than one action per life-cycle.

bizley commented 3 years ago

I think it was more for the case when the objects are changed during the processing. I'm not sure though.