Zend Framework教程之模型Model用法簡單實(shí)例
本文實(shí)例講述了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
如下是從上到下,每一個文件的源碼,不再詳細(xì)說明:
/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(
'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
<?php
class Model_ModelTest{
static function echoModelModelTest(){
echo 'Model_ModelTest<br/>';
}
}
/model_demo1/application/models/Test.php
<?php
class Application_Model_Test {
static public function getUserInfo() {
return array (
'user_name' => '張三',
'user_gender' => '男'
);
}
}
/model_demo1/application/Bootstrap.php
<?php
class 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
<?php
class App_Test {
static public function echoAppTest() {
echo 'App_Test<br/>';
}
}
/model_demo1/library/AppTest/Test.php
<?php
class AppTest_Test{
static public function echoAppTestTest(){
echo 'AppTestTest<br/>';
}
}
/model_demo1/library/AppTest2/Test.php
<?php
class AppTest2_Test{
static public function echoAppTest2Test(){
echo 'AppTest2Test<br/>';
}
}
/model_demo1/library/myApp/Test.php
<?php
class MyApp_Test {
static public function echoAMyAppTest() {
echo 'MyApp_Test<br/>';
}
}
/model_demo1/library/Zend/Test.php
<?php
class Zend_Test{
static public function echoZendTest(){
echo 'ZendTest<br/>';
}
}
沒有貼出的代碼,是創(chuàng)建項(xiàng)目默認(rèn)的代碼。
記?。鹤裱s定規(guī)則,就會避免不必要的麻煩。
更多關(guān)于zend相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Zend FrameWork框架入門教程》、《php優(yōu)秀開發(fā)框架總結(jié)》、《Yii框架入門及常用技巧總結(jié)》、《ThinkPHP入門教程》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家PHP程序設(shè)計(jì)有所幫助。
- Zend Framework教程之Resource Autoloading用法實(shí)例
- Zend Framework教程之MVC框架的Controller用法分析
- Zend Framework教程之路由功能Zend_Controller_Router詳解
- Zend Framework教程之Zend_Controller_Plugin插件用法詳解
- Zend Framework教程之響應(yīng)對象的封裝Zend_Controller_Response實(shí)例詳解
- Zend Framework教程之請求對象的封裝Zend_Controller_Request實(shí)例詳解
- Zend Framework教程之動作的基類Zend_Controller_Action詳解
- Zend Framework教程之分發(fā)器Zend_Controller_Dispatcher用法詳解
- Zend Framework教程之前端控制器Zend_Controller_Front用法詳解
- Zend Framework教程之視圖組件Zend_View用法詳解
- Zend Framework教程之Autoloading用法詳解
相關(guān)文章
php ajax數(shù)據(jù)傳輸和響應(yīng)方法
今天小編就為大家分享一篇php ajax數(shù)據(jù)傳輸和響應(yīng)方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-08-08
PHP加密3DES報(bào)錯 Call to undefined function: mcrypt_module_open()
這篇文章主要介紹了PHP加密3DES報(bào)錯 Call to undefined function: mcrypt_module_open() 如何解決的相關(guān)資料,需要的朋友可以參考下2016-04-04
mysql alter table命令修改表結(jié)構(gòu)實(shí)例詳解
這篇文章主要介紹了mysql alter table命令修改表結(jié)構(gòu)實(shí)例的相關(guān)資料,需要的朋友可以參考下2016-09-09
php版微信開發(fā)Token驗(yàn)證失敗或請求URL超時問題的解決方法
這篇文章主要介紹了php版微信開發(fā)Token驗(yàn)證失敗或請求URL超時問題的解決方法,簡單分析了Token驗(yàn)證失敗及請求URL超時的原因及相關(guān)解決方法,需要的朋友可以參考下2016-09-09
thinkPHP統(tǒng)計(jì)排行與分頁顯示功能示例
這篇文章主要介紹了thinkPHP統(tǒng)計(jì)排行與分頁顯示功能,結(jié)合實(shí)例形式分析了thinkPHP數(shù)據(jù)庫查詢與結(jié)果分頁顯示相關(guān)操作技巧,需要的朋友可以參考下2016-12-12

