Yii框架中注册表单

rur96b6h  于 2022-11-09  发布在  其他
关注(0)|答案(2)|浏览(180)

我是Yii 1框架新手!我在这个框架中建立了注册表单,包括控制器,模型和视图。我的控制器是这样的:

<?php class RegisterController extends Controller{
public function actionIndex()
{
    $this->layout='//layouts/main';
    $this->render('index');
}  public function actionRegister() {
$model   = new RegisterForm ;
$newUser = new User;   if(isset($_POST['RegisterForm'])) {
  $model->attributes = $_POST['RegisterForm'];
  if($model->validate()) {
  $newUser->name = $model->name ;
  $newUser->contact_no = $model->contact_no;
  $newUser->email = $model->email;
  $newUser->password = $model->password;
  if($newUser->save()) {
   $this->_identity = new UserIdentity($newUser->email,$newUser->password);
    if($this->_identity->authenticate())
     Yii::app()->user->login($this->_identity);
     $this->redirect(Yii::app()->user->returnUrl);
    }
  }
}$this->render('register',array('model'=>$model));}}

我也有一个视图文件名为register,它有两个PHP文件名为index和register,但当我输入我的addrees:http://localhost/blog/index. php/register它只是显示索引文件中的内容,但我想看看我在注册表文件中设置了什么,但我不知道如何才能做到这一点,有人能帮助我吗?
这里是我的索引和注册代码的视图文件:(注册)

<?php echo CHtml::errorSummary($model); ?>

<div class="row">
    <?php echo CHtml::activeLabel($model,'Name'); ?>
    <?php echo CHtml::activeTextField($model,'name') ?>
</div>

<div class="row">
    <?php echo CHtml::activeLabel($model,'Contact Number'); ?>
    <?php echo CHtml::activeTextField($model,'contact_no') ?>
</div>

<div class="row">
    <?php echo CHtml::activeLabel($model,'email'); ?>
    <?php echo CHtml::activeTextField($model,'email') ?>
</div>

<div class="row">
    <?php echo CHtml::activeLabel($model,'password'); ?>
    <?php echo CHtml::activePasswordField($model,'password') ?>
</div>

<div class="row">
    <?php echo CHtml::activeLabel($model,'Retype Password'); ?>
    <?php echo CHtml::activePasswordField($model,'retypepassword') ?>
</div>

<div class="row submit">
    <?php echo CHtml::submitButton('Register'); ?>
</div>

<?php echo CHtml::endForm(); ?>

索引:

<?php $this->breadcrumbs=array(
'Register',);?> <p>
You may change the content of this page by modifying
the file <tt><?php echo __FILE__; ?></tt>.</p>
sy5wg1nm

sy5wg1nm1#

首先,当你新的Yii我建议你使用Yii 2.
现在你的问题。它显示你使用了错误的网址。
您有RegisterController,并且来自此控制器的路由是http://localhost/blog/index.php/registerhttp://localhost/blog/index.php?r=registerhttp://localhost/blog/index.php/register/indexhttp://localhost/blog/index.php?r=register/index是相同的。
这是默认值,并调用actionIndex函数。
用于调用actionRegister函数。您必须调用此URL http://localhost/blog/index.php/register/registerhttp://localhost/blog/index.php?r=register/register
在这里你可以找到关于控制器路由的文档:https://www.yiiframework.com/doc/guide/1.1/en/basics.controller#route
如果要使用http://localhost/blog/register,则必须启用urlManagerhttps://www.yiiframework.com/doc/guide/1.1/en/topics.url

50pmv0ei

50pmv0ei2#

您访问方式错误,我认为问题与路由有关请尝试使用以下URL
登录以获取访问权限

相关问题