yii framework學習筆記

來源:互聯網
上載者:User

yii framework學習筆記

首先呢,我學習的版本是yii framework1.1.10 版本
開始呢,php本地環境搭建好了嗎?yii是運行在php環境中的。
你可以去http://www.yiiframework.com/download/下載相應的版本,現在應該有更新的。
下載下來後,如果你會php的話,應該在demos檔案夾裡的檔案看出個大概文法吧,我是這麼學習的。
OK,下面部署下yii framework吧

第一步:檢測您的系統內容是否支援yii運行,建立一個空白網站,然後將requirements 複製其中,請求

localhost/requirements/index.php可獲得檢測結果,會顯示哪些組件能用哪些不能用。

第二步:建一個自己的yii framework架構的demo吧,在cmd中運行命令:c:\php\php.exe

c:\www\yii_framework\framework\yiic webapp c:\www\localhost,然後輸入yes。即可建立一個yii 結

構的模板檔案,你會發現c:\www\localhost檔案夾下多了assets、css、images、protected、themes、

index.php、index-test.php等檔案。

第三步:實現hello world! 在protected\controllers目錄下建立helloworldController.php檔案,寫入

代碼:

<?php
class HelloworldController extends Controller
{
 public function actionIndex()
 {
  echo 'hello world';
 }
}
?>
請求網址:http://localhost/index.php?r=Helloworld,即可。

小提示:

處理安全考慮,可以將protected移到網站外部的檔案夾,以避免使用者直接請求controller輸出一些許可權之

外資料,移動後可修改檔案入口檔案/index.php中
     $config=dirname(__FILE__).'/protected/config/main.php';
改為:
     $config=dirname(__FILE__).'../protected/config/main.php';
即可。

大概運行出效果,大家應該明白了吧,yii就是一個架構,實現了mvc架構,其中controllers是就是MVC中的C層。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.