PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, February 26, 2022

[FIXED] Yii Basic 404 Page not found

 February 26, 2022     model-view-controller, php, yii, yii2     No comments   

Issue

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


Answered By - ScaisEdge
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing