O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Agile Web Application Development with Yii 1.1 and PHP5

Book Description

For PHP developers who know object-oriented programming, this book is the fast track to learning the Yii framework. It takes a step-by-step approach to building a complete real-world application – teaching by practice rather than theory.

  • 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

  • Write less code by using Yii's application generation and scaffolding tools

  • Enhance your application by adding Web feeds, adapting it to multiple languages, and by utilizing themes to provide beautiful skins and design flexibility

  • 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.

    Learn the Yii development framework by taking a test-driven, incremental, and iterative approach to building a real-world task management application

    Table of Contents

    1. Agile Web Application Development with Yii 1.1 and PHP5
      1. Table of Contents
      2. Agile Web Application Development with Yii 1.1 and PHP5
      3. Credits
      4. About the Author
      5. About the Reviewers
      6. Preface
        1. What this book cover
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Errata
          2. Piracy
          3. Questions
      7. 1. Meet Yii
        1. Yii is easy
        2. Yii is efficient
        3. Yii is extensible
        4. MVC architecture
          1. The model
          2. The view
          3. The 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
      8. 2. Getting Started
        1. Installing Yii
          1. Installing a database
        2. Creating a new application
        3. Hello, World!
          1. Creating the controller
          2. One final step
          3. Reviewing our request routing
        4. Adding dynamic content
          1. Adding the date and time
          2. Adding the date and time, a better approach
            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
      9. 3. The TrackStar Application
        1. Introducing TrackStar
        2. Creating user stories
          1. Users
          2. Projects
          3. Issues
        3. Navigation and page flow
        4. Defining a data scheme
        5. Defining our development methodology
          1. Automated software testing
          2. Unit and functional testing
            1. Unit tests
            2. Functional tests
          3. Benefits of testing
          4. Test-driven development
        6. Testing in Yii
          1. Unit tests
            1. Installing PHPUnit
          2. Functional tests
            1. Installing Selenium
            2. Running a quick example
          3. Hello TDD!
        7. Summary
      10. 4. Iteration 1: Creating the Initial TrackStar Application
        1. Iteration planning
        2. Creating the new application
        3. Connecting to the database
          1. Testing the connection
            1. Yii and databases
          2. Adding a db connection as an application component
        4. Summary
      11. 5. Iteration 2: Project CRUD
        1. Iteration planning
          1. Running our test suite
        2. Creating the project table
          1. Naming conventions
        3. Creating the AR model class
          1. Configuring Gii
          2. Using Gii to create our Project AR class
          3. Testing out our newly generated code
            1. Creating the unit test file
            2. Testing create
            3. Testing read
            4. Testing update and delete
          4. Was all that testing really necessary?
        4. Enabling CRUD operations for users
          1. Creating CRUD scaffolding for projects
          2. Creating a new project
            1. Adding a required field to our form
          3. Reading the project
          4. Updating and deleting projects
          5. Managing projects in admin mode
        5. More on testing—fixtures
          1. Configuring the fixture manager
          2. Creating a fixture
          3. Configuring this fixture for use
          4. Specifying a test database
            1. Using fixtures
        6. Summary
      12. 6. Iteration 3: Adding Tasks
        1. Iteration planning
        2. Running the test suite
        3. Designing the schema
          1. Defining some relationships
          2. Building the database and the relationships
        4. Creating the Active Record model classes
          1. Creating the Issue model class
          2. Creating the User model class
        5. Creating the Issue CRUD operations
          1. Using the Issue CRUD operations
        6. Creating a new Issue
          1. Adding the types drop-down menu
          2. Getting the test in the "Red"
          3. Moving From "Red" To "Green"
          4. Moving Back To "Red"
          5. Getting back to "Green" once again
          6. Adding the issue type dropdown
          7. Adding the status drop-down menu: Do it yourself
        7. Fixing the owner and requester fields
          1. Enforcing a project context
          2. Implementing a filter
          3. Adding a filter
          4. Specifying the filtered actions
          5. Adding some filter logic
          6. Adding the project ID
          7. Altering the project details page
          8. Removing the project input form field
        8. Returning back to the owner and requester dropdowns
          1. Generating the data to populate the drop-down menu
          2. Adding User and ProjectUserAssignment fixtures
          3. Making one last change
        9. Finishing the rest of the CRUD
          1. Listing the issues
          2. Altering the ProjectController
            1. Altering the project view file
        10. Making some final tweaks
          1. Getting the status and type text to display
          2. Adding the text display to the form
          3. Changing the issue detail view
          4. Getting the owner and requester names to display
          5. Using relational AR
        11. Making some final navigation tweaks
        12. Summary
      13. 7. Iteration 4: User Management and Authentication
        1. Iteration planning
        2. Running the test suite
        3. Creating our User CRUD
          1. Updating our common audit history columns
          2. Adding a password confirmation field
          3. Adding password encryption
        4. Authenticating users using the database
          1. Introducing the Yii authentication model
            1. Changing the authenticate implementation
              1. Extending application user attributes
        5. Updating the user last login time
          1. Displaying the last login time on the home page
        6. Summary
      14. 8. Iteration 5: User Access Control
        1. Iteration planning
        2. Running our existing test suite
        3. accessControl filter
        4. 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 projects
            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
        5. Checking authorization level
        6. Summary
      15. 9. Iteration 6: Adding User Comments
        1. Iteration planning
        2. Creating the model
        3. Creating the Comment CRUD
        4. Altering the scaffolding to meet requirements
          1. Adding a comment
          2. Displaying the form
        5. Creating a recent comments widget
          1. Introducing CWidget
            1. More on relational AR queries in Yii
            2. Completing the test
            3. Creating the widget
              1. Introducing CPortlet
              2. Adding our widget to another page
        6. Summary
      16. 10. Iteration 7: Adding an RSS Web Feed
        1. Iteration 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
            2. Removing the entry script from the URL
        6. Adding the feed links
        7. Summary
      17. 11. Iteration 8: Making it Pretty - Design, Layout, Themes, and Internationalization(i18n)
        1. Iteration 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 Yii 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. 12. Iteration 9: Modules - Adding Administration
        1. Iteration planning
        2. Modules
          1. Creating a module
          2. Using a module
          3. Theming a module
            1. Applying a theme
        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. 13. Iteration 10: Production Readiness
        1. Iteration planning
        2. Logging
          1. Message logging
          2. Categories and levels
          3. Adding a login message log
          4. Message routing
        3. Handling errors
          1. Displaying errors
        4. Caching
          1. Configuring for cache
          2. Using a file-based cache
          3. Cache dependencies
          4. Fragment caching
            1. Declaring fragment caching options
            2. Using fragment cache
          5. Page caching
        5. General performance tuning tips
          1. Using APC
          2. Disabling debug mode
          3. Using yiilite.php
          4. Using caching techniques
          5. Enabling schema caching
        6. Summary
      20. Index