Zend Framework提供了命令行的方式快速創(chuàng)建應用,如果是用ZendStudio9,可能步采用命令行的方式,當時你稀飯的話,可以用。
下載完整的庫文件包,在bin目錄的幾個腳本就是用來創(chuàng)建應用的。
root@coder-671T-M:/mydev_src/zend_framework_learn/ZendFramework-1.11.11# tree -L 2.├── bin│ ├── zf.bat│ ├── zf.php│ └── zf.sh├── demos│ └── Zend├── documentation│ ├── api│ └── manual├── externals│ └── dojo├── extras│ ├── library│ └── tests├── incubator├── INSTALL.txt├── library│ └── Zend├── LICENSE.txt├── README.txt├── resources│ └── languages├── src└── tests ├── AllTests.php ├── phpunit.xml ├── resources ├── runtests.sh ├── TestConfiguration.php.dist ├── TestHelper.php └── Zend20 directories, 11 files
具體給出的命令格式如下:
Zend Framework Command Line Console Tool v1.11.11Usage: zf [--global-opts] action-name [--action-opts] provider-name [--provider-opts] [provider parameters ...] Note: You may use "?" in any place of the above usage string to ask for more specific help information. Example: "zf ? version" will list all available actions for the version provider.Providers and their actions: Version zf show version mode[=mini] name-included[=1] Note: There are specialties, use zf show version.? to get specific help on them. Config zf create config zf show config zf enable config Note: There are specialties, use zf enable config.? to get specific help on them. zf disable config Note: There are specialties, use zf disable config.? to get specific help on them. Phpinfo zf show phpinfo Manifest zf show manifest Profile zf show profile Project zf create project path name-of-profile file-of-profile zf show project Note: There are specialties, use zf show project.? to get specific help on them. Application zf change application.class-name-prefix class-name-prefix Model zf create model name module View zf create view controller-name action-name-or-simple-name module Controller zf create controller name index-action-included[=1] module Action zf create action name controller-name[=Index] view-included[=1] module Module zf create module name Form zf enable form module zf create form name module Layout zf enable layout zf disable layout DbAdapter zf configure db-adapter dsn section-name[=production] DbTable zf create db-table name actual-table-name module force-overwrite Note: There are specialties, use zf create db-table.? to get specific help on them. ProjectProvider zf create project-provider name actions
/mydev_src/zend_framework_learn/ZendFramework-1.11.11/bin
設置臨時的path,重啟會失效的。
export PATH=$PATH:/mydev_src/zend_framework_learn/ZendFramework-1.11.11/bin
顯示框架版本
root@coder-671T-M:~# zf.sh show version
Zend Framework Version: 1.11.11
Project 創(chuàng)建一個項目
zf create project path name-of-profile file-of-profile
zf show project
Note: There are specialties, use zf show project.? to get specific help on them.
root@coder-671T-M:/mydev_src/zend_framework_learn/www# zf.sh create project zf_demo2Creating project at /mydev_src/zend_framework_learn/www/zf_demo2Note: This command created a web project, for more information setting up your VHOST, please see docs/READMETesting Note: PHPUnit was not found in your include_path, therefore no testing actions will be created.root@coder-671T-M:/mydev_src/zend_framework_learn/www# ll總用量 28drwxr-xr-x 6 root root 4096 2011-12-06 16:35 ./drwxr-xr-x 9 root root 4096 2011-12-06 16:08 ../drwxr-xr-x 4 root root 4096 2011-12-06 12:48 .metadata/-rw-r--r-- 1 root root 17 2011-12-06 12:30 phpinfo.phpdrwxr-xr-x 2 root root 4096 2011-12-06 12:48 RemoteSystemsTempFiles/drwxr-xr-x 8 root root 4096 2011-12-06 13:56 zf_demo1/drwxr-xr-x 7 root root 4096 2011-12-06 16:35 zf_demo2/root@coder-671T-M:/mydev_src/zend_framework_learn/www#創(chuàng)建成功,訪問一下:
http://localzend.com/zf_demo2/public/
顯示項目結構信息
root@coder-671T-M:/mydev_src/zend_framework_learn/www/zf_demo2# zf.sh show profileProjectDirectory ProjectProfileFile ApplicationDirectory ConfigsDirectory ApplicationConfigFile ControllersDirectory ControllerFile ActionMethod ControllerFile ModelsDirectory ViewsDirectory ViewScriptsDirectory ViewControllerScriptsDirectory ViewScriptFile ViewControllerScriptsDirectory ViewScriptFile ViewHelpersDirectory BootstrapFile DocsDirectory file LibraryDirectory PublicDirectory PublicIndexFile HtaccessFile TestsDirectory TestPHPUnitConfigFile TestPHPUnitBootstrapFile TestApplicationDirectory TestApplicationControllerDirectory TestApplicationControllerFile TestLibraryDirectoryroot@coder-671T-M:/mydev_src/zend_framework_learn/www/zf_demo2#
顯示Phpinfo
zf.sh show phpinfo
查看指定命令的幫助信息:
zf.sh ? (命令)
Config創(chuàng)建include_path配置文件
zf create config
zf show config
zf enable config
Note: There are specialties, use zf enable config.? to get specific help on them.
zf disable config
Note: There are specialties, use zf disable config.? to get specific help on them.
root@coder-671T-M:/mydev_src/zend_framework_learn/www/zf_demo2# zf.sh create config
Successfully written Zend Tool config.
It is located at: /root/.zf.ini
大體內(nèi)容
php.include_path = "/mydev_src/zend_framework_learn/ZendFramework-1.11.11/library:.:/usr/share/php:/usr/share/pear"
作用不言而喻。
Model 創(chuàng)建Model,可以指定模塊,也是創(chuàng)建全局的
zf create model name module
root@coder-671T-M:/mydev_src/zend_framework_learn/www/zf_demo2# zf.sh create model myModel testmod
Note: The canonical model name that is used with other providers is "MyModel"; not "myModel" as supplied
Creating a model at /mydev_src/zend_framework_learn/www/zf_demo2/application/modules/testmod/models/MyModel.php
Updating project profile '/mydev_src/zend_framework_learn/www/zf_demo2/.zfproject.xml'
/zf_demo2/application/modules/testmod/models/MyModel.php
<?phpclass Testmod_Model_MyModel{}
root@coder-671T-M:/mydev_src/zend_framework_learn/www/zf_demo2# zf.sh create controller NewsManage 1 testmodNote: PHPUnit is required in order to generate controller test stubs.Creating a controller at /mydev_src/zend_framework_learn/www/zf_demo2/application/modules/testmod/controllers/NewsManageController.phpCreating an index action method in controller NewsManageCreating a view script for the index action method at /mydev_src/zend_framework_learn/www/zf_demo2/application/modules/testmod/views/scripts/news-manage/index.phtmlUpdating project profile '/mydev_src/zend_framework_learn/www/zf_demo2/.zfproject.xml'
root@coder-671T-M:/mydev_src/zend_framework_learn/www/zf_demo2/application/modules# tree .└── testmod ├── controllers │ └── NewsManageController.php ├── forms │ └── TestForm.php ├── models │ └── MyModel.php └── views ├── filters ├── helpers └── scripts └── news-manage └── index.phtml9 directories, 4 files/zf_demo2/application/modules/testmod/controllers/NewsManageController.php
<?phpclass Testmod_NewsManageController extends Zend_Controller_Action{ public function init() { /* Initialize action controller here */ } public function indexAction() { // action body }}
root@coder-671T-M:/mydev_src/zend_framework_learn/www/zf_demo2/application/modules# tree.└── testmod ├── controllers │ └── NewsManageController.php ├── forms │ └── TestForm.php ├── models │ └── MyModel.php └── views ├── filters ├── helpers └── scripts └── news-manage ├── add.phtml └── index.phtml9 directories, 5 files
<?phpclass Testmod_NewsManageController extends Zend_Controller_Action{ public function init() { /* Initialize action controller here */ } public function indexAction() { // action body } public function addAction() { // action body }}
root@coder-671T-M:/mydev_src/zend_framework_learn/www/zf_demo2# zf.sh create action edit NewsManage testmodNote: PHPUnit is required in order to generate controller test stubs.Creating an action named edit inside controller at /mydev_src/zend_framework_learn/www/zf_demo2/application/modules/testmod/controllers/NewsManageController.phpUpdating project profile '/mydev_src/zend_framework_learn/www/zf_demo2/.zfproject.xml'Creating a view script for the edit action method at /mydev_src/zend_framework_learn/www/zf_demo2/application/views/scripts/news-manage/edit.phtmlUpdating project profile '/mydev_src/zend_framework_learn/www/zf_demo2/.zfproject.xml'root@coder-671T-M:/mydev_src/zend_framework_learn/www/zf_demo2# zf.sh create view NewsManage edit testmodUpdating project profile '/mydev_src/zend_framework_learn/www/zf_demo2/.zfproject.xml'
root@coder-671T-M:/mydev_src/zend_framework_learn/www/zf_demo2# zf.sh create view NewsManage editx testmodUpdating project profile '/mydev_src/zend_framework_learn/www/zf_demo2/.zfproject.xml'
.└── testmod ├── controllers │ └── NewsManageController.php ├── forms │ └── TestForm.php ├── models │ └── MyModel.php └── views ├── filters ├── helpers └── scripts └── news-manage ├── add.phtml ├── edit.phtml ├── editx.phtml └── index.phtml9 directories, 7 files
root@coder-671T-M:/mydev_src/zend_framework_learn/www/zf_demo2# zf.sh create module testmodCreating the following module and artifacts:/mydev_src/zend_framework_learn/www/zf_demo2/application/modules/testmod/controllers/mydev_src/zend_framework_learn/www/zf_demo2/application/modules/testmod/models/mydev_src/zend_framework_learn/www/zf_demo2/application/modules/testmod/views/mydev_src/zend_framework_learn/www/zf_demo2/application/modules/testmod/views/scripts/mydev_src/zend_framework_learn/www/zf_demo2/application/modules/testmod/views/helpers/mydev_src/zend_framework_learn/www/zf_demo2/application/modules/testmod/views/filtersAdded a key for path module directory to the application.ini fileUpdating project profile '/mydev_src/zend_framework_learn/www/zf_demo2/.zfproject.xml'配置文件中增加了
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
zf create form name module
為指定模塊創(chuàng)建Form
root@coder-671T-M:/mydev_src/zend_framework_learn/www/zf_demo2# zf.sh create form testForm testmodCreating a form at /mydev_src/zend_framework_learn/www/zf_demo2/application/modules/testmod/forms/TestForm.phpUpdating project profile '/mydev_src/zend_framework_learn/www/zf_demo2/.zfproject.xml'
/zf_demo2/application/modules/testmod/forms/TestForm.php
<?phpclass Testmod_Form_TestForm extends Zend_Form{ public function init() { /* Form Elements & Other Definitions Here ... */ }}
root@coder-671T-M:/mydev_src/zend_framework_learn/www/zf_demo2# zf.sh create form testForm
Creating a form at /mydev_src/zend_framework_learn/www/zf_demo2/application/forms/TestForm.php
Updating project profile '/mydev_src/zend_framework_learn/www/zf_demo2/.zfproject.xml'
/zf_demo2/application/forms/TestForm.php
<?phpclass Application_Form_TestForm extends Zend_Form{ public function init() { /* Form Elements & Other Definitions Here ... */ }}
Layout配置layout
zf enable layoutroot@coder-671T-M:/mydev_src/zend_framework_learn/www/zf_demo2# zf.sh enable layoutA layout entry has been added to the application config file.A default layout has been created at /mydev_src/zend_framework_learn/www/zf_demo2/application/layouts/scripts/layout.phtmlUpdating project profile '/mydev_src/zend_framework_learn/www/zf_demo2/.zfproject.xml'
/zf_demo2/application/layouts/scripts/layout.phtml
<?php echo $this->layout()->content; ?>
zf configure db-adapter dsn section-name[=production]
root@coder-671T-M:/mydev_src/zend_framework_learn/www/zf_demo2# zf.sh configure db-adapter "adapter=Mysqli&username=uname&password=mypass&dbname=mydb"
A db configuration for the production section has been written to the application config file.
resources.db.adapter = "Mysqli"resources.db.params.username = "uname"resources.db.params.password = "mypass"resources.db.params.dbname = "mydb"
es# tree.└── testmod ├── controllers │ └── NewsManageController.php ├── forms │ └── TestForm.php ├── models │ ├── DbTable │ │ └── TblUser.php │ └── MyModel.php └── views
<?phpclass Testmod_Model_DbTable_TblUser extends Zend_Db_Table_Abstract{ protected $_name = 'tbl_user';}
以上是zendframework提供的命令工具,可以根據(jù)需要使用,使用命令行要確保所有的東西都是用命令行完成的,因為命令行的運行是通過記錄在配置文件中完成的,如果手動加入一些功能,命令行就無法進行正確的運行了。