日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

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

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

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


用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.調用模型。只需按照模型定義的類名使用即可。






生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 日韩一级 | 亚洲视频久久 | 久久免费小视频 | 亚洲va中文字幕 | 国产在线视频一区二区 | 青青草天堂 | 日韩精品一区二区三区在线 | 中国黄色片网站 | 精品999久久久 | 国产精品久久久久9999 | 欧美日韩国产一区二区三区 | 国产一二区在线观看 | 欧美视频一区 | 国产精品一区二区无线 | 爱爱视频在线免费观看 | 操人视频| 插插网站| 久久久久久久久久久久久久久久久久久久 | 亚洲三级国产 | 成年人免费网站 | 亚洲精品视频在线 | 爱爱视频在线播放 | 天堂精品一区 | 久久国产一区 | 波多野结衣电影久久 | 亚洲高清视频在线观看 | 九九精品在线观看 | 欧美国产精品一区二区三区 | 亚洲综合影院 | 免费黄视频网站 | 日韩在线播放视频 | 成人在线视频一区 | 日韩写真福利视频在线 | 免费91视频 | 久久国产精品一区二区三区 | 亚洲成人久久久 | 精品一区二区三区在线播放 | 成人性爱视频在线观看 | 久久视频一区二区 | 一区二区三区在线播放 | 欧美一区二区三区白人 |