3

I have controller called RegisterController and index view. If I submit the form, its showing the page not found (404) error. In the same if I change the method to actionCreate instead of actionAddBasic, working fine. Please help me to resolve the issue. Thanks.

RegisterController.php

<?php    
namespace app\controllers;

use app\models\Address;
use yii;
use yii\filters\AccessControl;
use yii\web\Controller;
use yii\filters\VerbFilter;
use app\models\BasicInfo;
use app\models\User;    

/**
 * Class RegisterController
 * To Handle Registration Related Requests.
 */
class RegisterController extends Controller
{
     public function behaviors()
    {
        return [
           'access' => [
                'class' => AccessControl::className(),
                'only' => ['addBasic'],
                'rules' => [
                    [
                        'actions' => ['addBasic'],
                        'allow' => true,
                        'roles' => ['?'],
                    ],
                ],
            ],
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'addBasic' => ['post'],
                ],
            ],
        ];
    }


    /**
     * To Load Registration Page.
     */
    public function actionIndex()
    {
        $user = new User();
        $basicInfo = new BasicInfo();
        $basicInfo->gender = 1;
        $fileUpload = new FileUpload();
        $addressModel = new Address();
        return $this->render('index', [
            'userModel' => $user,
            'basicInfoModel' => $basicInfo,
            'fileUploadModel' => $fileUpload,
            'addressModel' => $addressModel
        ]);
    }

    public function actionAddBasic()
    {
        yii::trace('Inside AddBasic');
        return $this->render('index', [
            'userModel' => new User(),
            'basicInfoModel' => new BasicInfo(),
            'fileUploadModel' => new FileUpload(),
            'addressModel' => new Address()
        ]);
    }

}

register/index.php:

    <?php
    use yii\helpers\Html;
    use yii\helpers\ArrayHelper;
    use yii\widgets\ActiveForm;
    use app\models\MaritalStatus;
    use app\models\ProfileFor;

    ?>
    <div class="form">
        <?php $form = ActiveForm::begin(['id' => 'form-signup-1', 'action' => ['index.php/register/addBasic']]); ?>

                    <div class="row">
                        <?= $form->field($basicInfoModel, 'name')->textInput(['maxlength' => 25, 'placeholder' => 'Name']) ?>
                    </div>
                    <div class="row">
                        <?= $form->field($userModel, 'email')->input('email', ['maxlength' => 30, 'placeholder' => 'Email']) ?>
                    </div>
                    <div class="row">
                        <?= $form->field($userModel, 'mno')->input('text', ['maxlength' => 10, 'placeholder' => 'Mobile Number']) ?>
                    </div>  
<div class="row" style="float: right;">
                    <?= Html::submitButton('Create', ['class' => 'btn btn-success']) ?>
                    <?= Html::resetButton('Reset', ['class' => 'btn btn-success']) ?>
                </div>             
        <?php ActiveForm::end(); ?>
    </div>

1 Answer 1

3

I don't get the benefit of creating separate action in your case, but the error is here:

'action' => ['index.php/register/addBasic'],

addBasic should be replaced with add-basic.

Action names transformed with dash and lowercase.

Also including index.php in url is redundant, this should be enough:

'action' => ['register/add-basic'],

Or even this for the same controller:

'action' => ['add-basic'],

Official documentation:

Sign up to request clarification or add additional context in comments.

3 Comments

Still i am getting object not found 404
Object not found? Or page not found? Show full error text, trace will be helpful as well.
Thanks bro... Its working fine... Changed to 'action' => ['index.php/register/add-basic']..... if i put 'action' => ['add-basic'] not working.... Thanks a lot....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.