A simple example of ZendFramework Model usage in the zendframework tutorial. A simple example of ZendFramework Model usage in the zendframework tutorial. This document describes the Model usage in the ZendFramework tutorial. For your reference, refer to the simple Model usage example in the Zend Framework tutorial.
This document describes the Model usage in the Zend Framework tutorial. We will share this with you for your reference. The details are as follows:
A simple and vulgar example is provided. It just illustrates the usage: If you want to learn more, you can track the source code.
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
│
Deletests
│ Phpunit. xml
│ Bootstrap. php
│
├ ── Application
│ └ ── Controllers
│ IndexControllerTest. php
│
└-Library
The source code of each file from top to bottom is not described in detail as follows:
/Model_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"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 = 1phpSettings.display_errors = 1[development : production]phpSettings.display_startup_errors = 1phpSettings.display_errors = 1resources.frontController.params.displayExceptions = 1
/Model_demo1/application/controllers/IndexController. php
<?phpclass 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
<?phpclass Model_ModelTest{ static function echoModelModelTest(){ echo 'Model_ModelTest
'; }}
/Model_demo1/application/models/Test. php
<? Phpclass Application_Model_Test {static public function getUserInfo () {return array ('User _ name' => 'Zhang San', 'User _ gender' => 'mal ');}}
/Model_demo1/application/Bootstrap. php
<?phpclass 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
<?phpclass App_Test { static public function echoAppTest() { echo 'App_Test
'; }}
/Model_demo1/library/AppTest/Test. php
<?phpclass AppTest_Test{ static public function echoAppTestTest(){ echo 'AppTestTest
'; }}
/Model_demo1/library/AppTest2/Test. php
<?phpclass AppTest2_Test{ static public function echoAppTest2Test(){ echo 'AppTest2Test
'; }}
/Model_demo1/library/myApp/Test. php
<?phpclass MyApp_Test { static public function echoAMyAppTest() { echo 'MyApp_Test
'; }}
/Model_demo1/library/Zend/Test. php
<?phpclass Zend_Test{ static public function echoZendTest(){ echo 'ZendTest
'; }}
The code that is not pasted is the default code for creating a project.
Remember: following the agreed rules will avoid unnecessary troubles.