Yii2 由浅入深详细解说,超详细开发手册,适用于入门、提高、进阶各阶段。Web application development with yi 2 and PHPCopyright o 2014 Packt PublishingAll rights reserved. No part of this book may be reproduced, stored in a retrievalsystem, or transmitted in any form or by any means, without the prior writtenpermission of the publisher, except in the case of brief quotations embedded incritical articles or reviewsrt has been made in the preparation of this book to ensure the accuracyof the information presented. However, the information contained in this book issold without warranty cither expressed or implied. Neither the authors, nor PacktPublishing and its dealers and distributors will be held liable for any damagescaused or alleged to be caused directly or indirectly by this bookPackt Publishing has endeavored to provide trademark information about all of thecompanies and products mentioned in this book by the appropriate use of capitalsHowever, Packt Publishing cannot guarantee the accuracy of this informationFirst published: August 2010Second edition: November 2012Third edition: September 2014Production reference: 1190914Published by Packt Publishing LtdLivery place35 Livery streetBirmingham b3 2PB, UKISBN978-178398-188-5www.packtpub.comCoverImagebyaniketSawant(aniketsawantphotographyohotmail.comCreditsAuthorsProject CeMark safronovVenitha cutinhoJeffrey WinesettAkash PoojaryReviewersProofreadersAjay BalachandranSimran bhogalMaher elaissiStephen CopestakeMd Rashidul hasan masumMaria gouldMohammed hussein othmanAmeesha greenPaul hindleCommissioning EditorJoel t. johnsonUsha lyerJonathan ToddAcquisition EditorIndexersHarsha bharwaniMariamman ChettiyarMonica Ajmera MehtaContent Development EditorMadhuja ChaudhariTejal SoniTechnical editorsGraphicsVeronica fernandesDisha hariaProduction coordinatorsKyle AlbuquerqueCopy EditRoshni BanerjeeMelwyn d'saSarang ChariSaiprasad KadGladson monteiroCover workAdithi shettyMelwyn D'saAbout the authorsMark safronov is a professional web application developer from the russianFederation, with experience and interest in a wide range of programming languagesand technologies. He has built and participated in building different types of webapplications, from pure computational ones to full-blown e-commerce sites. Ile isalso a proponent of following the current best practices of test-first developmentand clean and maintainable codeHe is currently employed at Clevertech and is working on Yii-based PHP webapplications. He was also a maintainer of the popular Yii Booster open sourceextension for some timeBack in 2008, he translated the book Visual prolog 7. 1 for Tyros, Eduardo costa,in Russian with a totally new color layout In 2013, along with Jacob mumm,he co-authored the book Instant Yii Application Development starter, Packt PublishingJeffrey Winesett is a partner at See Saw Labs in Austin, Texas, and has over 10 yearsof using open source development frameworks when developing applications Onentof experience building large-scale, web-based applications. He is a strong profand a champion of the yii framework in particular since its initial alpha releasHe frequently presents on, writes about, and develops with Yii as often as possibleI would like to thank Qiang Xue for creating this amazingframework, and the entire Yii framework development team whocontinually improve and maintain it. I thank all of the technicalreviewers, editors, and staff at Packt Publishing for their fantasticcontributions, suggestions, and improvements. I would also liketo thank my family who have provided encouragement andunconditional support, and to my many colleagues over the yearsfor providing invaluable opportunities for me to explore newtechnologies, expand my knowledge, and shape my careerAbout the reviewersAjay Balachandran is a hardcore PhP developer and an avid Yii lover from IndiaHe is a huge advocate of writing modular, reusable, and standards-based codewhich leads to his love for the yii frameworkHe is an expert in federated authentication using openid connect, and nowspecializes in providing single sign-on and analytics solutions for the enterprisecustomers on behalf of his company, HiFx T media ServicesHaving a Ul/uX background, Yii and its robust Web 2.0 oriented developmenthas enabled ajay to easily write applications ranging from simple shopping cartsto robust apisMaher elaissi is a web developer based in Canada. He has good knowledge ofobject-oriented analysis and designs and specializes in PHP programming. Hisfirst experience with the Yii framework was in 2012, with a startup company CishaGmbhbasedinGermanytocreateanonlinechessgame(www.chess24.com)I would like to thank the Super Mario team(dev team)for all theirsupport and help in producing this bookMd. Rashidul hasan Masum is a professional Software Engineer. Over thelast 6 years, he has designed and developed a wide range of desktop and webapplications using the enterprise framework Spring. NET NHibernate and websitesusing HTML, DhTMl, JavaScript, jQuery, SignalR, Ext Js 4, ASP.NET(C#), PHP(Yii framework), Spring. NET, NHibernate, Google App Engine ( ava), OpenLayer,Android with MSSQL, MySQL, and Bigtable, including sites for startup companiesand small businesses. I lis core competency lies in complete end-to-end managementof a new application developmentHe also has experience in the following areas: OOP, AOP, DI, ORM, SOA, n-Tire,highly configurable applications, neural networks, and software design and testingHe now works at OnnoRokom Software Ltd as a software architect From thebeginning, they have been using the Yii framework for their large-scale webapplicationdevelopmentS.m.QuamruzzamanRahmani(www.byronbd.com),PRojectManagerandGmNazmulhoSsain,(www.gmnazmul.com),SystemAnalyst,have been working with him. The three of them are a super combination forteamwork according to their personality profilesI'd like to thank Venitha Cutinho and Akash Poojary for theircoordination. Also, I'd like to thank my friend maruf maniruzzamanwho works at Microsoft. He has taught me a lot about computerengineering. Thank you to my friend K M. Masum Habib. I'd alsolike to thank Packt Publishing. I have read lots of e-books publishedby packt publishinMohammed hussein Othman is a Software Engineer who has graduated fromDamascus University in Syria. He has 4 years of experience in working with the Yiiframework in a variety of small and enterprise projects. Mohammed has also beenworking on various modern web technologies, such as phP asp. net, ruby onRails, Node. js, and many others. Currently, he works as a Senior Web Developer andProject Manager at Flex Solutions, which specializes in enterprise web applicationsWww.Packtpub.comSupport files, eBooks, discount offersand moreYoumightwanttovisitwww.Packtpub.comforsupportfilesanddownloadsrelatedtoyour bookDid you know that Packt offers e Book versions of every book published, with PDF and ePubfilesavailableYoucanupgradetotheebooKversionatwww.Packtpub.comandasaprintbook customer, you are entitled to a discount on the e Book copy get in touch with us atservice@packtpub com for more detailsAtwww.packtpub.comyoucanalsoreadacollectionoffreetechnicalarticlessignupforaange of free newsletters, and receive exclusive discounts and offers on Packt books and eBooksPACKTLIBhttp://packtlib.Packtpub.comDo you need instant solutions to your If questions? PacktLib is Packt's online digital booklibrary. Here, you can access, read, and search across Packt's entire library of booksWhy subscribe?Fully searchable across every book published by packtCopy and paste, print, and bookmark contentOn demand and accessible via web browserFree access for Packt account holdersIfyouhaveanaccountwithPacktalwww.packtpub.comyoucanusethisloaccessPacktlib today and view nine entirely free books. Simply use your login credentials forimmediate accessTable of contentsPrefaceChapter 1: Getting Started7A basic applicationInstallation of a basic application templateSpecifics of the basic application template9An advanced application10Installation of an advanced application templateSpecifics of the advanced application template13Summary14Chapter 2: Making a Custom Application with Yii215The design stage16ask at handDomain model design16Target feature18Initial preparations19Setting up project management19Setting up the testing harness20Setting up the deployment pipelineMaking a web application entry point visible26Introducing the Yii framework into our application26First end-to-end test27Yii 2 installation to the bare code base34Checking the requirements34An introduction to rii conventions34Building the wireframe code36Adding a controller37Handling possible errors38