Zend Framework MVC设计模式.pdf

上传人:asd****56 文档编号:69684720 上传时间:2023-01-07 格式:PDF 页数:18 大小:282.21KB
返回 下载 相关 举报
Zend Framework MVC设计模式.pdf_第1页
第1页 / 共18页
Zend Framework MVC设计模式.pdf_第2页
第2页 / 共18页
点击查看更多>>
资源描述

《Zend Framework MVC设计模式.pdf》由会员分享,可在线阅读,更多相关《Zend Framework MVC设计模式.pdf(18页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、MVC?MVC?Zend Framework?Zend?MVC?index.php?Zend?MVC?2.1?Web?Zend?MVC?URL?The modelThe model?MVC?Zend?Zend_Db_Table?Zend_Service?Zend_Db_Table?Zend_Service?The viewThe view?Web?HTML?XML?RSS?CSV?CSV?Zend?Zend_View?PHP?Smarty?PHPTAL?The controllerThe controller?Web?Web?Zend Framework?Zend_Controller_Fro

2、nt?Zend_Controller_Action?Action?Zend Framework?Zend Framework?MVC?Zend Framework?The controller?The controller?Web?librarylibrary?ZendFramework?ORM?Smarty?PHP?/usr/php_include?php_include?Windows?php.ini?include_path?Zend Framework?PHP?Web?Web?Zend Framework?index.php?PHP?Web?CSS?JavaScript?Zend?We

3、b?Hello World?htaccess?Apache?Zend?2.3?MVC?BootstrappingBootstrapping?index.php?ZendFramework?2.1?Listing 2.1 The bootstrap file,index.php,initializes and runs theapplication2.1?index.php?Listing 2.1 The bootstrap file,index.php,initializes and runs theapplication2.1?index.php?123456789bootstrap()-r

4、un();?PHP 5.1?date_default_timezone_set?Zend?php_include?include_path?php.ini?Zend Framework?Zend_Loader?loadClass?1Zend_Loader:loadClass(Zend_Controller_Front);?1include_once Zend/Controller/Front.php;?Zend_Debug?var_dump?Zend_Controller_Front?Singleton?getInstance?URL?HTML?HTTP?Zend Framework?Erro

5、rHandler?ErrorController?dispatch?2.3.2 Apache.htaccess2.3.2 Apache.htaccess?Web?Apache?mod_rewrite?Apache?httpd.conf?Apache?htaccess?2.2?htaccess?Zend?1.?URL?2.?index.php?Apache?mod_rewrite?RewriteCond?RewriteRule?Apache?index.php?JavaScript?CSS?2.3.3 Index controller2.3.3 Index controller?URL?Cont

6、roller?ControllerName actionName?ControllerName Controller.php?“index”?http:/ Framework?/controllers?IndexController.php?IndexController?indexAction?2.3?Hello World?IndexController.php?Listing 2.3 The index controller:application/controllers/IndexController.php?123view-assign(title,Hello World!);?In

7、dexController?Zend_Controller_Action?indexAction?Zend_Controller_Action_ViewRenderer?ViewRenderer?ViewRenderer?Zend_View?ViewRenderer?phtml?/index.phtml?Zend_View?MVC?PHP?2.3.4 View template2.3.4 View template?12345678910111213 escape($this-title);?escape($this-title);?Zend_View?PHP?PHP?index.phtml?

8、Zend_View?$this?Zend_View?$this?$this?-title?index.phtml?HTML?XSS?HTML?Escape?Zend_View?Zend?Zend?MVC?2.4 How MVC applies to Zend Framework2.4 How MVC applies to Zend Framework?Web?web?PHP?session_start?Web?index.php?index.php?URL?index.php?controller=news&action=list?Zend Framework?Model View Contr

9、oller?2.4?Web?URL?http:/ Zend Frameworks controller2.4.1 Zend Frameworks controllerZend?Web?Zend_Controller_Front?THE REQUESTTHE REQUEST?Zend_Controller_Request_Http?HTTP?HTTP?$_GET?$_POST?$_COOKIE?$_SERVER?$_ENV?Zend_Controller_Request_Http?HTTP?Web?$items=$request-getParam(items);?Zend_Controller_

10、Request_Http?ROUTINGROUTING?Zend_Controller_Router_Interface?Zend_Controller_Router_Rewrite?URI?URI?http:/ Framework?action?Zend_Controller_Dispatcher_Standard?THE ACTIONTHE ACTION Zend_Controller_Action?URL?Action?indexAction?viewAction?editAction?deleteAction?URL?Zend_Controller_Action?init?preDis

11、patch?postDispatch?init?preDispatch?postDispatch?run?init?preDispatch?_forward?preDispatch?init?init?preDispatch?THE RESPONSETHE RESPONSE?Web?Zend_Controller_Response_Http?Zend_Controller_Response_Cli?Zend_Controller_Response_Http?HTTP?HTML?HTTP?RFC 2616?200?404?302?URL?304?RSS?Web?PDF?12345678910$f

12、ilename=example.pdf;$response=new Zend_Controller_Response_Http();/set the HTTP headers$response-setHeader(Content-Type,application/pdf);$response-setHeader(Content-Disposition,attachment;filename=.$filename.);$response-setHeader(Accept-Ranges,bytes);$response-setHeader(Content-Length,filesize($file

13、name);/load the file to send into the body$response-setBody(file_get_contents($filename);echo$response;?$response-setException()?Zend_Controller_Front?renderExceptions?true?FRONT CONTROLLER PLUG-INSFRONT CONTROLLER PLUG-INS?Zend_Controller_Plugin_Abstract?routeStartup?routeShutdown?dispatchLoopStart

14、up?preDispatch?postDispatch?dispatchLoopShutdown?Zend?ErrorHandler?MVC?Zend_View?2.4.2 Understanding Zend_View2.4.2 Understanding Zend_View?Zend_View?MVC?PHP?PHP?Smarty?Zend_View?Zend_View?Zend_View?1$view-assign(title,Hello World!);?title?“Hello World?123$music=array(title=Abbey Road,artist=The Bea

15、tles);$music=array(title=The Wall,artist=Pink Floyd);$view-assign($music);?PHP5?_set?1$view-title=Hello World!;?title?HTML?THE VIEW SCRIPTTHE VIEW SCRIPT?PHP?Zend_View?Zend_View?123456789Glossaryglossary)?glossary as$item):?escape($itemterm);?escape($itemdescription);?PHP?HTML?PHP?PHP?“?PHP?PHP?XSS?

16、HTML?PHP?VIEW HELPER FUNCTIONSVIEW HELPER FUNCTIONS Zend_View?escape?Zend_View?Zend_View?10?10.00?-10?10.00?1He gave me formatCurrency(10);?.?2.5?Zend_View_Helper?Zend_View_Helper_FormatCurrency?/FormatCurrency.php?2.5?Listing 2.5 The FormatCurrency view helperListing 2.5 The FormatCurrency view hel

17、per?123456789101112131415class Zend_View_Helper_FormatCurrency public function formatCurrency($value,$symbol=)$output=;$value=trim($value);if(is_numeric($value)if($value=0)$output=$symbol.number_format($value,2);else$output=-.$symbol.number_format(abs($value),2);return$output;?$value?XSS?formatCurre

18、ncy?Zend_View?_call?formatCurrency?*?Web?SECURITY CONSIDERATIONSSECURITY CONSIDERATIONS?XSS?HTML,CSS,(?HTML?”?XSS?JavaScript?JavaScript?“?100?Samy-over?20?,?XSS?HTML?<(?HTML?()?PHP?(),?HTML?HTML,?HTML?,?2.4.3 The model in MVC2.4.3 The model in MVC?HelloWorld?MVC?DATABASE ABSTRACTION WITH ZEND_DBDA

19、TABASE ABSTRACTION WITH ZEND_DB Zend_Db?Zend Framework?SQLite?MySQL?Oracle?Zend_Db?MySQL Zend_Db?12345$params=array(host=127.0.0.1,username=rob,password=*,dbname=zfia);$db=Zend_Db:factory(PDO_MYSQL,$params);?Zend_Db?PHP?PDO?DB2?Oracle?PDO?Zend_Db_Adapter_Abstract?Zend_Db?SECURITY ISSUES WITH DATABAS

20、ESSECURITY ISSUES WITH DATABASES?SQL?12$result=$db-query(SELECT*FROM usersWHERE name=.$_POSTname.);?$_POST?$_POST?1 OR 1 OR name=?SQL?1SELECT*from users where name=OR 1 OR name=?SQL?SQL?SQL?SQL?MySQL?mysql_real_escape_ string?PostgreSQL?pg_escape_string?Zend_Db?1$value=$db-quote(Its a kind of magic)

21、;?Zend_Db?quoteInto?12$sql=$db-quoteInto(SELECT*FROM table WHERE id=?,1);$result=$db-query($sql);?Zend_Db?Zend Framework?Zend_Db_Table?SQL?HIGHER-LEVEL INTERACTION WITH ZEND_DB_TABLEHIGHER-LEVEL INTERACTION WITH ZEND_DB_TABLE?MVC?Zend_Db_Table?Zend_Db_Table?Zend_Db?setDefaultAdapter?Zend_Db_Table?12

22、$db=Zend_Db:factory(PDO_MYSQL,$params);Zend_Db_Table:setDefaultAdapter($db);?Zend_Db_Table?ID?date_created?created_by?News?1234Class News extends Zend_Db_Table protected$_name=news;$_name?zend_db_table?Zend_Db_Table?id?$_name?$_primary?12class LatestNews extends Zend_Db_Table345protected$_name=news;

23、protected$_primary=article_id;?LatestNews?article_id?Zend_Db_Table?fetchRow?fetchAll?find?fetchRow?fetchAll?fetchRow?fetchAll?Zend_Db_Table?Zend_Db_Table?MVC?insert?MySQL?1234567CREATE TABLE news(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,date_created DATETIME NOT NULL,date_updated DATETIME NULL,tit

24、le VARCHAR(100)NULL,body MEDIUMTEXT NOT NULL)?date_created?date_updated?2.6?Listing 2.6 Automatically maintaining date fields in a modelListing 2.6 Automatically maintaining date fields in a model?12345678910111213class News extends Zend_Db_Table protected$_name=news;public function insert($data)if(

25、empty($datadate_created)$datadate_created=date(Y-m-d H:i:s);return parent:insert($data);public function update($data)if(empty($datadate_updated)$datadate_updated=date(Y-m-d H:i:s);141516 return parent:update($data);?date_created?Zend_Db_Table?Insert?date_updated?fetchAll?12345public function fetchLatest($count=5)$cutOff=date(Y-m-,strtotime(-3 months)$where=array(date_created?=$cutOff);$order=date_created DESC;return$this-fetchAll($where,$order,$count);?MVC?$where?Zend_Db?SQL?2.5 Summary2.5 Summary?Hello World?Zend?Zend?80/20?80?Zend_View_Abstract?Smarty?PHPTAL?Zend_View?

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 应用文书 > 财经金融

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