多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php框架 > ZendFramework > Zend Framework教程-Zend_Application_Module-Zend Framework 多模塊支持

Zend Framework教程-Zend_Application_Module-Zend Framework 多模塊支持

來源:程序員人生   發布時間:2013-10-10 19:11:56 閱讀次數:3769次


用zend studio或者zf命令創建module_demo1項目。執行如下命令,添加user,blog,picture模塊。



/www/module_demo1>zf create module userCreating the following module and artifacts:/www/module_demo1/application/modules/user/controllers/www/module_demo1/application/modules/user/models/www/module_demo1/application/modules/user/views/www/module_demo1/application/modules/user/views/scripts/www/module_demo1/application/modules/user/views/helpers/www/module_demo1/application/modules/user/views/filtersAdded a key for path module directory to the application.ini fileUpdating project profile '/www/module_demo1/.zfproject.xml'/www/module_demo1>zf create module blogCreating the following module and artifacts:/www/module_demo1/application/modules/blog/controllers/www/module_demo1/application/modules/blog/models/www/module_demo1/application/modules/blog/views/www/module_demo1/application/modules/blog/views/scripts/www/module_demo1/application/modules/blog/views/helpers/www/module_demo1/application/modules/blog/views/filtersAdded a key for path module directory to the application.ini fileUpdating project profile '/www/module_demo1/.zfproject.xml'/www/module_demo1>zf create module pictureCreating the following module and artifacts:/www/module_demo1/application/modules/picture/controllers/www/module_demo1/application/modules/picture/models/www/module_demo1/application/modules/picture/views/www/module_demo1/application/modules/picture/views/scripts/www/module_demo1/application/modules/picture/views/helpers/www/module_demo1/application/modules/picture/views/filtersAdded a key for path module directory to the application.ini fileUpdating project profile '/www/module_demo1/.zfproject.xml'




我們創建了user,blog,picture三個模塊。項目結構如下:

│  .buildpath│  .project│  .zfproject.xml│├─.settings│      .jsdtscope│      org.eclipse.php.core.prefs│      org.eclipse.wst.jsdt.ui.superType.container│      org.eclipse.wst.jsdt.ui.superType.name│├─application│  │  Bootstrap.php│  ││  ├─configs│  │      application.ini│  ││  ├─controllers│  │      ErrorController.php│  │      IndexController.php│  ││  ├─models│  ├─modules│  │  ├─blog│  │  │  ├─controllers│  │  │  ├─models│  │  │  └─views│  │  │      ├─filters│  │  │      ├─helpers│  │  │      └─scripts│  │  ├─picture│  │  │  ├─controllers│  │  │  ├─models│  │  │  └─views│  │  │      ├─filters│  │  │      ├─helpers│  │  │      └─scripts│  │  └─user│  │      ├─controllers│  │      ├─models│  │      └─views│  │          ├─filters│  │          ├─helpers│  │          └─scripts│  └─views│      ├─helpers│      └─scripts│          ├─error│          │      error.phtml│          ││          └─index│                  index.phtml│├─docs│      README.txt│├─library├─public│      .htaccess│      index.php│└─tests   │  bootstrap.php   │  phpunit.xml   │   ├─application   │  └─controllers   │          IndexControllerTest.php   │   └─library



執行如下命令,創建為各個模塊創建一個IndexController。
/www/module_demo1> zf create controller user index-action-included[=1] user
/www/module_demo1> zf create controller index index-action-included[=1] blog
/www/module_demo1> zf create controller index index-action-included[=1] picture


結構如下:


│  │      application.ini│  ││  ├─controllers│  │      ErrorController.php│  │      IndexController.php│  ││  ├─models│  ├─modules│  │  ├─blog│  │  │  ├─controllers│  │  │  │      IndexController.php│  │  │  ││  │  │  ├─models│  │  │  └─views│  │  │      ├─filters│  │  │      ├─helpers│  │  │      └─scripts│  │  │          └─index│  │  │                  index.phtml│  │  ││  │  ├─picture│  │  │  ├─controllers│  │  │  │      IndexController.php│  │  │  ││  │  │  ├─models│  │  │  └─views│  │  │      ├─filters│  │  │      ├─helpers│  │  │      └─scripts│  │  │          └─index│  │  │                  index.phtml│  │  ││  │  └─user│  │      ├─controllers│  │      │      UserController.php│  │      ││  │      ├─models│  │      └─views│  │          ├─filters│  │          ├─helpers│  │          └─scripts│  │              └─index│  │                      index.phtml│  ││  └─views│      ├─helpers│      └─scripts│          ├─error│          │      error.phtml│          ││          └─index│                  index.phtml│├─docs




