Yii-gii-creating-model
提供:Dev Guides
Gii-モデルの作成
Giiでモデルを作成するには-
<?php
namespace app\models;
use app\components\UppercaseBehavior;
use Yii;
/**
*This is the model class for table "user".
*
*@property integer $id
* @property string $name
*@property string $email
*/
class MyUser extends \yii\db\ActiveRecord {
/**
*@inheritdoc
*/
public static function tableName() {
return 'user';
}
/**
*@inheritdoc
*/
public function rules() {
return [
[[name', 'email'], 'string', 'max' => 255]
];
}
/**
*@inheritdoc
*/
public function attributeLabels() {
return [
'id' => 'ID',
'name' => 'Name',
'email' => 'Email',
];
}
}
?>
CRUDの生成
MyUserモデルのCRUDを生成します。
- ステップ1 *-CRUDジェネレーターインターフェイスを開き、フォームに入力します。
ステップ2 *-次に、[プレビュー]ボタンをクリックして[生成]をクリックします。 URL *http://localhost:8080/index.php?r = my-user にアクセスすると、すべてのユーザーのリストが表示されます。
ステップ3 *-URL *http://localhost:8080/index.php?r = my-user/create を開きます。 ユーザー作成フォームが表示されます。