Action register error

When trying to access the registration form, it returns an error working from production. In local it does not give me this error.

this is the error:


Hubo un error interno del servidor.

The above error occurred while the Web server was processing your request.

Please contact us if you think this is a server error. Thank you.


<?php namespace app\controllers; use Yii; use yii\filters\AccessControl; use yii\web\Controller; use yii\web\Response; use yii\filters\VerbFilter; use app\models\LoginForm; use app\models\FormRegister; use app\models\Users; use app\models\User; use yii\helpers\Html; use yii\helpers\Url; use yii\data\ActiveDataProvider; use app\models\Talentos; use app\models\Filtro; use app\models\FormPreregistro; class SiteController extends Controller { public function actionRegister(){ $model = new FormRegister(); $msg = null; if ($model->load(Yii::$app->request->post())){ if($model->validate()){ $table = new Users; $table->username = $model->username; $table->email = $model->email; $table->tipo = "invitado"; $table->password = crypt($model->password, Yii::$app->params["salt"]); $table->authKey = $this->randKey("abcdef0123456789", 200); $table->accessToken = $this->randKey("abcdef0123456789", 200); if ($table->insert()){ $user = $table->find()->where(["email" => $model->email])->one(); $id = urlencode($user->id); $authKey = urlencode($user->authKey); $subject = "Confirmar registro"; $body = "

Haga click en el siguiente enlace para finalizar tu registro

"; $body .= "Confirmar"; Yii::$app->mailer->compose() ->setTo($user->email) ->setFrom([Yii::$app->params["adminEmail"] => Yii::$app->params["title"]]) ->setSubject($subject) ->setHtmlBody($body) ->send(); $model->username = null; $model->email = null; $model->password = null; $model->password_repeat = null; $msg = "Enhorabuena, ahora sólo falta que confirmes tu registro en tu cuenta de correo"; }else{ $msg = "Ha ocurrido un error al llevar a cabo tu registro"; } }else{ $model->getErrors(); } } return $this->render("register", ["model" => $model, "msg" => $msg]); } } My model “FormRegister.php” <?php namespace app\models; use Yii; use yii\base\model; use app\models\Users; class FormRegister extends model{ public $username; public $email; public $password; public $password_repeat; public function rules(){ return [ [['username', 'email', 'password', 'password_repeat'], 'required', 'message' => 'Campo requerido'], ['username', 'match', 'pattern' => "/^.{3,50}$/", 'message' => 'Mínimo 3 y máximo 50 caracteres'], ['username','email', 'message' => 'Formato no válido'], ['username', 'username_existe'], ['email', 'match', 'pattern' => "/^.{5,80}$/", 'message' => 'Mínimo 5 y máximo 80 caracteres'], ['email', 'email', 'message' => 'Formato no válido'], ['email', 'email_existe'], ['password', 'match', 'pattern' => "/^.{8,16}$/", 'message' => 'Mínimo 6 y máximo 16 caracteres'], ['password_repeat', 'compare', 'compareAttribute' => 'password', 'message' => 'Los passwords no coinciden'], ]; } public function email_existe($attribute, $params){ $table = Users::find()->where("email=:email", [":email" => $this->email]); if ($table->count() == 1){ $this->addError($attribute, "El email seleccionado existe"); } } public function username_existe($attribute, $params){ $table = Users::find()->where("username=:username", [":username" => $this->username]); if ($table->count() == 1) { $this->addError($attribute, "El usuario seleccionado existe"); } } } My view “register.php” <?php use yii\helpers\Html; use yii\widgets\ActiveForm; ?>

<?= $msg ?>


<?php $form = ActiveForm::begin([ 'method' => 'post', 'id' => 'formulario', 'enableClientValidation' => true, 'enableAjaxValidation' => false, ]); ?>
<?= $form->field($model, "username")->input("text")->label('Usuario') ?>
<div class="form-group">
 <?= $form->field($model, "email")->input("email") ?>   

<div class="form-group">
 <?= $form->field($model, "password")->input("password")->label('Contraseña') ?>   

<div class="form-group">
 <?= $form->field($model, "password_repeat")->input("password")->label('Repite Contraseña') ?>   

<?= Html::submitButton("Registrar", ["class" => "btn btn-primary"]) ?>

<?php  ActiveForm::end(); ?>

What’s the error in the log file?

2021-01-09 14:44:30 [][1][32b1ad2cce568d220aaf9edaeef533b6][error][Error] Error: Class ‘yii\base\model’ not found in /homepages/7/d815927762/htdocs/talentos/models/FormRegister.php:8
Stack trace:
#0 /homepages/7/d815927762/htdocs/talentos/vendor/yiisoft/yii2/BaseYii.php(293): include()
#1 [internal function]: yii\BaseYii::autoload(‘app\models\Form…’)
#2 /homepages/7/d815927762/htdocs/talentos/controllers/SiteController.php(391): spl_autoload_call(‘app\models\Form…’)
#3 [internal function]: app\controllers\SiteController->actionRegister()
#4 /homepages/7/d815927762/htdocs/talentos/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#5 /homepages/7/d815927762/htdocs/talentos/vendor/yiisoft/yii2/base/Controller.php(180): yii\base\InlineAction->runWithParams(Array)
#6 /homepages/7/d815927762/htdocs/talentos/vendor/yiisoft/yii2/base/Module.php(528): yii\base\Controller->runAction(‘register’, Array)
#7 /homepages/7/d815927762/htdocs/talentos/vendor/yiisoft/yii2/web/Application.php(103): yii\base\Module->runAction(‘site/register’, Array)
#8 /homepages/7/d815927762/htdocs/talentos/vendor/yiisoft/yii2/base/Application.php(386): yii\web\Application->handleRequest(Object(yii\web\Request))
#9 /homepages/7/d815927762/htdocs/talentos/web/index.php(12): yii\base\Application->run()

Your FormRegister class is trying to access the class yii\base\model with the letter m in small caps (this class doesn’t exist). update this part of the code to yii\base\Model with the letter m in uppercase.

1 Like

That was the mistake. buff what nonsense and I’ve been with it for hours. Thank you very much for your help, really thank you very much