close

才研究完django framework沒多久,我又回到yii framework身上

之前在0.x beta時代有稍稍研究過,就一直擱置

直到最近yzlin幫忙把yii framework包成ports,不知道send pr沒

發現yii framework已經有好大的進展了

不過網路上的教學文似乎還是不多,但官方的document到是蠻豐富

可是那些文件需要花一點心思去進入狀況

好像現在每個framework都強調快速blog建成,應該是受ROR的影響吧

yii 官網上也有快速的blog建置,另外也有某個google code project是yii-blogdemo-enhanced

廢話不多說,來教學一下

1. 下載 yii framework

 Linux or Window : http://www.yiiframework.com/download/

Freebsd之後會進到ports, 直接/usr/ports/www/yii ,

並且選擇自己要的option  mysql或sqlite...etc

2. 設定php.ini的 include path

include_path = ".:/php/includes:/usr/local/share/yii/framework"

3.建立第一個yii application

  /your/yii/framework/path/yiic webapp /your/web/application/path

  如此會在你設定的path產生一個資料夾裡面得資料如下

assets/  css/  images/  index.php  protected/  themes/

主要的code都放在protected下,是MVC的方式

commands/  components/  config/  controllers/  extensions/  messages/  models/  runtime/  views/  yiic*  yiic.bat  yiic.php

4.連接database部分

  編輯protected/config/main.php

mysql請用

                  'db'=>array(
                          'class'=>'CDbConnection',
                          'connectionString'=>'mysql:host=localhost;dbname=test',
                          'username'=>'username',
                          'password'=>'password',
                  ),

sqlite請用

                  'db'=>array(
                          'class'=>'CDbConnection',
                          'connectionString'=>'sqlite:/db/path/sqlite.db',
                  ),

5.產生簡單model 和controller

/your/yii/framework/path/yiic shell /your/web/application/path/index.php

接著會進到shell裡面,

以下的xxx是你db裡面的table name,所以請自行調整

>> model xxx;

   generate xxx.php

The following model classes are successfully generated:
    xxx

If you have a 'db' database connection, you can test these models now with:
    $model=xxx::model()->find();
    print_r($model);

這樣就代表建立model成功

會在 protected/models產生Xxx.php

>>crud xxx;

   generate XxxController.php
      mkdir /your/web/application/path/protected/views/users
   generate create.php
   generate update.php
   generate list.php
   generate show.php
   generate admin.php
   generate _form.php

Crud 'xxx' has been successfully created. You may access it via:
http://hostname/path/to/index.php?r=xxx

6.遵照上面的url規則馬上貼到browser去看

就可以看到一個簡單的show databases的功能

登入admin之後還能create跟delete

其他之後再補充囉

arrow
arrow
    全站熱搜

    lyforever 發表在 痞客邦 留言(4) 人氣()