This example describes the model usage of the Zend Framework tutorial. Share to everyone for your reference, specific as follows:
A simple and vulgar example is attached. Just probably explain the usage: if you want to delve into, you can follow the source of their own understanding.
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 from top to bottom, the source of each file, no longer detailed description:
/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 CONTR
Oller 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 ' =&G T
' 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 ' => ' John ',
' user_gender ' => ' man '
);
}
/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/> ';
}
}
The code that is not posted is the default code for creating the project.
Remember: Follow the rules of engagement and avoid unnecessary hassles.
More interested in Zend related content readers can view the site topics: "The introduction of the Zend Framework frame", "PHP Excellent Development Framework Summary", "Yii framework Introduction and common skills Summary", "thinkphp Introductory Course", "PHP object-oriented Programming Program , "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation Skills Summary"
I hope this article will help you with the PHP program design.