本文实例讲述了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
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;">
'/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
PHP;">
PHP
class Model_ModelTest{
static function echoModelModelTest(){
echo 'Model_ModelTest
';
}
}
/model_demo1/application/models/Test.PHP
PHP;">
'张三','user_gender' => '男'
);
}
}
/model_demo1/application/Bootstrap.PHP
PHP;">
getApplication ();
$namespaces = array (
'AppTest'
);
$app->setAutoloaderNamespaces ( $namespaces );
return $app;
}
}
/model_demo1/library/app/Test.PHP
PHP;">
PHP
class App_Test {
static public function echoAppTest() {
echo 'App_Test
';
}
}
/model_demo1/library/AppTest/Test.PHP
PHP;">
PHP
class AppTest_Test{
static public function echoAppTestTest(){
echo 'AppTestTest
';
}
}
/model_demo1/library/AppTest2/Test.PHP
PHP;">
PHP
class AppTest2_Test{
static public function echoAppTest2Test(){
echo 'AppTest2Test
';
}
}
/model_demo1/library/myApp/Test.PHP
PHP;">
PHP
class MyApp_Test {
static public function echoAMyAppTest() {
echo 'MyApp_Test
';
}
}
/model_demo1/library/Zend/Test.PHP
PHP;">
PHP
class Zend_Test{
static public function echoZendTest(){
echo 'ZendTest
';
}
}
没有贴出的代码,是创建项目默认的代码。
记住:遵循约定规则,就会避免不必要的麻烦。
更多关于zend相关内容感兴趣的读者可查看本站专题:《》、《》、《》、《》、《》、《》及《PHP常见数据库操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。