0%

Book Description

For PHP programmers with a yearning to add modernity and sophistication to their web applications, this book will be a revelation. A step-by-step tutorial to Yii, it talks you through the development of a complete real-world application.

  • 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 inbetween, from "A"ctive record to "Z"ii component library

In Detail

This book is a step by step tutorial in developing a real-world application using the incremental and iterative approach to software development. You learn about agile software development by leaning on the agile nature of the Yii application development framework. You touch on each aspect of the software development lifecycle by building a project task management application from concept through production deployment.

After a brief, general introduction to the Yii framework and outlining the software development approach taken throughout the book, the chapters break down in the same way as software development iterations do in real-world projects. After the 1st iteration, you will have a working and tested application with a valid, tested connection to a database.

In the 2nd and 3rd iterations, we flesh out our main database entities and domain object model and become familiar with Yii's object-relational-mapping (ORM) layer, Active Record. We also learn how to lean on Yii's auto-generation tools to automatically build our create/read/update/delete (CRUD) functionality against our newly created model. These iterations also focus on how Yii's form validation and submission model works. By the end of the third iteration you will have a working application that allows you to mange projects and issues (tasks) within those projects.

The 4th and 5th iterations are dedicated to user management. We learn about the built-in authentication model within Yii to assist in application login and logout functionality. We then dive into the authorization model, first taking advantage of a Yii's simple access control model, then implementing the more sophisticated role-based access control (RBAC) framework that Yii provides.

By the end of the 5th iteration, all of the basics of a task management application are in place. The next several iterations are focused on the nice-to-haves. We add user comment functionality, introducing a reusable content portlet architecture approach in the process. We add in an RSS Web feed and demonstrate how easy it is to integrate other third-party tools within a Yii application. We take advantage of Yii's theming structure to help streamline and design the application, and then introduce Yii's internationalization (I18N) features so the application can be adapted to various languages and regions without engineering changes.

Finally, we turn our focus to production deployment. We introduce ways to optimize performance and security to prepare the application for a real-world production environment.

