{"record":{"id":"bd473aa1e79f8bd0","repo":"yiisoft/yii2","slug":"get-class-this-must-define-a-run-method","errorCode":null,"errorMessage":"get_class($this) . ' must define a \"run()\" method.'","messagePattern":"get_class\\(\\$this\\) \\. ' must define a \"run\\(\\)\" method\\.'","errorType":"exception","errorClass":"InvalidConfigException","httpStatus":null,"severity":"error","filePath":"framework/base/Action.php","lineNumber":88,"sourceCode":"     * @return string the unique ID of this action among the whole application.\n     */\n    public function getUniqueId()\n    {\n        return $this->controller->getUniqueId() . '/' . $this->id;\n    }\n\n    /**\n     * Runs this action with the specified parameters.\n     * This method is mainly invoked by the controller.\n     *\n     * @param array $params the parameters to be bound to the action's run() method.\n     * @return mixed the result of the action\n     * @throws InvalidConfigException if the action class does not have a run() method\n     */\n    public function runWithParams($params)\n    {\n        if (!method_exists($this, 'run')) {\n            throw new InvalidConfigException(get_class($this) . ' must define a \"run()\" method.');\n        }\n        $args = $this->controller->bindActionParams($this, $params);\n        Yii::debug('Running action: ' . get_class($this) . '::run(), invoked by ' . get_class($this->controller), __METHOD__);\n        if (Yii::$app->requestedParams === null) {\n            Yii::$app->requestedParams = $args;\n        }\n        if ($this->beforeRun()) {\n            $result = call_user_func_array([$this, 'run'], $args);\n            $this->afterRun();\n\n            return $result;\n        }\n\n        return null;\n    }\n\n    /**\n     * This method is called right before `run()` is executed.","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/yiisoft/yii2/blob/66f00d18a29b520f85e8e8f1e32d1e7e7b556cac/framework/base/Action.php#L70-L106","documentation":"Standalone actions (classes extending yii\\base\\Action, registered in a controller's actions() map) are executed via runWithParams(): it first checks method_exists($this, 'run') and throws InvalidConfigException(get_class($this) . ' must define a \"run()\" method.') before parameter binding, beforeRun()/afterRun(), and events. An Action without run() is unusable, so the throw fires on the first request to that action.","triggerScenarios":"A custom action class listed in actions() whose logic method is named execute() or handle() instead of run(); an abstract base Action class mistakenly registered directly in actions(); renaming run() during a refactor of a previously working action.","commonSituations":"Action classes ported from other frameworks (Symfony uses execute()); vendor Action base classes whose run() was removed and subclasses are expected to add it; scaffolding that generated an empty action body.","solutions":["Add 'public function run()' to the class named in the exception message and return the response/result from it","If the class is a shared base, mark it abstract and implement run() in each concrete subclass - never register the base class in actions()","If you actually wanted an inline action, delete the class and add action<Id>() to the controller instead"],"exampleFix":"// before\nclass DownloadAction extends \\yii\\base\\Action\n{\n    public function execute() { /* ... */ } // wrong method name\n}\n\n// after\nclass DownloadAction extends \\yii\\base\\Action\n{\n    public function run()\n    {\n        return $this->controller->response->sendFile($this->path);\n    }\n}","handlingStrategy":"validation","validationCode":"foreach ($this->actions() as $id => $definition) {\n    $class = is_array($definition) ? ($definition['class'] ?? null) : $definition;\n    if (is_string($class) && !method_exists($class, 'run')) {\n        throw new \\LogicException(\"Action '{$class}' registered as '{$id}' has no run() method\");\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    return $action->runWithParams($params);\n} catch (\\yii\\base\\InvalidConfigException $e) {\n    Yii::error($e->getMessage());\n    throw $e;\n}","preventionTips":["Cover every actions() entry with a smoke test that runs the route once","Use static analysis rules that flag Action subclasses without run()","Prefer a template-method base: final run() in the base class, subclasses override step methods"],"tags":["mvc","action","controller","run-method"],"backgroundTag":"abstract-method-not-implemented","analyzedSha":"66f00d18a29b520f85e8e8f1e32d1e7e7b556cac","analyzedAt":"2026-08-17T05:17:23.470Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}