Open djidji01 opened 3 years ago
But Yii::$app->requestedParams
are initialized here. Could you provide use case for having additional beforeRun
in the InlineAction
?
But
Yii::$app->requestedParams
are initialized here. Could you provide use case for having additionalbeforeRun
in theInlineAction
?
In fact the use case should be the same as beforeRun
implemented in standalone Action
. Any way , why was beforeRun
implemented on former and not on the later, yet both are to controlle the execution of controller method!?
Just providing possibility of additional logic while having Yii::$app->requestedParams
before execution as it is for standalone Action
. especially when arguments are action injected!!! as example, in bellow code, I may need to run the actionBook()
only if the context meets a condition defined by $bookingService
property or method or vice versa!!
Thanks
namespace app\controllers;
use yii\web\Controller;
use app\components\BookingInterface;
class HotelController extends Controller
{
public function actionBook($id, BookingInterface $bookingService)
{
$result = $bookingService->book($id);
// ...
}
}
But
Yii::$app->requestedParams
are initialized here. Could you provide use case for having additionalbeforeRun
in theInlineAction
?
although it is initialized there, it is where I do see the limitation since it is done after this beforeAction()
call. Also the condition above it will almost always evaluate to false
unless this is null, which is not possible.
Thanks
What steps will reproduce the problem?
Wouldn't it be great to wrap this https://github.com/yiisoft/yii2/blob/ff0760142d768b03e192098d94a3c0edc2710990/framework/base/InlineAction.php#L57
in a beforeRun condition as it is here https://github.com/yiisoft/yii2/blob/ff0760142d768b03e192098d94a3c0edc2710990/framework/base/Action.php#L93 on a standalone action?
What is the expected result?
This may help doing all logic and rules beforeRun and/or beforeAction while having all data ready, especially all arguments to be bound to the action that at this level are accessible on
Yii::$app->requestedParams
What do you get instead?
BeforeRun is not implemented on
\yii\base\inlineAction
andYii::$app->requestedParams
is not yet initialized ??!!!Additional info
I would suggest to have a beforeActionRun($action) on controller may be implemented as bellow
or just move the
Controller::beforeAction($action)
andModule::beforeAction($action)
around thiscall_user_func_array([$this, 'run'], $args)
; which will help accessing Yii::$app->requestedParams`Thank you very much