# 創建你自己的應用程序結構
> 注:本章節正在開發中。
雖然?[basic](https://github.com/yiisoft/yii2-app-basic)?和?[advanced](https://github.com/yiisoft/yii2-app-advanced)?項目模板能夠滿足你的大部分需求,但是,你仍有可能需要創建你自己的項目模板來開始項目。
Yii 的項目模板是一個包含?`composer.json`?文件的倉庫,并被注冊為一個 Composer package。任何一個倉庫都可以被標識為一個 Composer package,只要讓其可以通過?`create-project`?Composer 命令安裝。
由于完全從新創建一個你自己的模板工作量有點大,最好的方式是以一個內建模板為基礎。這里,我們使用基礎應用模板。
## 克隆基礎模板
第一步是從 Git 倉庫克隆 Yii 的基礎模板:
~~~
git clone git@github.com:yiisoft/yii2-app-basic.git
~~~
等待倉庫下載到你的電腦。因為為調整到你自己的模板所產生的修改不會被 push 回,你可以刪除下載下來的?`.git`?目錄及其內容。
## 修改文件
Next, you'll want to modify the?`composer.json`?to reflect your template. Change the?`name`,?`description`,?`keywords`,?`homepage`,`license`, and?`support`?values to describe your new template. Also adjust the?`require`,?`require-dev`,?`suggest`, and other options to match your template's requirements. 接下來,你需要修改?`composer.json`?以配置你自己的模板。修改?`name`,`description`,?`keywords`,?`homepage`,?`license`, 和?`support`?的值來描述你自己的模板。同樣,調整?`require`,?`require-dev`,`suggest`?和其他的參數來匹配你模板的環境需求。
> 注意:在?`composer.json`?文件中,使用?`extra`?下的?`writeable`?參數來指定使用模板創建的應用程序后需要設置文件權限的文件列表。
接下來,真正的修改你的應用程序默認的目錄結構和內容。最后,更新 README 文件以符合你的模板。
## 發布一個 Package
模板調整好后,通過其創建一個 Git 倉庫并提交你的代碼。如果你希望將你的應用程序模板開源,[Github](http://www.yiichina.com/doc/guide/2.0/tutorial-start-from-scratch)?將是最好的托管服務。如果你不喜歡其他的人來跟你一起協作,你可以使用任意的 Git 倉庫服務。
接下來,你需要為 Composer 注冊你的 package。對于公有的模板,你可以將 package 注冊到?[Packagist](https://packagist.org/)。對于私有的模板,注冊 package 將會麻煩一點。參考?[Composer documentation](https://getcomposer.org/doc/05-repositories.md#hosting-your-own)?獲取更多的指示。
## 使用模板
以上就是為了創建一個新的 Yii 項目模板你需要做的事情。現在,你可以使用你自己的模板創建項目了:
~~~
composer global require "fxp/composer-asset-plugin:~1.0.0"
composer create-project --prefer-dist --stability=dev mysoft/yii2-app-coolone new-project
~~~
- 介紹(Introduction)
- 關于 Yii(About Yii)
- 從 Yii 1.1 升級(Upgrading from Version 1.1)
- 入門(Getting Started)
- 安裝 Yii(Installing Yii)
- 運行應用(Running Applications)
- 第一次問候(Saying Hello)
- 使用 Forms(Working with Forms)
- 玩轉 Databases(Working with Databases)
- 用 Gii 生成代碼(Generating Code with Gii)
- 更上一層樓(Looking Ahead)
- 應用結構(Application Structure)
- 結構概述(Overview)
- 入口腳本(Entry Scripts)
- 應用(Applications)
- 應用組件(Application Components)
- 控制器(Controllers)
- 模型(Models)
- 視圖(Views)
- 模塊(Modules)
- 過濾器(Filters)
- 小部件(Widgets)
- 前端資源(Assets)
- 擴展(Extensions)
- 請求處理(Handling Requests)
- 運行概述(Overview)
- 引導(Bootstrapping)
- 路由引導與創建 URL(Routing and URL Creation)
- 請求(Requests)
- 響應(Responses)
- Sessions and Cookies
- 錯誤處理(Handling Errors)
- 日志(Logging)
- 關鍵概念(Key Concepts)
- 組件(Components)
- 屬性(Properties)
- 事件(Events)
- 行為(Behaviors)
- 配置(Configurations)
- 別名(Aliases)
- 類自動加載(Class Autoloading)
- 服務定位器(Service Locator)
- 依賴注入容器(Dependency Injection Container)
- 配合數據庫工作(Working with Databases)
- 數據庫訪問(Data Access Objects): 數據庫連接、基本查詢、事務和模式操作
- 查詢生成器(Query Builder): 使用簡單抽象層查詢數據庫
- 活動記錄(Active Record): 活動記錄對象關系映射(ORM),檢索和操作記錄、定義關聯關系
- 數據庫遷移(Migrations): 在團體開發中對你的數據庫使用版本控制
- Sphinx
- Redis
- MongoDB
- ElasticSearch
- 接收用戶數據(Getting Data from Users)
- 創建表單(Creating Forms)
- 輸入驗證(Validating Input)
- 文件上傳(Uploading Files)
- 收集列表輸入(Collecting Tabular Input)
- 多模型同時輸入(Getting Data for Multiple Models)
- 顯示數據(Displaying Data)
- 格式化輸出數據(Data Formatting)
- 分頁(Pagination)
- 排序(Sorting)
- 數據提供器(Data Providers)
- 數據小部件(Data Widgets)
- 操作客戶端腳本(Working with Client Scripts)
- 主題(Theming)
- 安全(Security)
- 認證(Authentication)
- 授權(Authorization)
- 處理密碼(Working with Passwords)
- 客戶端認證(Auth Clients)
- 安全領域的最佳實踐(Best Practices)
- 緩存(Caching)
- 概述(Overview)
- 數據緩存(Data Caching)
- 片段緩存(Fragment Caching)
- 分頁緩存(Page Caching)
- HTTP 緩存(HTTP Caching)
- RESTful Web 服務
- 快速入門(Quick Start)
- 資源(Resources)
- 控制器(Controllers)
- 路由(Routing)
- 格式化響應(Response Formatting)
- 授權驗證(Authentication)
- 速率限制(Rate Limiting)
- 版本化(Versioning)
- 錯誤處理(Error Handling)
- 開發工具(Development Tools)
- 調試工具欄和調試器(Debug Toolbar and Debugger)
- 使用 Gii 生成代碼(Generating Code using Gii)
- TBD 生成 API 文檔(Generating API Documentation)
- 測試(Testing)
- 概述(Overview)
- 搭建測試環境(Testing environment setup)
- 單元測試(Unit Tests)
- 功能測試(Functional Tests)
- 驗收測試(Acceptance Tests)
- 測試夾具(Fixtures)
- 高級專題(Special Topics)
- 高級應用模版(Advanced Project Template)
- 從頭構建自定義模版(Building Application from Scratch)
- 控制臺命令(Console Commands)
- 核心驗證器(Core Validators)
- 國際化(Internationalization)
- 收發郵件(Mailing)
- 性能優化(Performance Tuning)
- 共享主機環境(Shared Hosting Environment)
- 模板引擎(Template Engines)
- 集成第三方代碼(Working with Third-Party Code)
- 小部件(Widgets)
- Bootstrap 小部件(Bootstrap Widgets)
- jQuery UI 小部件(jQuery UI Widgets)
- 助手類(Helpers)
- 助手一覽(Overview)
- Array 助手(ArrayHelper)
- Html 助手(Html)
- Url 助手(Url)