F
F
funtik522016-03-21 20:31:06
Yii
funtik52, 2016-03-21 20:31:06

How to fix the registration controller on the site?

Hello. I study WEB according to the book. And now I ran into a problem - in the navigation bar, the author suggests not to create a link to enter the site, but to go to it manually by entering the address ("security"). As soon as I pass to the address the error takes off.
bc9876eb96024fe2863a2a7222138972.png
Here is the controller:

public function actionLogin()
  {
    $this->pageTitle = "Вход";
    $user = new User("search");
    if (isset($_POST['User'])) {
      $user->attributes = $_POST['User'];
      if ($user->validate()) {
        $idetntity = new UserIdentity($user->name, $user->password);
        if(($identity->authenticate()) &&
        (Yii::app()->user-login($identity))) {
          $this->redirect(array("site/index"));
        }
      }
    }
    $this->render('login', array('user' => $user));
  }

Here is the login.php template:
<h1><?php echo CHtml::encode($this->PageTitle); ?> </h1>
<?php if ($this->isMobile) { ?>
  <p> Пользователи мобильных устройств не могут войти на сайт.</p>
<?php } else { ?>
  <?php echo CHtml::beginForm() ?>
  <div class="label"><?php echo CHtml::activeLabelEx($user, "name")
  ?></div>
  <div class="control"><?php echo CHtml::activeTextField($user, "name")
  ?></div>
  <?php echo Chtml::error($user, "name") ?>
  <div class="label"><?php echo CHtml::activeLabelEx($user, "password")
  ?></div>
  <div class="control"><?php echo CHtml::activePasswordField($user, "password") ?><div>
  <?php echo CHtml::error($user, "password") ?>
  <div class="button"><?php echo CHtml::submitButton("Войти"); ?></div>
  <?php echo CHtml::endForm() ?>
<?php } ?>

Just to mention, to duplicate the password input field during registration, a field is created in the User class model:
class User extends CActiveRecord
{
  public $password2;

...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
enchikiben, 2016-03-21
@funtik52

you have a login file "rendered" in your controller $this->render('login', array('user' => $user)); and the error crashes on the fact that it cannot find the "password2" file, without the source code it's hard to understand what's wrong with you

I
ingwar4ik, 2016-03-22
@ingwar4ik

Not strong in yii, but probably you need to add password2 to the rules

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question