Simple example of model usage in Zend Framework tutorial, zendframework_PHP tutorial

WBOY
Release: 2016-07-12 08:57:57
Original
869 people have browsed it

A simple example of model usage in Zend Framework tutorial, zendframework

This article describes the usage of model in Zend Framework tutorial. Share it with everyone for your reference, the details are as follows:

Attached is a simple and vulgar example. It just briefly explains the usage: if you want to dig deeper, you can track the source code yourself to understand.

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

The following is the source code of each file from top to bottom, without further explanation:

/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

Copy after login

/model_demo1/application/controllers/IndexController.php

<&#63;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 ();
  }
}

Copy after login

/model_demo1/application/models/ModelTest.php

<&#63;php
class Model_ModelTest{
  static function echoModelModelTest(){
    echo 'Model_ModelTest<br/>';
  }
}

Copy after login

/model_demo1/application/models/Test.php

<&#63;php
class Application_Model_Test {
  static public function getUserInfo() {
    return array (
        'user_name' => '张三',
        'user_gender' => '男'
    );
  }
}

Copy after login

/model_demo1/application/Bootstrap.php

<&#63;php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
  protected function _initAutoload() {
    $app = $this->getApplication ();
    $namespaces = array (
        'AppTest'
    );
    $app->setAutoloaderNamespaces ( $namespaces );
    return $app;
  }
}

Copy after login

/model_demo1/library/app/Test.php

<&#63;php
class App_Test {
  static public function echoAppTest() {
    echo 'App_Test<br/>';
  }
}

Copy after login

/model_demo1/library/AppTest/Test.php

<&#63;php
class AppTest_Test{
  static public function echoAppTestTest(){
    echo 'AppTestTest<br/>';
  }
}

Copy after login

/model_demo1/library/AppTest2/Test.php

<&#63;php
class AppTest2_Test{
  static public function echoAppTest2Test(){
    echo 'AppTest2Test<br/>';
  }
}

Copy after login

/model_demo1/library/myApp/Test.php

<&#63;php
class MyApp_Test {
  static public function echoAMyAppTest() {
    echo 'MyApp_Test<br/>';
  }
}

Copy after login

/model_demo1/library/Zend/Test.php

<&#63;php
class Zend_Test{
  static public function echoZendTest(){
    echo 'ZendTest<br/>';
  }
}

Copy after login

The code that is not posted is the default code for creating a project.

Remember: following the agreed rules will avoid unnecessary trouble.

Readers who are interested in more zend-related content can check out the special topics of this site: "Zend FrameWork Framework Introductory Tutorial", "php Excellent Development Framework Summary", "Yii Framework Introduction and Summary of Common Techniques", "ThinkPHP Introductory Tutorial" , "php object-oriented programming introductory tutorial", "php mysql database operation introductory tutorial" and "php common database operation skills summary"

I hope this article will be helpful to everyone in PHP programming.

Articles you may be interested in:

  • Zend Framework Tutorial: Basic Model Rules and Usage Methods
  • Zend Framework Tutorial: Zend_Layout Layout Assistant Detailed Explanation
  • How to use memcache in zend framework
  • Solution to the url case problem in zend framework
  • Zend Framework 2.0 Event Manager (The EventManager) introductory tutorial
  • Zend Framework page Cache instance
  • Very useful Zend Framework paging class
  • Detailed explanation of Layout (modular layout) in zend Framework
  • Zend framework configuration operation database instance analysis
  • Zendframework project environment construction under windows (configuration through command line)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1106111.htmlTechArticleA simple example of model usage in Zend Framework tutorial, zendframework This example describes the usage of model in Zend Framework tutorial. Share it with everyone for your reference, the details are as follows:...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!