Table of Contents

  1. Web Application Development with Yii and PHP Second Edition
    1. Table of Contents
    2. Web Application Development with Yii and PHP
    3. Credits
    4. About the Author
    5. About the Reviewers
    6. www.PacktPub.com
      1. Support files, eBooks, discount offers and more
        1. Why Subscribe?
        2. Free Access for Packt account holders
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    8. 1. Meet Yii
      1. Easy
      2. Efficient
      3. Extensible
      4. MVC architecture
        1. Model
        2. View
        3. Controller
      5. Stitching these together: Yii request routing
        1. Blog posting example
      6. Object-relational mapping and Active Record
        1. Active Record
      7. The view and controller
      8. Summary
    9. 2. Getting Started
      1. Installing Yii
        1. Installing a database
      2. Creating a new application
      3. "Hello, World!"
        1. Creating the controller
          1. Configuring Gii
        2. One final step
        3. Reviewing our request routing
      4. Adding dynamic content
        1. Adding the date and time
        2. A different approach for adding the date and time
          1. Moving the data creation to the controller
        3. Have you been paying attention?
      5. Linking pages together
        1. Linking to a new page
        2. Getting a little help from Yii CHtml
      6. Summary
    10. 3. The TrackStar Application
      1. Introducing TrackStar
      2. Creating user stories
        1. Users
        2. Projects
        3. Issues
      3. Navigation and page flow
      4. Data relationships
      5. Creating the new application
      6. Connecting to the database
        1. Yii and databases
          1. Adding a db connection as an application component
            1. Adding a db connection as an application component
      7. Testing the database connection
        1. Using the interactive shell
        2. Automated testing – unit and functional tests
          1. Unit and functional testing
            1. Unit tests
            2. Functional tests
        3. Benefits of testing
        4. Testing in Yii
        5. Unit tests
          1. Installing PHPUnit
        6. Testing the connection
      8. Summary
    11. 4. Project CRUD
      1. Feature planning
      2. Creating the project table
        1. Yii database migrations
        2. Naming conventions
      3. Creating the AR model class
        1. Configuring Gii
        2. Using Gii to create our Project AR class
      4. Enabling CRUD operations for projects
        1. Creating CRUD scaffolding for projects
        2. Creating a new project
          1. Form field validation
        3. Reading the project
        4. Updating and deleting projects
        5. Managing projects in Admin mode
      5. Summary
    12. 5. Managing Issues
      1. Feature planning
      2. Designing the schema
        1. Defining some relationships
      3. Building objects and their relationships
      4. Creating active record model classes
        1. Creating the Issue model class
        2. Creating the User model class
      5. Creating the issue CRUD operations
      6. Using the issue CRUD operations
        1. Creating a new issue
          1. Adding drop-down fields
          2. Adding the issue type drop-down
          3. Adding the status dropdown: do it yourself
      7. Fixing the owner and requester fields
        1. Enforcing a project context
          1. Defining filters
          2. Adding a filter
          3. Specifying the filtered actions
          4. Adding filter logic
          5. Adding the project ID
          6. Altering the project details page
        2. Returning back to the owner and requester dropdowns
          1. Generating the data to populate the dropdowns
          2. Making one last change
      8. The rest of the CRUD
        1. Listing the issues
          1. Altering the project controller
          2. Altering the project view file
      9. Final tweaks
        1. Getting the status and type text to display
          1. Adding the text display to the form
        2. Changing the issue detail view
        3. Displaying owner and requester names
          1. Using relational AR
        4. Making some final navigation tweaks
      10. Summary
    13. 6. User Management and Authentication
      1. Feature planning
      2. User CRUD
        1. Updating our common audit history columns
          1. Component behavior
        2. Adding a password confirmation field
        3. Hash the password
      3. Authenticating users using the database
        1. Introducing the Yii authentication model
          1. Changing the authenticate implementation
          2. Extending user attributes
        2. Displaying the last login time on the home page
      4. Summary
    14. 7. User Access Control
      1. Feature planning
      2. Access control filter
      3. Role based access control
        1. Configuring the authorization manager
        2. Creating the RBAC database tables
        3. Creating the RBAC authorization hierarchy
          1. Writing a console application command
        4. Assigning users to roles
        5. Adding RBAC roles to users on a per-project basis
          1. Adding RBAC business rules
          2. Implementing the new project AR methods
        6. Adding users to projects
          1. Altering the project model class
          2. Adding the new form model class
          3. Adding the new action method to the project controller
          4. Adding the new view file to display the form
          5. Putting it all together
      4. Checking authorization level
      5. Summary
    15. 8. Adding User Comments
      1. Feature planning
      2. Creating the model
      3. Creating the comment CRUD
      4. Altering the scaffolding to meet our requirements
        1. Adding a comment
        2. Displaying the form
      5. Creating a recent comments widget
        1. Introducing CWidget
          1. Named scopes
          2. More on relational AR queries in Yii
          3. Creating the widget
          4. Introducing CPortlet
            1. Adding our widget to another page
      6. Summary
    16. 9. Adding an RSS Web Feed
      1. Feature planning
      2. A little background–content syndication, RSS, and Zend Framework
      3. Installing Zend Framework
      4. Using Zend_Feed
      5. Creating user-friendly URLs
        1. Using the URL manager
          1. Configuring routing rules
            1. Removing the entry script from the URL
      6. Adding the feed links
      7. Summary
    17. 10. Making It Look Good
      1. Feature planning
      2. Designing with layouts
        1. Specifying a layout
        2. Applying and using a layout
      3. Deconstructing the main.php layout file
        1. Introducing the Blueprint CSS framework
          1. Understanding the Blueprint installation
        2. Setting the page title
        3. Defining a page header
        4. Displaying menu navigation items
        5. Creating a breadcrumb navigation
        6. Specifying the content being decorated by the layout
        7. Defining the footer
      4. Nesting the layouts
      5. Creating themes
        1. Building themes in Yii
        2. Creating a theme
        3. Configuring the application to use a theme
      6. Translating the site to other languages
        1. Defining locale and language
        2. Performing language translation
          1. Performing message translation
          2. Performing file translation
      7. Summary
    18. 11. Using Yii Modules
      1. Feature planning
      2. Working with modules
        1. Creating a module
        2. Using a module
        3. Module layout
          1. Applying a layout
      3. Restricting admin access
      4. Adding a system-wide message
        1. Creating the database table
        2. Creating our model and CRUD scaffolding
        3. Adding a link to our new functionality
        4. Displaying the message to users
          1. Importing the new model class for application-wide access
          2. Selecting the most recently updated message
          3. Adding a little design tweak
      5. Summary
    19. 12. Production Readiness
      1. Feature planning
      2. Logging
        1. Message logging
          1. Categories and levels
          2. Adding a login message log
        2. Message routing
      3. Handling errors
        1. Displaying errors
      4. Caching
        1. Cache configuration
        2. Using a file-based cache
        3. Cache dependencies
        4. Query caching
        5. Fragment caching
          1. Declaring fragment caching options
          2. Using fragment cache
        6. Page caching
      5. General performance tuning tips
        1. Using APC
        2. Disabling the debug mode
        3. Using yiilite.php
        4. Using caching techniques
        5. Enabling schema caching
      6. Summary
    20. Index
3.144.252.140