خرید بک لینک

سلام دوستان
یه ثبت نام کاربر ساده نوشتم میخواستم ببینم استانداردهای mvc را رعایت کرده ام یا نه

واینکه برای کار با جدول کاربران باید از همین مدل user استفاده بشه یا یه مدل جدید ساخته شود
اگه مشکلی بود خوشحال میشم بگید

<?php

namespace appmodels;

use Yii;

/**
* This is the model class for table "{{%shop_users}}".
*
* @property integer $id
* @property string $fname
* @property string $email
* @property string $user
* @property string $pass
* @property integer $phone
* @property string $address
* @property string $codemeli
* @property string $image
* @property integer $type
*/
class Users extends yiidbActiveRecord {

/**
* @inheritdoc
*/
public static function tableName() {
retu '{{%shop_users}}';
}

/**
* @inheritdoc
*/
public function rules() {
retu [
[['fname', 'email', 'user', 'pass', 'type', 'lname'], 'required', 'message' => '{attribute} نباید خالی باشد'],
[['phone', 'type'], 'integer'],
[['address'], 'string'],
[['fname', 'email', 'user'], 'string', 'max' => 255],
[['pass'], 'string', 'max' => 125],
[['codemeli'], 'string', 'max' => 10],
[['image'], 'string', 'max' => 500],
[['email'], 'email', 'message' => 'ادرس ایمیل معتبر وارد کنید'],
[['email'], 'unique', 'message' => '{attribute} تکراری میباشد'],
//[['email'], 'unique', 'message' => 'ین ایمیل قبلا ثبت شده است ']
];
}

/**
* @inheritdoc
*/
public function attributeLabels() {
retu [
'id' => Yii::t('app', 'شناسه کاربر'),
'fname' => Yii::t('app', 'نام '),
'email' => Yii::t('app', 'ادرس ایمیل'),
'user' => Yii::t('app', 'نام کاربری'),
'pass' => Yii::t('app', 'رمز عبور'),
'phone' => Yii::t('app', 'شماره همراه'),
'address' => Yii::t('app', 'ادرس'),
'codemeli' => Yii::t('app', 'کد ملی'),
'image' => Yii::t('app', 'عکس'),
'type' => Yii::t('app', 'جنسیت'),
'lname' => Yii::t('app', 'نام خانوادگی'),
];
}

public function register_user() {

//($this->validate())
if ( $this->save()){
Yii::$app->session->setFlash('user_register');
retu 1;
} else {
Yii::$app->session->setFlash('user_not_register');
retu -1;
}
}

}
************************************************** *

<?php

namespace appcontrollers;

use appmodelsUsers;
use Yii;

class UsersController extends yiiwebController {

public function actionIndex() {
retu $this->render('index');
}

public function actionRegister() {

$user = new Users();
if ($user->load(Yii::$app->request->post()) && $user->validate()) {
// $values = Yii::$app->request->post();
$user->register_user();
retu $this->refresh();
} else {
retu $this->render('index', ['model' => $user]);
}
}

}

**************************************************

<?php
/* @var $this yiiwebView */

use yiibootstrapActiveForm;
use yiihelpersHtml;
?>
<div class="row">
<div class="col-lg-6" >
<?php if (Yii::$app->session->hasFlash('user_not_register')) { ?>
<div class="alert alert-danger">
ثبت نام شما انجام نشد لطفا دوباره تلاش کنید.
</div>
<?php } ?>
<?php if (Yii::$app->session->hasFlash('user_register')) { ?>
<div class="alert alert-success">
ثبت نام شما با موفقیت انجام شد.
</div>
<?php } ?>
<div class="well">
<?php $form = yiiwidgetsActiveForm::begin() ?>

<?= $form->field($model, 'fname') ?>
<?= $form->field($model, 'lname') ?>
<?= $form->field($model, 'user') ?>
<?= $form->field($model, 'pass')->passwordInput() ?>
<?= $form->field($model, 'email') ?>
<?= $form->field($model, 'type')->radioList(['0' => 'مرد', '1' => 'زن'], ['prompt' => ' انتخاب کنید']) ?>
<?= "<div align ='left'>" . yiibootstrapHtml::submitButton('ثبت نام', ['class' => 'btn btn-success']) . "</div>" ?>
<?php $form->end(); ?>
</div>
<?php ?>
</div>
</div>

برچسب: نویسنده: محمد رضا جوادیان تاريخ: شنبه 29 خرداد 1395 ساعت: 7:20

صفحه بندی