首页 php教程 PHP开发 Zend Framework教程之模型Model用法简单实例

Zend Framework教程之模型Model用法简单实例

Jan 03, 2017 pm 01:42 PM

本文实例讲述了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(
        &#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 ();
  }
}
登录后复制

/model_demo1/application/models/ModelTest.php

<?php
class Model_ModelTest{
  static function echoModelModelTest(){
    echo &#39;Model_ModelTest<br/>&#39;;
  }
}
登录后复制

/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;
    );
  }
}
登录后复制

/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;
  }
}
登录后复制

/model_demo1/library/app/Test.php

<?php
class App_Test {
  static public function echoAppTest() {
    echo &#39;App_Test<br/>&#39;;
  }
}
登录后复制

/model_demo1/library/AppTest/Test.php

<?php
class AppTest_Test{
  static public function echoAppTestTest(){
    echo &#39;AppTestTest<br/>&#39;;
  }
}
登录后复制

/model_demo1/library/AppTest2/Test.php

<?php
class AppTest2_Test{
  static public function echoAppTest2Test(){
    echo &#39;AppTest2Test<br/>&#39;;
  }
}
登录后复制

/model_demo1/library/myApp/Test.php

<?php
class MyApp_Test {
  static public function echoAMyAppTest() {
    echo &#39;MyApp_Test<br/>&#39;;
  }
}
登录后复制

/model_demo1/library/Zend/Test.php

<?php
class Zend_Test{
  static public function echoZendTest(){
    echo &#39;ZendTest<br/>&#39;;
  }
}
登录后复制

没有贴出的代码,是创建项目默认的代码。

记住:遵循约定规则,就会避免不必要的麻烦。

希望本文所述对大家PHP程序设计有所帮助。

更多Zend Framework教程之模型Model用法简单实例相关文章请关注PHP中文网!

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

<🎜>:泡泡胶模拟器无穷大 - 如何获取和使用皇家钥匙
4 周前 By 尊渡假赌尊渡假赌尊渡假赌
北端:融合系统,解释
4 周前 By 尊渡假赌尊渡假赌尊渡假赌
Mandragora:巫婆树的耳语 - 如何解锁抓钩
3 周前 By 尊渡假赌尊渡假赌尊渡假赌

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

热门话题

Java教程
1670
14
CakePHP 教程
1428
52
Laravel 教程
1329
25
PHP教程
1276
29
C# 教程
1256
24