Simple examples of Model usage in ZendFramework tutorial

Source: Internet
Author: User
Tags zend framework
This document describes the Model usage in the ZendFramework tutorial. For your reference, refer to the following example: 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 │ examples-. settings │ org.

This document describes the Model usage in the Zend Framework tutorial. For your reference, refer to the following example: 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 │ examples-. settings │ org.

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.