Web application development with yii 2 and PHP

406 3.1K 0
Web application development with yii 2 and PHP

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Lap trinh php,mysql,lap trinh yii2,yii2,lap trinh,chuyen gia lap trinh php,tai lieu php,tai lieu yii2,hoc yii2,ebook yii2,chuyen gia cong nghe thong tin,linh vuc lap trinh php mysql,xay dung ung dung bang yii2

www.it-ebooks.info Web Application Development with Yii and PHP Fast-track your web application development using the new generation Yii PHP framework Mark Safronov Jeffrey Winesett BIRMINGHAM - MUMBAI www.it-ebooks.info Web Application Development with Yii and PHP Copyright © 2014 Packt Publishing All rights reserved No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews Every effort has been made in the preparation of this book to ensure the accuracy of the information presented However, the information contained in this book is sold without warranty, either expressed or implied Neither the authors, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals However, Packt Publishing cannot guarantee the accuracy of this information First published: August 2010 Second edition: November 2012 Third edition: September 2014 Production reference: 1190914 Published by Packt Publishing Ltd Livery Place 35 Livery Street Birmingham B3 2PB, UK ISBN 978-1-78398-188-5 www.packtpub.com Cover Image by Aniket Sawant (aniket_sawant_photography@hotmail.com) www.it-ebooks.info Credits Authors Project Coordinators Mark Safronov Venitha Cutinho Jeffrey Winesett Akash Poojary Reviewers Proofreaders Ajay Balachandran Simran Bhogal Maher Elaissi Stephen Copestake Md Rashidul Hasan Masum Maria Gould Mohammed Hussein Othman Ameesha Green Paul Hindle Commissioning Editor Usha Iyer Jonathan Todd Acquisition Editor Indexers Harsha Bharwani Mariammal Chettiyar Content Development Editor Madhuja Chaudhari Technical Editors Veronica Fernandes Pramod Kumavat Copy Editors Roshni Banerjee Sarang Chari Gladson Monteiro Adithi Shetty Joel T Johnson Monica Ajmera Mehta Tejal Soni Graphics Disha Haria Production Coordinators Kyle Albuquerque Melwyn D'sa Saiprasad Kadam Cover Work Melwyn D'sa www.it-ebooks.info About the Authors Mark Safronov is a professional web application developer from the Russian Federation, with experience and interest in a wide range of programming languages and technologies He has built and participated in building different types of web applications, from pure computational ones to full-blown e-commerce sites He is also a proponent of following the current best practices of test-first development and clean and maintainable code He is currently employed at Clevertech and is working on Yii-based PHP web applications He was also a maintainer of the popular YiiBooster open source extension for some time Back 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 Publishing Jeffrey Winesett is a partner at SeeSaw Labs in Austin, Texas, and has over 10 years of experience building large-scale, web-based applications He is a strong proponent of using open source development frameworks when developing applications, and a champion of the Yii framework in particular since its initial alpha release He frequently presents on, writes about, and develops with Yii as often as possible I would like to thank Qiang Xue for creating this amazing framework, and the entire Yii framework development team who continually improve and maintain it I thank all of the technical reviewers, editors, and staff at Packt Publishing for their fantastic contributions, suggestions, and improvements I would also like to thank my family, who have provided encouragement and unconditional support, and to my many colleagues over the years for providing invaluable opportunities for me to explore new technologies, expand my knowledge, and shape my career www.it-ebooks.info About the Reviewers Ajay Balachandran is a hardcore PHP developer and an avid Yii lover from India He is a huge advocate of writing modular, reusable, and standards-based code, which leads to his love for the Yii framework He is an expert in federated authentication using OpenID Connect, and now specializes in providing single sign-on and analytics solutions for the enterprise customers on behalf of his company, HiFX IT & Media Services Having a UI/UX background, Yii and its robust Web 2.0 oriented development has enabled Ajay to easily write applications ranging from simple shopping carts to robust APIs Maher Elaissi is a web developer based in Canada He has good knowledge of object-oriented analysis and designs and specializes in PHP programming His first experience with the Yii framework was in 2012, with a startup company Cisha GmbH based in Germany, to create an online chess game (www.chess24.com) I would like to thank the Super Mario team (dev team) for all their support and help in producing this book www.it-ebooks.info Md Rashidul Hasan Masum is a professional Software Engineer Over the last years, he has designed and developed a wide range of desktop and web applications using the enterprise framework Spring.NET NHibernate and websites using HTML, DHTML, JavaScript, jQuery, SignalR, Ext JS 4, ASP.NET (C#), PHP (Yii framework), Spring.NET, NHibernate, Google App Engine (Java), OpenLayer, Android with MSSQL, MySQL, and Bigtable, including sites for startup companies and small businesses His core competency lies in complete end-to-end management of a new application development He also has experience in the following areas: OOP, AOP, DI, ORM, SOA, n-Tire, highly configurable applications, neural networks, and software design and testing He now works at OnnoRokom Software Ltd as a Software Architect From the beginning, they have been using the Yii framework for their large-scale web application development S M Quamruzzaman Rahmani (www.byronbd.com), Project Manager, and GM Nazmul Hossain, (www.gmnazmul.com), System Analyst, have been working with him The three of them are a super combination for teamwork according to their personality profiles I'd like to thank Venitha Cutinho and Akash Poojary for their coordination Also, I'd like to thank my friend Maruf Maniruzzaman who works at Microsoft He has taught me a lot about computer engineering Thank you to my friend K M Masum Habib I'd also like to thank Packt Publishing I have read lots of e-books published by Packt Publishing Mohammed Hussein Othman is a Software Engineer who has graduated from Damascus University in Syria He has years of experience in working with the Yii framework in a variety of small and enterprise projects Mohammed has also been working on various modern web technologies, such as PHP, ASP.NET, Ruby on Rails, Node.js, and many others Currently, he works as a Senior Web Developer and Project Manager at Flex Solutions, which specializes in enterprise web applications www.it-ebooks.info www.PacktPub.com Support files, eBooks, discount offers, and more You might want to visit www.PacktPub.com for support files and downloads related to your book Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy Get in touch with us at service@packtpub.com for more details At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks TM http://PacktLib.PacktPub.com Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library Here, you can access, read, and search across Packt's entire library of books Why subscribe? • Fully searchable across every book published by Packt • Copy and paste, print, and bookmark content • On demand and accessible via web browser Free access for Packt account holders If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books Simply use your login credentials for immediate access www.it-ebooks.info www.it-ebooks.info Table of Contents Preface 1 Chapter 1: Getting Started A basic application Installation of a basic application template Specifics of the basic application template An advanced application 10 Installation of an advanced application template 11 Specifics of the advanced application template 13 Summary 14 Chapter 2: Making a Custom Application with Yii The design stage Task at hand Domain model design Target feature Initial preparations Setting up project management Setting up the testing harness Setting up the deployment pipeline Making a web application entry point visible Introducing the Yii framework into our application First end-to-end test Yii installation to the bare code base Checking the requirements An introduction to Yii conventions Building the wireframe code Adding a controller Handling possible errors www.it-ebooks.info 15 16 16 16 18 19 19 20 22 26 26 27 34 34 34 36 37 38 Index A AcceptanceTester class 92 acceptance tests, user management interface 116-118 access control applying, to site 166-170 in controllers, failing test 162-164 user authentication used 140 access control filter 165, 166 AccessControl filter 149 action filters \yii\filters\AccessControl filter 148 \yii\filters\ContentNegotiator filter 148 \yii\filters\HttpCache filter 148 \yii\filters\PageCache filter 148 \yii\filters\RateLimiter filter 149 \yii\filters\VerbFilter filter 148 about 147-151 advantages 147 actions, controller create 70 delete 70 index 70 update 70 view 70 active query 362-364 ActiveQuery class 363 active record password hashing, implementing inside 123-125 Add New Customer UI about 50, 51 finishing 53-55 load() method 54 rules() method 54 save() method 54 URL 59 validate() method 54 addresses table custom column value, creating for 374-376 advanced application 10 advanced application template installing 11-13 specifics 13 aliases registering 237 alias tokens @app 86 @runtime 86 @vendor 86 @web 86 @webroot 86 anatomy, Yii rendering 79-81 APC PHP about 218 URL 218 API module automatic tests, requisites 187-190 building 183 test suite, building 184-186 application layers, custom application creating 39 AssetBundle class, properties css 101 depends 101 js 101 sourcePath 101 www.it-ebooks.info asset bundles about 100 JavaScript, placing in different positions 105, 106 manual registration, of CSS files 104, 105 manual registration, of JavaScript files 104, 105 with files, from arbitrary folder 100, 101 with files, from web-accessible folder 103 assets minimizing 223-232 assets publishing about 101 practical consequences 102 AttributeBehavior class about 263 attributes setting 262 value setting 262 authentication indicator, login interface making 131 authentication key 126 autogenerated form customizing 364-371 automatic tests, API modules requisites 187-190 B BaseMailer class 278 basic application basic application template installing 7, specifics 9, 10 basic table, MySQL Workbench URL 114 beginCache() method 221 behavior about 253, 263 attaching 264, 265 detaching 264, 265 methods 264 behavior classes about 264 AttributeBehavior 263 BlameableBehavior 263 TimestampBehavior 263 behaviors() method 149 black hat hacker 233 blameable behavior using 260-263 BlameableBehavior class 263 boilerplate code preparing, for extension 235 bootstrap creating, for extension 238, 239 bootstrap() method 235 bootstrapping 235, 236 built-in events 270 built-in exceptions 214-216 built-in validators URL 46 C cache component 217-219 caching about 216 cache component 217-219 database queries caching 220 HTTP headers, using 222 levels 216 page fragment caching 221 whole page caching 221, 222 caching, dependencies \yii\caching\ChainedDependency 218 \yii\caching\DbDependency 218 \yii\caching\ExpressionDependency 218 \yii\caching\FileDependency 218 caching solutions \yii\caching\ApcCache 218 \yii\caching\DbCache 218 \yii\caching\DummyCache 219 \yii\caching\FileCache 219 \yii\caching\MemCache 219 \yii\caching\WinCache 219 \yii\caching\XCache 219 \yii\caching\ZendDataCache 219 code generating, for Model class 66-69 code base, custom application Yii 2, installing to 34 [ 378 ] www.it-ebooks.info Codeception about 21, 184 URL 10, 21 column types, Yii \yii\grid\ActionColumn 309 \yii\grid\CheckboxColumn 309 \yii\grid\DataColumn 309 \yii\grid\SerialColumn 309 component, Yii application 81-83 Composer about 7, 19 URL 20 Composer Custom Installer URL 242 composer.json manifest preparing 243 configuration local overrides, adding to 337-340 configuration construction 336, 337 console application 341, 342 constants, message log yii\log\Logger::LEVEL_ERROR 198 yii\log\Logger::LEVEL_INFO 198 yii\log\Logger::LEVEL_TRACE 198 yii\log\Logger::LEVEL_WARNING 198 controller actions moving, to separate module 191-193 controller class adding 38 adding, to custom application 37 qualities 37 Controller.render() method 87 controllers access control, failing test 162-164 hook methods 140-142 CRM management protecting, from CRM users 152, 153 Cross-Site Request Forgery (CSRF) 142 CRUD code generating 69-71 CRUD user interface 16 cryptographic hash function 115 custom application application layers, creating 39 controller class, adding 37, 38 data layers, creating 39 design 16 developing, Yii used 26 domain model design 16-18 end-to-end test, performing 27-33 errors, handling 38 preparations 19 target feature 18, 19 task 16 user interface, creating 49 using 58-60 wireframe code, building 36, 37 Yii 2, installing to code base 34 custom asset bundle creating, for application 106, 107 custom column value creating, for addresses table 374-376 custom console commands 342-344 customer Edit form, creating for 361, 362 customer creation test case 254-257 customer ID passing, to submodels 371-373 Customer Query UI about 58 URL 60 customers' index designing about 280 address, creating 281-284 common base controller, creating for submodels 285-287 e-mail, creating 281-284 phone active records, creating 281-284 relations, creating 288-290 customer updates test case 257-259 custom renderers overview 90-95 custom response formatter overview 95-100 custom routes implementing, configuration used 328 implementing, custom URL rule classes used 331-334 custom snowy theme creating 108-110 [ 379 ] www.it-ebooks.info custom templates creating, for database migrations 349-351 custom URL rule classes used, for implementing custom routes 331-334 D dash-separated format 326 database migrations about 11, 345-348 custom templates, creating for 349-351 references 11, 345 database queries caching 220 database records marking, with timestamp 253, 254 marking, with user ID 253, 254 data layers, custom application creating 39 customer model, defining 40, 41 database, setting up 43-45 decoupling, from ORM 47-49 ORM 45-47 DB connection component, property settings enableQueryCache 220 enableSchemaCache 220 queryCacheDependency 220 queryCacheDuration 220 schemaCacheDuration 220 schemaCacheExclude 220 Db module, Codeception URL 121 Debug module 180-183 default role 152 Dependency Injection Containers 82 deployment pipeline, custom application setting up 22-25 web application entry point visibility, enabling 26 DetailView widget 55 domain layer dismissal 279, 280 domain model design, custom application 16-18 domain-specific language (DSL) 362 down() method 346 E Edit form, for customer about 361, 362 active query 362-364 autogenerated form, customizing 364-371 custom column value, creating for addresses table 374-376 customer ID, passing to submodels 371-373 Update Customer form, after submodel update 373, 374 e-mailing component setting, for message log 201 enablePrettyUrl property 324 end-to-end test performing, on custom application 27-33 error handling about 211-213 built-in exceptions 214-216 error handling controller action 213, 214 errors, custom application handling 38 errorSummary method 51 ETag header 148, 222 events about 253, 265 classes 266 example 269, 270 methods 266 events, \yii\base\Application EVENT_AFTER_REQUEST 271 EVENT_BEFORE_REQUEST 271 events, \yii\base\Controller EVENT_AFTER_ACTION 271 EVENT_BEFORE_ACTION 271 events, \yii\base\Model EVENT_AFTER_VALIDATE 274 EVENT_BEFORE_VALIDATE 274 events, \yii\base\Module EVENT_BEFORE_ACTION 272 events, \yii\base\View EVENT_AFTER_RENDER 273 EVENT_BEFORE_RENDER 273 [ 380 ] www.it-ebooks.info EVENT_BEGIN_PAGE 273 EVENT_END_PAGE 273 events, \yii\db\BaseActiveRecord EVENT_AFTER_DELETE 276 EVENT_AFTER_FIND 275 EVENT_AFTER_INSERT 275 EVENT_AFTER_UPDATE 275 EVENT_BEFORE_DELETE 275 EVENT_BEFORE_INSERT 275 EVENT_BEFORE_UPDATE 275 EVENT_INIT 275 events, \yii\db\Connection EVENT_AFTER_OPEN 276 EVENT_BEGIN_TRANSACTION 276 EVENT_COMMIT_TRANSACTION 276 EVENT_ROLLBACK_TRANSACTION 276 events, \yii\mail\BaseMailer EVENT_AFTER_SEND 278 EVENT_BEFORE_SEND 278 events, \yii\web\Response EVENT_AFTER_PREPARE 277 EVENT_AFTER_SEND 277 EVENT_BEFORE_SEND 277 events, \yii\web\User EVENT_AFTER_LOGIN 277 EVENT_AFTER_LOGOUT 277 EVENT_BEFORE_LOGIN 277 EVENT_BEFORE_LOGOUT 277 events, \yii\web\View EVENT_BEGIN_BODY 274 EVENT_END_BODY 274 exception classes \yii\base\ErrorException 215 \yii\base\Exception 215 \yii\base\ExitException 215 \yii\base\InvalidCallException 215 \yii\base\InvalidConfigException 215 \yii\base\InvalidParamException 215 \yii\base\InvalidRouteException 215 \yii\base\NotSupportedException 215 \yii\base\UnknownClassException 215 \yii\base\UnknownMethodException 215 \yii\base\UnknownPropertyException 215 \yii\base\UserException 215 \yii\console\Exception 215 \yii\db\Exception 216 \yii\db\StaleObjectException 216 exception handling 143-147 extension about 233, 234 boilerplate code, creating for 235 bootstrap, creating for 238, 239 installable making 240, 241 registering 237 repositories, configuring for 244-250 extension contents creating 234 F failing test, access control in controllers 162-164 failing test, role hierarchy 157-159 Faker library URL 29 features, Yii assets, minimizing 223-232 caching 216 error handling 211-213 message log 197-199 profiling 206-210 file-based installation cons 249 pros 249 filters 142 format() method 80, 297 formats boolean 298 date 298 datetime 298 double 298 email 298 html 297 image 298 integer 298 ntext 297 number 299 paragraphs 297 raw 297 relativeTime 299 size 299 [ 381 ] www.it-ebooks.info text 297 time 298 url 298 formatter about 296 purpose 296 functional tests, password hashing 120-123 G generated classes, over manual classes cons 78 pros 78 generated CRUD UI overview 74-77 Gii about 10 code, generating for Model class 66-69 CRUD code, generating 69-71 installing, into application 64, 65 layout, creating for pages 72, 73 using 64 Google Closure compiler about 225 URL 225 GridView columns about 308 body rows 308 filter row 308 footer row 308 header row 308 GridView, customers filtering, implementing inside 310-314 sorting, implementing inside 316-320 GridView widget 55 H handleUpload() routine 267 hook methods afterAction($action, $result) 140 beforeAction($action) 140 of controller 141, 142 HTTP headers ETag 222 Last-Modified 222 reference link 222 used, for caching request 222 I identity user record, making into 126-128 index page, for customers base GridView, creating 293-295 creating 292, 293 custom GridView column, creating for customer audit info 299-306 format, modifying of column content 295, 296 submodels, compressing 307 index.php file about 25 basePath 37 components.request.cookieValidationKey 37 id 37 informal concept of reachability 175 installation, advanced application template 11-13 installation, basic application template 7, installation, Gii into application 64, 65 installation, Yii application requirements, checking 34 to custom application code base 34 L LAMP stack planning 354 Last-Modified header 148, 222 layouts about 52, 53 creating, for pages support 72, 73 List Customers UI 56, 57 ListView widget 55 local deploy target virtual machine, using as 359, 360 local overrides adding, to configuration 337-340 login interface authentication indicator, making 131 creating 128 [ 382 ] www.it-ebooks.info login form functionality 132-137 logout functionality 137 user authentication, specifications 129-131 log rotation 201 M Markdown URL 91 MarkdownRenderer class 94 md5() function 118 memcache solution URL 219 message log about 197-199 e-mailing component, setting 201 stored log messages, reading 203-205 storing 200 message log, methods Yii::error($message, $category) 199 Yii::info($message, $category) 199 Yii::trace($message, $category) 199 Yii::warning($message, $category) 199 message log, targets yii\log\DbTarget 201 yii\log\EmailTarget 201 yii\log\FileTarget 201 yii\log\SyslogTarget 201 methods, asset bundles registerCss($css, $options) 104 registerCssFile($url, $depends, $options) 104 registerJs($js, $position) 104 registerJsFile($url, $depends, $options) 104 methods, behavior attachBehavior($name, $behavior) 264 attachBehaviors($behaviors) 264 detachBehavior($name) 264 detachBehaviors() 264 methods, Cache API add($key, $value, $duration = 0, $dependency = null) 217 delete($key) 217 exists($key) 217 flush() 217 get($key) 217 methods, View component beginBody() 89 beginPage() 89 endBody() 89 endPage() 89 head() 89 methods, yii\rbac\DbManager class add($item) 160 addChild($parent, $child); 160 assign($role, $userId) 160 createPermission($name) 160 createRole($name) 160 methods, \yii\web\UrlRuleInterface createUrl($manager, $route, $params) 330 parseRequest($manager, $request) 330 MigrateController about 349 safeDown() method 349 safeUp() method 349 model defining 63, 64 Model class about 35 code, generating for 66-69 Model View Controller See  MVC module configuration examples 176-180 modules 173 Multipurpose Internet Mail Extensions (MIME) 98 MVC about 34, 35 Controller 35 Model 35 View 35 MySQL Workbench URL 42 O OAuth protocol URL 116 object-relation mapping See  ORM observer pattern incarnate URL 265 [ 383 ] www.it-ebooks.info OpenID URL 116 ORM about 45-47 data layers, decoupling from 47-49 P Packagist service cons 244 pros 244 URL 244 page fragment caching 221 password-based login mechanics about 114-116 password field 115 user field 115 password hashing functional tests 120-123 implementing, inside active record 123-125 upon saving user record 119, 120 password strength URL 154 PDO calls 48 permissions about 151, 152 features 151 Personal Package Archives (PPA) 356 phishing backdoor 233 PHP archive (PHAR) PHP script 336 popovers, Twitter Bootstrap reference link 301 positions, for JavaScript files View::POS_BEGIN 105 View::POS_END 105 View::POS_HEAD 105 View::POS_LOAD 105 View::POS_READY 105 predefined users installing 153, 154 preparations, custom application deployment pipeline, setting up 22-25 project management, setting up 19 testing framework, setting up 20-22 profiling 206-210 profiling, methods \yii\BaseYii::beginProfile() 207 \yii\BaseYii::endProfile() 207 \yii\log\Logger::getDbProfiling() 207 \yii\log\Logger::getElapsedTime() 207 \yii\log\Logger::getProfiling() 207 profiling security levels, log messages yii\log\Logger::LEVEL_PROFILE 206 yii\log\Logger::LEVEL_PROFILE_BEGIN 206 yii\log\Logger::LEVEL_PROFILE_END 206 project management, custom application setting up 19 PSR-4 standard URL 237 R RBAC 151 RBAC managers 155, 156 Redis URL 219 relational database management system (RDBMS) 345 render() method 90 renderPhpFile() method 90 repositories configuring, for extensions 244-250 repository-based installation cons 250 pros 250 repository pattern 47 requirements.php file URL, for downloading 34 require() method 79 Response::FORMAT_HTML literal 97 Response::FORMAT_JSON literal 97 Response::FORMAT_JSONP literal 97 Response::FORMAT_RAW literal 97 Response::FORMAT_XML literal 97 rich UI 362 role-based access control See  RBAC role hierarchy failing test 157-159 setting up 159-162 [ 384 ] www.it-ebooks.info routes controlling, ways 325 routing actions, using 325, 326 controllers, using 325, 326 modules name, using 325 routing 101 51, 52 routing 102, Yii 323-325 Ruby on Rails migrations reference link 345 S salting 115 Selenium 23 settings, modules basePath 174 components 174 controllerMap 174 controllerNamespace 174 controllerPath 174 layout 174 layoutPath 174 module 174 modules 174 viewPath 174 showScriptName property 324 Single Assertion principle 33 Single Responsibility Principle about 269 URL, for example 269 SSL certificates URL 116 Stack Exchange URL 118 StepObject pattern URL 28 stored log messages reading 20-205 submodels customer ID, passing to 371-373 SwiftMailer library about 201 URL 10 Symfony2 97 T tags 243 test case, customer creation 254-257 test case, customer updates about 257-259 database fields, preparing 259, 260 test-driven development (TDD) 190 testing framework, custom application setting up 20-22 themes 107 timestamp behavior using 260-263 TimestampBehavior class 263 touches finishing 72 Twitter Bootstrap UI library URL 10 U Update Customer form returning, after submodel update 373, 374 up() method 346 URL management fundamental rules 326 URL rules about 328-330 reference link 329 URL rules, properties mode 329 pattern 328 route 328 suffix 329 verb 328 URLs creating, in Yii 327 user authenticating, Yii used 114 user authentication, login interface specifications 129-131 user authorization 139 user interface, custom application Add New Customer UI 50, 51 Add New Customer UI, finishing 53-55 [ 385 ] www.it-ebooks.info creating 49 Customer Query UI 58 layouts 52, 53 List Customers UI 56, 57 routing 101 51, 52 widgets 55, 56 user login, Yii anatomy 114 user management interface about 116 acceptance tests 116-118 CRUD code, generating by Gii 118 database table, preparing for user records storage 118 model, generating by Gii 118 password field, removing from autogenerated code 119 user record making, into identity 126-128 W V Y Vagrant about 353 initial setup, creating 354-356 references 179, 353, 354 VerbFilter::className() invocation 149 View component about 35, 79, 84 algorithm, for finding view files 84-86 algorithm, for searching layout file 87-89 internal working, of rendering view file 89, 90 methods 89 VirtualBox URL 353 VirtualBox Guest Additions plugin 357 virtual machine using, as local deploy target 360 virtual machine, fine-tuning about 356 application, preparing 358, 359 database, preparing 357, 358 guest OS, preparing 356, 357 whole page caching 221, 222 widgets about 55, 56, 111 DetailView 55 GridView 55 ListView 55 using 290-292 Windows Cache URL 219 wireframe code, custom application building 36, 37 X XCache URL 219 Xdebug 197 YAML URL 97 Yaml::dump() method 100 Yaml::parse() method 100 Yii exception handling 143-147 RBAC managers 155 URLs, creating in 327 used, for authenticating user 114 Yii about column types 309 features 197 installing, to custom application code base 34 MVC 34, 35 routing 102 323-325 URL, for application boilerplate URL, for documentation page used, for developing custom application 26 yii2-debug repository URL, for installation instructions 180 Yii application components 81-83 [ 386 ] www.it-ebooks.info Yii basic-application template reference link 337 YiiBoilerplate project, Clevertech URL 340 Yii::createObject() invocation 82 Yii DAO URL 48 Yii::error($message, $category) method 199 Yii::info($message, $category) method 199 Yii rendering anatomy 79-81 Yii::trace($message, $category) method 199 Yii::warning($message, $category) method 199 YUI compressor about 225 URL 225 Z Zend Data Cache URL 219 [ 387 ] www.it-ebooks.info www.it-ebooks.info Thank you for buying Web Application Development with Yii and PHP About Packt Publishing Packt, pronounced 'packed', published its first book "Mastering phpMyAdmin for Effective MySQL Management" in April 2004 and subsequently continued to specialize in publishing highly focused books on specific technologies and solutions Our books and publications share the experiences of your fellow IT professionals in adapting and customizing today's systems, applications, and frameworks Our solution based books give you the knowledge and power to customize the software and technologies you're using to get the job done Packt books are more specific and less general than the IT books you have seen in the past Our unique business model allows us to bring you more focused information, giving you more of what you need to know, and less of what you don't Packt is a modern, yet unique publishing company, which focuses on producing quality, cutting-edge books for communities of developers, administrators, and newbies alike For more information, please visit our website: www.packtpub.com About Packt Open Source In 2010, Packt launched two new brands, Packt Open Source and Packt Enterprise, in order to continue its focus on specialization This book is part of the Packt Open Source brand, home to books published on software built around Open Source licenses, and offering information to anybody from advanced developers to budding web designers The Open Source brand also runs Packt's Open Source Royalty Scheme, by which Packt gives a royalty to each Open Source project about whose software a book is sold Writing for Packt We welcome all inquiries from people who are interested in authoring Book proposals should be sent to author@packtpub.com If your book idea is still at an early stage and you would like to discuss it first before writing a formal book proposal, contact us; one of our commissioning editors will get in touch with you We're not just looking for published authors; if you have strong technical skills but no writing experience, our experienced editors can help you develop a writing career, or simply get some additional reward for your expertise www.it-ebooks.info Yii Application Development Cookbook Second Edition ISBN: 978-1-78216-310-7 Paperback: 408 pages A Cookbook covering both practical Yii application development tips and the most important Yii features Learn how to use Yii even more efficiently Full of practically useful solutions and concepts you can use in your application Both important Yii concept descriptions and practical recipes are inside Web Application Development with Yii and PHP Second Edition ISBN: 978-1-84951-872-7 Paperback: 332 pages Learn the Yii application development framework by taking a step-by-step approach to building a Web-based project task tracking system from conception through production deployment A step-by-step guide to creating a modern Web application using PHP, MySQL, and Yii Build a real-world, user-based, database-driven project task management application using the Yii development framework Start with a general idea, and finish with deploying to production, learning everything about Yii in between, from "A"ctive record to "Z"ii component library Please check www.PacktPub.com for information on our titles www.it-ebooks.info Yii Rapid Application Development HOTSHOT ISBN: 978-1-84951-750-8 Paperback: 340 pages Become a RAD hotshot with Yii, the world's most popular PHP framework A series of projects to help you learn Yii and Rapid Application Development Learn how to build and incorporate key web technologies Use as a cookbook to look up key concepts, or work on the projects from start to finish for a complete web application Agile Web Application Development with Yii1.1 and PHP5 ISBN: 978-1-84719-958-4 Paperback: 368 pages Fast-track your web application development by harnessing the power of the Yii PHP Framework A step-by-step guide to creating a modern, sophisticated web application using an incremental and iterative approach to software development Build a real-world, user-based, database-driven project task management application using the Yii development framework Take a test-driven design (TDD) approach to software development utilizing the Yii testing framework Please check www.PacktPub.com for information on our titles www.it-ebooks.info [...]... Built-in events 27 0 Events of \yii\ base \Application 27 1 Events of \yii\ base\Controller 27 1 Events of \yii\ base\Module 27 2 Events of \yii\ base\View 27 3 Events of \yii \web\ View 27 4 Events of \yii\ base\Model 27 4 Events of \yii\ db\BaseActiveRecord 27 5 Events of \yii\ db\Connection 27 6 Events of \yii \web\ Response 27 7 Events of \yii \web\ User 27 7 Events of \yii\ mail\BaseMailer 27 8 Summary 27 8 Chapter 11: The... www.it-ebooks.info 27 9 27 9 28 0 28 1 28 5 28 8 29 0 29 2 29 3 29 5 29 6 29 9 307 308 310 Table of Contents Implementing sorting inside GridView of customers 316 Summary 321 Chapter 12: Route Management 323 Chapter 13: Collaborative Work 335 Appendix A: Deployment Setup with Vagrant 353 Appendix B: The Active Form Primer 361 Yii 2 routing 1 02 323 FEATURE – routing using names of modules, controllers, and actions 325 Fundamental... 197 20 0 20 1 Reading the stored log messages 20 3 FEATURE – profiling 20 6 Error handling details 21 1 FEATURE – error handling controller action 21 3 List of built-in exceptions 21 4 Caching 21 6 FEATURE – cache component 21 7 FEATURE – database queries caching 22 0 FEATURE – page fragment caching 22 1 FEATURE – whole page caching 22 1 FEATURE – caching the request by HTTP headers 22 2 Minimizing the assets 22 3... 23 5 23 5 23 7 23 8 24 0 24 2 Table of Contents Configuring the repositories 24 4 Summary 25 1 Chapter 10: Events and Behaviors Automatically marking database records with the timestamp and user ID Test case for customer creation Test case for updating customer updates Preparing the database fields 25 3 25 3 25 4 25 7 25 9 Using the timestamp and blameable behaviors 26 0 FEATURE – behaviors 26 3 FEATURE – events 26 5... code block, the relevant lines or items are set in bold: require_once( DIR '/ / /vendor/yiisoft /yii2 /Yii. php' ); new yii \web\ Application( require( DIR '/ / /config /web. php' ) ); Any command-line input or output is written as follows: $ php composer.phar require prefer-dist yiisoft /yii2 -debug "*" New terms and important words are shown in bold Words that you see on the screen, in menus or dialog... application The most basic and straightforward way to get started with Yii 2 is to use the application boilerplate published by the Yii 2 team on their GitHub repository (https://github.com/yiisoft /yii2 ) and available through the Composer tool In the prior versions of Yii, you had to manually download and extract the archive with the framework contents While you can still do the same in Yii 2, this version is... advanced application: $ curl -sS https://getcomposer.org/installer | php $ php composer.phar create-project prefer-dist \ stability=dev yiisoft /yii2 -app-advanced advanced $ cd advanced $ /init $ mysql -u root -e 'create database yii2 advanced' $. /yii migrate $ php -S localhost:8080 -t frontend /web $ php -S localhost:8081 -t backend /web [ 13 ] www.it-ebooks.info Getting Started Summary Yii 2 allows... user input, and Twitter handles are shown as follows: "Now run the following command to create a subdirectory called basic, and fill it with the basic application template." A block of code is set as follows: require_once( DIR '/ / /vendor/yiisoft /yii2 /Yii. php' ); new yii \web\ Application( require( DIR '/ / /config /web. php' ) ); When we wish to draw your attention to a particular part of a code block,... the process of incremental, test-first development of a web application using Yii framework Version 2 The Yii framework, hosted at http://www.yiiframework.com/, is a PHP- based application framework built around the Model-View-Controller composite pattern It is suitable for building both web and console applications, but its feature set makes it most useful for web applications It has several code generation... stability=dev \ yiisoft /yii2 -app-basic basic www.it-ebooks.info Getting Started Please note that Yii 2 specifies several system-wide dependencies for itself You probably will need to consult the composer.json file inside their GitHub repository to learn about them beforehand (https://github.com/yiisoft /yii2 ) But in any case, Composer will tell you what you need to install to make Yii 2 workable Yii 2 gets new

Ngày đăng: 30/07/2016, 07:04

Mục lục

  • Chapter 1: Getting Started

    • A basic application

      • Installation of a basic application template

      • Specifics of the basic application template

      • An advanced application

        • Installation of an advanced application template

        • Specifics of the advanced application template

        • Chapter 2: Making a Custom Application with Yii 2

          • The design stage

            • Task at hand

            • Initial preparations

              • Setting up project management

              • Setting up the testing harness

              • Setting up the deployment pipeline

                • Making a web application entry point visible

                • Introducing the Yii framework into our application

                  • First end-to-end test

                  • Yii 2 installation to the bare code base

                    • Checking the requirements

                    • An introduction to Yii conventions

                    • Building the wireframe code

                    • Making the data and application layers

                      • Defining the customer model at the data layer

                      • Setting up the database

                      • Object-relation mapping in Yii

                      • Creating the user interface

                        • The Add New Customer UI

                        • Finishing the Add New Customer UI

                        • The List Customers UI

                        • Definition of the model to work with

                        • Using Gii

                          • Installing Gii into the application

Tài liệu cùng người dùng

Tài liệu liên quan