Home php教程 PHP开发 Simple example of model usage in Zend Framework tutorial

Simple example of model usage in Zend Framework tutorial

Jan 03, 2017 pm 01:42 PM

The example in 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
│                                                                                     │        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

<?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(
        &#39;basePath&#39; => &#39;/www/model_demo1/application&#39;,
        &#39;namespace&#39; => &#39;&#39;,
        &#39;resourceTypes&#39; => array(
            &#39;model&#39; => array(
                &#39;path&#39; => &#39;models&#39;,
                &#39;namespace&#39; => &#39;Model&#39;
            )
        )
    )
    );
    $auto_loader->pushAutoloader($resourceLoader);
    $auto_loader->registerNamespace(array(&#39;AppTest2_&#39;));
    AppTest2_Test::echoAppTest2Test();
    Model_ModelTest::echoModelModelTest();
    exit ();
  }
}
Copy after login

/model_demo1/application/models/ModelTest.php

<?php
class Model_ModelTest{
  static function echoModelModelTest(){
    echo &#39;Model_ModelTest<br/>&#39;;
  }
}
Copy after login

/model_demo1/application/models/Test.php

<?php
class Application_Model_Test {
  static public function getUserInfo() {
    return array (
        &#39;user_name&#39; => &#39;张三&#39;,
        &#39;user_gender&#39; => &#39;男&#39;
    );
  }
}
Copy after login

/model_demo1/application/Bootstrap.php

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

/model_demo1/library/app/Test.php

<?php
class App_Test {
  static public function echoAppTest() {
    echo &#39;App_Test<br/>&#39;;
  }
}
Copy after login

/model_demo1/library/AppTest/Test.php

<?php
class AppTest_Test{
  static public function echoAppTestTest(){
    echo &#39;AppTestTest<br/>&#39;;
  }
}
Copy after login

/model_demo1/library/AppTest2/Test.php

<?php
class AppTest2_Test{
  static public function echoAppTest2Test(){
    echo &#39;AppTest2Test<br/>&#39;;
  }
}
Copy after login

/model_demo1/library/myApp/Test.php

<?php
class MyApp_Test {
  static public function echoAMyAppTest() {
    echo &#39;MyApp_Test<br/>&#39;;
  }
}
Copy after login

/model_demo1/library/Zend/Test.php

<?php
class Zend_Test{
  static public function echoZendTest(){
    echo &#39;ZendTest<br/>&#39;;
  }
}
Copy after login

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

Remember: following the agreed rules will avoid unnecessary trouble.

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

For more articles related to simple examples of model usage in the Zend Framework tutorial, please pay attention to the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1669
14
PHP Tutorial
1273
29
C# Tutorial
1256
24