简单介绍Zend_Amf 与 Flex
实现数据库的操作。flex前端初始化的时候调用getAStudent()方法,该方法驱动mainService下的getAStudent()方
法,后台该方法通过Jd_Model_Student,构建Student对象,并调用其getAStudent()方法,返回数组到
mainService,传输到前端。前端获取到返回数据后,onStudentGot()方法被调用,Alert id为1的学生的name。 在看篇文章前,确定你已经看了这篇文章zend_amf flex前端开发 Hello world 。 1. 数据库的构建 2.application.ini配置 [production] phpSettings.display_startup_errors = 0 phpSettings.display_errors = 0 includePaths.library = APPLICATION_PATH "/../library" bootstrap.path = APPLICATION_PATH "/Bootstrap.php" bootstrap.class = "Bootstrap" resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers" ;database resources.db.adapter = "PDO_MYSQL" resources.db.isdefaulttableadapter = true resources.db.params.driver_options.1002 = "SET NAMES UTF8;" resources.db.params.host = localhost resources.db.params.username = root resources.db.params.password = resources.db.params.dbname = school [staging : production] [testing : production] phpSettings.display_startup_errors = 1 phpSettings.display_errors = 1 [development : production] phpSettings.display_startup_errors = 1 phpSettings.display_errors = 1 3.bootstrap.php文件 <?php class Bootstrap extends Zend_Application_Bootstrap_Bootstrap { public function _initDb(){ $dbAdapter = $this->getPluginResource('db')->init(); Zend_Registry::set('dbAdapter',$dbAdapter); } public function _initAutoLoader(){ $autoloader = new Zend_Application_Module_Autoloader( array( 'namespace' => 'Jd', 'basePath' => realpath(dirname(__FILE__)) ) ); return $autoloader; } } 4.MainService.php文件 <?php class MainService{ public function getAStudent($id){ $student = new Jd_Model_Student(); return $student->getAStudent($id); } } 5. Studeng.php文件 <?php class Jd_Model_Student extends Zend_Db_Table{ protected $_name = "student"; public function getAStudeng($id){ $select = $this->select(); $select->where("id = ?", $id); return $this->fetchRow($select)->toArray(); } } 6.前端代码 <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="getAStudent(1)"> <mx:RemoteObject id="mainService" destination="zend_amf" source="MainService"> <mx:method name="getAStudent" result="onStudentGot()" fault="onFault(event)" /> </mx:RemoteObject> <mx:Script> <![CDATA[ import mx.rpc.events.FaultEvent; import mx.controls.Alert; import mx.collections.*; private function getAStudent(id:int):void{ mainService.getAStudent(id); } private function onStudentGot():void{ var student:Array = new Array(); student = mainService.getADoc.lastResult; Alert.show(student['name']); } ]]> </mx:Script> </mx:Application> |
|