模塊的Controller的結構如下:
以/module_demo1/application/modules/blog/controllers/IndexController.php為例
類名為模塊名稱_控制器名稱即:Blog_IndexController。如下:
<?phpclass Blog_IndexController extends Zend_Controller_Action{    public function init()    {        /* Initialize action controller here */    }    public function indexAction()    {        // action body    }}



這樣,一個簡單的模塊就創建完成了。

可以通過訪問

http://www.localzend.com/module_demo1/public/blog/index/index

來訪問blog模塊的index控制器的index Action。



多模塊的Model支持


以user模塊為例。

│  │  ││  │  └─user│  │      │  Bootstrap.php│  │      ││  │      ├─controllers│  │      │      IndexController.php│  │      ││  │      ├─models│  │      │      MUser.php│  │      ││  │      └─views│  │          ├─filters│  │          ├─helpers│  │          └─scripts│  │              └─index│  │                      index.phtml


/module_demo1/application/modules/user/models/MUser.php

在user模塊的models新建一個MUser.php文件。內容規則如下:


<?phpclass  User_Model_MUser {		public function getUserById() {		return array (				'username' => 'zhangsan',				'id' => '1' 		);	}}

格式要求如下:

模塊名_Model_模型類名


調用方法如下:

<?phpclass User_IndexController extends Zend_Controller_Action{	private $_user = null;    public function init()    {       $this->_user = new User_Model_MUser();       /* Initialize action controller here */    }    public function indexAction()    {        $this->view->assign('user',$this->_user->getUserById());    }}


/module_demo1/application/modules/user/views/scripts/index/index.phtml


<br /><br /><div id="view-content">	<p>View script for controller <b>Index</b> and script/action name <b>index</b></p>	<p>		<?php 		var_dump($this->user);		?>	</p></div>



總結:實現zend framework支持多模塊的方法如下:


1.配置文件

/module_demo1/application/configs/application.ini


[production]phpSettings.display_startup_errors = 1phpSettings.display_errors = 1includePaths.library = APPLICATION_PATH "/../library"bootstrap.path = APPLICATION_PATH "/Bootstrap.php"bootstrap.class = "Bootstrap"appnamespace = "Application"resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"resources.frontController.params.displayExceptions = 1resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"resources.modules[] =[staging : production]

重要的兩行

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"resources.modules[] =


2.各模塊放在配置文件中指定的模塊存放目錄。默認是/module_demo1/application/modules


3.各模塊的基本結構如下:

│  │  │
│  │  └─user
│  │      │  Bootstrap.php
│  │      │
│  │      ├─controllers
│  │      │      IndexController.php
│  │      │
│  │      ├─models
│  │      │      MUser.php
│  │      │
│  │      └─views
│  │          ├─filters
│  │          ├─helpers
│  │          └─scripts
│  │              └─index
│  │                      index.phtml


4.模塊的Bootstrap.php內容如下:

<?phpclass User_Bootstrap extends Zend_Application_Module_Bootstrap {	}

5.各模塊的models用來存放模型

模型的定義如下

模塊名_Model_模型類名

6.控制器的定義如下:

<?phpclass User_IndexController extends Zend_Controller_Action{	private $_user = null;    public function init()    {       $this->_user = new User_Model_MUser();       /* Initialize action controller here */    }    public function indexAction()    {        $this->view->assign('user',$this->_user->getUserById());    }}

模塊名_控制器名稱Contrller

 

7.調用模型。只需按照模型定義的類名使用即可。






生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 在线看欧美成人中文字幕视频 | 亚洲精品在线视频观看 | 九一精品| 福利视频一区二区微拍堂 | 久久成人精品免费播放 | 伊人久爱| 色人阁网站 | 日本www在线视频 | 美女被h | xxfree性欧美hd | 最近中文字幕国语免费高清6 | 久久r这里只有精品 | 非洲黑人最猛性xxxx交 | 福利视频播放 | 精品一区国产 | 性欧美f| 日本特黄一级片 | 欧美非洲黑人性xxxx | 国产免费一区二区三区 | 亚洲综合国产精品 | 手机看片国产 | 奇奇网免费影视片 | 视频三区精品中文字幕 | 日韩 欧美 国产 亚洲 中文 | 欧美xxxvideo| 亚a在线| 亚洲精品二区 | 亚洲视频中文字幕在线观看 | 青春草久久 | 中文无码日韩欧免费视频 | 欧美日韩免费一区二区三区 | 国产在线h | 亚洲视频免费看 | 久久国内精品 | 久久国产精品影院 | jizz国产精品jizz中国 | 欧美亚洲精品一区 | 在线观看视频高清视频 | 免费观看美女的网站 | 中文字幕最新 | 中文字幕国产欧美 |