Zend Framework教程之模型Model用法简单实例
本文实例讲述了zend framework教程之模型model用法。分享给大家供大家参考,具体如下:
附一个简单粗俗的例子。只是大概说明了用法:如果要深究,可以自己跟踪源码了解。
model_demo1
│ .project
│ .buildpath
│ .zfproject.xml
│
├─.settings
│ org.eclipse.php.core.prefs
│ .jsdtscope
│ org.eclipse.wst.jsdt.ui.supertype.name
│ org.eclipse.wst.jsdt.ui.supertype.container
│
├─application
│ │ bootstrap.php
│ │
│ ├─configs
│ │ application.ini
│ │
│ ├─controllers
│ │ indexcontroller.php
│ │ errorcontroller.php
│ │
│ ├─models
│ │ test.php
│ │ modeltest.php
│ │
│ └─views
│ ├─scripts
│ │ ├─index
│ │ │ index.phtml
│ │ │
│ │ └─error
│ │ error.phtml
│ │
│ └─helpers
├─docs
│ readme.txt
│
├─library
│ ├─app
│ │ test.php
│ │
│ ├─myapp
│ │ test.php
│ │
│ ├─zend
│ │ test.php
│ │
│ ├─apptest
│ │ test.php
│ │
│ └─apptest2
│ test.php
│
├─public
│ index.php
│ .htaccess
│
└─tests
│ phpunit.xml
│ bootstrap.php
│
├─application
│ └─controllers
│ indexcontrollertest.php
│
└─library
如下是从上到下,每一个文件的源码,不再详细说明:
/model_demo1/application/configs/application.ini
[production] phpsettings.display_startup_errors = 1 phpsettings.display_errors = 1 includepaths.library = application_path "/../library" bootstrap.path = application_path "/bootstrap.php" bootstrap.class = "bootstrap" appnamespace = "application" autoloadernamespaces.app = "app_" autoloadernamespaces.my = "myapp_" resources.frontcontroller.controllerdirectory = application_path "/controllers" resources.frontcontroller.params.displayexceptions = 1 [staging : production] [testing : production] phpsettings.display_startup_errors = 1 phpsettings.display_errors = 1 [development : production] phpsettings.display_startup_errors = 1 phpsettings.display_errors = 1 resources.frontcontroller.params.displayexceptions = 1
/model_demo1/application/controllers/indexcontroller.php
<?php class indexcontroller extends zend_controller_action { public function init() { /* initialize action controller here */ } public function indexaction() { var_dump ( application_model_test::getuserinfo () ); app_test::echoapptest (); myapp_test::echoamyapptest (); zend_test::echozendtest (); apptest_test::echoapptesttest (); $auto_loader = zend_loader_autoloader::getinstance(); $resourceloader = new zend_loader_autoloader_resource(array( 'basepath' => '/www/model_demo1/application', 'namespace' => '', 'resourcetypes' => array( 'model' => array( 'path' => 'models', 'namespace' => 'model' ) ) ) ); $auto_loader->pushautoloader($resourceloader); $auto_loader->registernamespace(array('apptest2_')); apptest2_test::echoapptest2test(); model_modeltest::echomodelmodeltest(); exit (); } }
/model_demo1/application/models/modeltest.php
<?php class model_modeltest{ static function echomodelmodeltest(){ echo 'model_modeltest<br/>'; } }
/model_demo1/application/models/test.php
<?php class application_model_test { static public function getuserinfo() { return array ( 'user_name' => '张三', 'user_gender' => '男' ); } }
/model_demo1/application/bootstrap.php
<?php class bootstrap extends zend_application_bootstrap_bootstrap { protected function _initautoload() { $app = $this->getapplication (); $namespaces = array ( 'apptest' ); $app->setautoloadernamespaces ( $namespaces ); return $app; } }
/model_demo1/library/app/test.php
<?php class app_test { static public function echoapptest() { echo 'app_test<br/>'; } }
/model_demo1/library/apptest/test.php
<?php class apptest_test{ static public function echoapptesttest(){ echo 'apptesttest<br/>'; } }
/model_demo1/library/apptest2/test.php
<?php class apptest2_test{ static public function echoapptest2test(){ echo 'apptest2test<br/>'; } }
/model_demo1/library/myapp/test.php
<?php class myapp_test { static public function echoamyapptest() { echo 'myapp_test<br/>'; } }
/model_demo1/library/zend/test.php
<?php class zend_test{ static public function echozendtest(){ echo 'zendtest<br/>'; } }
没有贴出的代码,是创建项目默认的代码。
记住:遵循约定规则,就会避免不必要的麻烦。
更多关于zend相关内容感兴趣的读者可查看本站专题:《zend framework框架入门教程》、《php优秀开发框架总结》、《yii框架入门及常用技巧总结》、《thinkphp入门教程》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家php程序设计有所帮助。
推荐阅读
-
Zend Framework教程之模型Model用法简单实例
-
Zend Framework教程之模型Model基本规则和使用方法
-
Zend Framework框架教程之Zend_Db_Table_Rowset用法实例分析_php实例
-
Zend Framework教程之Application用法实例详解_php实例
-
Zend Framework教程之资源(Resources)用法实例详解,zendframework_PHP教程
-
Zend Framework教程之Loader以及PluginLoader用法详解_php实例
-
Zend Framework教程之分发器Zend_Controller_Dispatcher用法详解_php实例
-
Zend Framework教程之模型Model基本规则和使用方法,zendframework_PHP教程
-
Zend Framework教程之Autoloading用法详解_php实例
-
Zend Framework教程之前端控制器Zend_Controller_Front用法详解_php实例