Search code examples
phpmodel-view-controlleryiiyii2

Yii Basic 404 Page not found


I very new to yii and I came accross this error and I can't find the cause of it.

SiteController.php

    public function actionUserForm(){


      $model = new UserForm();


      if($model->load(Yii::$app->request->post()) && $model->validate()){


      }else{

        return $this->render('userform', [
          'model' => $model,
        ]);
      }
    }

UserForm.php (Model)

<?php

namespace app\models;


use yii\base\Model;


class UserForm extends Model{
  public $name;
  public $email;


  public function rules(){
    return [
      [['name', 'email'], 'required'],
      //email form should look like an email
      ['email', 'email'],
    ];
  }
}

userform.php (View)

<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
?>


<?php

$form = ActiveForm::begin();
?>

<?=  $form->field($model, 'name'); ?>
<?=  $form->field($model, 'email'); ?>

<?=
 Html::submitButton('Submit', [
  'class' => 'btn btn-success'
]);

?>



     ?>

After that the resulting page would look like this. Can you help in identifying the problem and kindly point out the errors in the code? Because I am very new to this framework and I am still starting to get the feel for it. enter image description here

This is how I am accessing it right now. enter image description here

I have an .htaccess file that cleans up the url too.

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . index.php

Then in the web.php this was my step 2 to clean it. These are what I did before actually making the forms.

'urlManager' => [
          'enablePrettyUrl' => true,
          //this will remove index.php in the url
          'showScriptName' => false
          //this is a two step process, after this go to the .htaccess in the web directory
        ]

Solution

  • the right way for accessing Yii2 url is not cameCase but - minus separator

      ...   web/site/user-form