創建yii第一個應用(gii)


1、…\yii\framework\yiic webapp D:\wamp\www\mimscmgr

     …\yii\framework\yiic --- 為解壓后的目錄,D:\wamp\www\mimscmgr ---服務器目錄

    執行完,於是就在mimscmgr下創建了一個最基本的應用。

2、在protected\config\main.php中,修改數據庫連接 ‘db’

因為使用mysql數據庫,所以修改如下:

/* 'db'=>array(
'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',
),*/
// uncomment the following to use a MySQL database

'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=dmpushtest',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
),
mysql:host=localhost  ---為本地數據庫
dbname=dmpushtest ---為數據庫名
username -- 數據庫登陸的用戶名
password -- 數據庫登陸的密碼

3、在dmpushtest庫中建表

CREATE TABLE IF NOT EXISTS `user` (
`id` int(10) NOT NULL auto_increment,
`username` varchar(128) NOT NULL,
`password` varchar(128) NOT NULL,
`email` varchar(128) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;

 4、配置Gii,需要編輯文件 WebRoot/testdrive/protected/main.php

    'modules'=>array(
        // uncomment the following to enable the Gii tool
        
        'gii'=>array(
            'class'=>'system.gii.GiiModule',
            'password'=>'*********',
            // If removed, Gii defaults to localhost only. Edit carefully to taste.
            'ipFilters'=>array('127.0.0.1','::1'),
        ),
    ),

password --設置gii登陸密碼

5、http://127.0.0.1/mimscmgr/index.php?r=gii

提示輸入密碼,登陸

6、進入ModelGenerator,提示超時。

修改php.ini:max_execution_time = 300

7、再次進入ModelGenerator --> preview -->generate,生成User模型

一個名為 User.php 將生成到protected/models 目錄中,網頁也就和數據庫表關聯上。

8、進入Crud Generator --> preview -->generate,生成CRUD 代碼

至此CRUD 代碼生成完成。

9、查看效果:http://127.0.0.1/mimscmgr/index.php?r=user

登入(login:admin/admin)后,就可以點擊頁面上的 Create User 鏈接,如果沒有登錄的話我們將被帶到登錄頁。登錄后,我們看到一個可供我們添加新用戶的表單。

完成表單並點擊 Create 按鈕,如果有任何輸入錯誤的話,一個友好的錯誤提示將會顯示並阻止我們保存。回到用戶列表頁,我們應該能看到剛才添加的用戶顯示在列表中。 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM