You are previewing Kohana 3.0 Beginner’s Guide.
O'Reilly logo
Kohana 3.0 Beginner’s Guide

Book Description

Develop professional web applications with Kohana.

  • The first and only book on the Kohana 3 PHP framework.

  • Covers all major areas needed to begin developing web applications with Kohana

  • Covers complete development cycle from installation to deployment

  • Easy to follow instructions that help you build a working example application during the course of the book

  • In Detail

    Modern web development relies heavily on the ability to rapidly create applications that are reliable, maintainable, and scalable. The PHP-based Kohana framework has proven to be one of the best platforms for delivering professional quality applications using a stable framework that allows you to build great web properties while leveraging a rapid development architecture that is both powerful and intuitive.

    Kohana 3 Beginner’s Guide is the first and only book in the market for learning about this popular and powerful open-source PHP framework. Written with the beginner in mind, this book walks you through installation and configuration, then uses a case study site to deliver real world solutions to common web development needs.

    Beginning with the installation and configuration of the framework, you are guided through the steps necessary to get up and running, and are quickly introduced to the basics of Kohana.

    Using a case study site as an example, the book illustrates core components of Kohana while showing elegant solutions to real world tasks developers face every day. From working with forms to databases, interacting with users to deploying applications in the wild, everything is covered in simple, easy to understand examples.

    By the end of this book you will have mastered the core tasks needed to build great web applications using

    A step-by-step guide to creating professional web applications using the Kohana framework.

    Table of Contents

    1. Kohana 3.0 Beginner's Guide
      1. Kohana 3.0 Beginner's Guide
      2. Credits
      3. About the Author
      4. About the Reviewers
      5. www.PacktPub.com
        1. Support files, eBooks, discount offers and more
          1. Why Subscribe?
          2. Free Access for Packt account holders
      6. Preface
        1. Brief history of Kohana
        2. Kohana's user guide and API reference
        3. Structure and patterns
        4. HMVC in a nutshell
        5. Models, Views, and Controllers
        6. Alternative syntax
        7. Routing and request overview
        8. What this book covers
        9. Who this book is for
        10. Conventions
        11. Time for action—heading
          1. What just happened?
          2. Pop quiz—heading
          3. Have a go hero—heading
        12. Reader feedback
        13. Customer support
          1. Errata
          2. Piracy
          3. Questions
      7. 1. Getting Started
        1. System requirements
        2. Case Study
        3. Downloading and installing from the Web
        4. Time for action—Downloading from web
          1. What just happened?
        5. Installing Kohana from GitHub
        6. Time for action—downloading using Git
          1. What just happened?
          2. Advanced installation with Git
          3. Taking inventory
          4. Preparing the Filesystem
        7. Testing the environment
        8. Configuring Kohana for Development Environment
        9. Time for action—Setting your Timezone
          1. What just happened?
          2. Configuring URL settings
        10. Time for action—setting base URL
          1. What just happened?
          2. Setting up the Application Environment
        11. Time for action—Setting Kohana::$environment
          1. What just happened?
          2. Enabling modules
        12. Time for action—Enabling the User Guide
          1. What just happened?
          2. Creating a default config file
          3. Server configuration
            1. Configuring Apache
            2. Configuring nginx
        13. Testing your configuration
          1. Pop quiz—Installation and Configuration
        14. Summary
      8. 2. Using Views and Controllers
        1. What are controllers and views?
          1. Anatomy of a view
          2. Anatomy of a controller
        2. Updating our Welcome Controller
        3. Time for action—Getting our controller action to use a view file
          1. What just happened?
        4. Passing data to the view
          1. Using the factory( ) method
        5. Time for action—Passing data via the factory method
          1. What just happened?
          2. Using view variables
        6. Time for action—Passing data as view variables
          1. What just happened?
          2. Using the set( ) method
        7. Time for action—Passing data using the set() method
          1. What just happened?
          2. Using the bind( ) method
        8. Time for action—Passing data using the bind( ) method
          1. What just happened?
          2. Putting it all together
        9. Time for action—Passing data using multiple methods
          1. What just happened?
          2. Pop quiz—Controller conventions and View variables
        10. Using the Template Controller
        11. Time for action—Extending Kohana's Template Controller
          1. What just happened?
          2. Examining the Template controller
          3. Have a go hero—Explore controllers and view variables
          4. Setting global view variables
        12. Time for action—Setting global view variables
          1. What just happened?
          2. Binding global view variables
        13. Time for action—Binding global view variables
          1. What just happened?
          2. Beyond the Welcome Controller
        14. Creating new controllers
        15. Time for action—Creating our first controller
          1. What just happened?
        16. Time for action—Expanding on our first controller
          1. What just happened?
        17. Creating a base controller
        18. Time for action—Creating an abstract controller
          1. What just happened?
          2. Pop quiz—Controllers and views
        19. Putting it all together
        20. Time for action—Adding stylesheets to template
          1. What just happened?
          2. Adding structure to view files
        21. Time for action—Adding header and footer view files
          1. What just happened?
          2. Have a go hero—Customize quickly and easily
        22. Summary
      9. 3. Routing and Request Handling
        1. Hierarchy is King in Kohana
          1. Cascading filesystem
        2. Request flow in Kohana
        3. Using the Request object
          1. Creating a profile page to render messages
        4. Time for action—Creating a profile page with messages
          1. What just happened?
          2. Calling a new request inside a request
        5. Time for action—Creating a request within a request
          1. What just happened?
          2. Have a go hero—Create a request from within a view
        6. Routing in Kohana
        7. Time for action—Making profiles dynamic using ID
          1. What just happened?
          2. Creating friendly URLs using custom routes
        8. Time for action—Creating a Custom Route
          1. What just happened?
          2. Making routes explicit
        9. Time for action—Adding regex to a route
          1. What just happened?
          2. Allowing additional data in a URI
        10. Time for action—Allowing additional segments in a route
          1. What just happened?
          2. Using subdirectories with routes
        11. Time for action—Using Subdirectories and Routes
          1. What just happened?
          2. Pop quiz—Understanding Routes and the Kohana Filesystem
        12. Summary
      10. 4. Working with Helpers and Classes
        1. Autoloading classes
        2. Introducing helpers
          1. The Date class
          2. Have a go hero—Customizing fuzzy date text
          3. The HTML Class
            1. The HTML::chars() method
            2. The HTML::obfuscate() method
              1. The HTML::email() method
            3. The HTML::anchor() method
            4. The HTML::image() method
            5. The HTML::mailto() method
          4. The Inflector Class
          5. The URL class
            1. The URL::title() method
            2. The URL::base() method
            3. The URL::query() method
          6. The Arr (Array) Class
            1. The Arr::get() method
            2. The Arr::extract() method
            3. The Arr::pluck() method
            4. The Arr::merge() method
            5. The Arr::overwrite() method
            6. The Arr::flatten() method
            7. The Arr::unshift() method
            8. The Arr::map() method
            9. The Arr::is_array() method
            10. The Arr::range() method
          7. The Cookie class
          8. The Encrypt (Encryption) Class
        3. Time for action—Creating configuration for Encryption
          1. What just happened?
          2. The Feed Class
          3. The Form Class
        4. Time for action—Creating a login form using the Form helper class
          1. What just happened?
        5. Time for action—Creating a signup form for new users
          1. What just happened?
          2. Have a go hero—Creating a lost password reset form
        6. Extending Helpers
          1. Transparent Class Extension
        7. Time for action—Extending the HTML helper method
          1. What just happened?
          2. Creating your own helpers
        8. Summary
      11. 5. Installing and Configuring Modules
        1. Anatomy of a Module
        2. Loading and configuring modules
        3. Bundled modules
          1. User guide module
          2. Image module
          3. oAuth module
          4. Database and ORM modules
        4. Time for action—Configuring your application to use a database
          1. What just happened?
        5. Time for action—Creating a database table and using the query builder
          1. What just happened?
          2. Pagination module
        6. Time for action—Adding pagination to database results
          1. What just happened?
          2. Have a go hero—Explore the Pagination module
          3. Auth module
          4. Code Bench module
          5. Cache and Unit Test modules
        7. Installing modules
          1. Installing modules from source files
        8. Time for action—Installing a module from an archive
          1. What just happened?
          2. Installing modules via Git
        9. Time for action—Installing a module using git
          1. What just happened?
        10. Creating your own modules
          1. Pop quiz—Working with Modules
        11. Summary
      12. 6. Interacting with the Database
        1. Anatomy of a model
          1. Creating models
        2. Using the Database module
          1. Configuring the Database module
          2. Creating and running queries
          3. Using the Query Builder
            1. Select statements
            2. Using results
        3. Time for action—Refactoring Model_Message to allow dynamic search
          1. What just happened?
          2. Have a go hero—Adding new messages page using query builder
            1. Insert statements
        4. Time for action—Adding the ability to insert messages in case study site
          1. What just happened?
            1. Updating statements
        5. Time for action—Add ability to edit messages in case study site
          1. What just happened?
            1. Delete statements
        6. Time for action—Add ability to delete messages from the case study site
          1. What just happened?
            1. Other functions and expressions
        7. Using the Database Module with sessions
          1. Configuring database sessions
        8. Time for action—Adding session handling with the database adapter
          1. What just happened?
          2. Using Database Sessions
          3. Pop quiz—Using the Database Module
        9. Summary
      13. 7. Using the ORM and Auth Modules
        1. Using the ORM module
          1. Setting up the ORM module
            1. Convention over configuration
            2. ORM API Overview
        2. Time for action—Updating Message Model to use ORM
          1. What just happened?
          2. ORM, Forms, and Validation
            1. The Validation class
        3. Time for action—Adding validation to Message Model
          1. What just happened?
          2. ORM and Relational Data
        4. Using the Auth module
          1. Configuring the Auth module
        5. Time for action—Adding users and Auth to case study site
          1. What just happened?
          2. Implementing the Auth module
        6. Time for action—Adding the Auth functionality to the case study site
          1. What just happened?
          2. Securing controllers and actions
        7. Time for action—Adding secure actions to the case study site
          1. What just happened?
          2. Have a go hero—Adding new messages page using query builder
          3. Pop quiz—Using the ORM and Auth modules
        8. Summary
      14. 8. Troubleshooting and Error Handling
        1. Debugging code with Kohana
          1. Debugging with the Kohana class
          2. Error and exception handling
        2. Time for action—Adding error messages to signup form
          1. What just happened?
          2. Have a go hero—Add error messages to login form
          3. Disabling the error handler
          4. Viewing the error logs
        3. Handling 404 redirects
        4. Time for action—Adding a custom 404 page
          1. What just happened?
        5. Profiling our applications
        6. Time for action—Adding profiling to the case study project
          1. What just happened?
          2. Pop quiz—Troubleshooting and Error Handling
        7. Summary
      15. 9. Securing and Deploying Kohana 3
        1. Securing our applications
          1. XSS attacks
        2. Time for action—Securing against XSS risks
          1. What just happened?
          2. SQL injection
          3. Cookies and sessions
            1. Securing cookies
            2. Securing sessions
          4. Configuring the application environment
        3. Preparing for production
          1. Removing unnecessary files
          2. Directory structure considerations
          3. Have a go hero—Structure case study site for production
            1. Multiple Application Configuration
          4. Updating the Configuration settings
          5. Pop quiz—Preparing an application for production
        4. Summary
      16. A. Upgrading from CodeIgniter and Kohana 2
        1. What makes Kohana different from CodeIgniter?
        2. Moving from CodeIgniter to Kohana
          1. Autoloading classes
          2. Strict PHP 5 codebase
          3. Included ORM
          4. Modules
        3. Moving from Kohana 2.x
          1. GET and POST methods
          2. Directory structure
          3. Naming conventions
          4. Views
          5. Updated ORM
          6. Routing and requests
        4. Upgrading from Kohana 3.0 to 3.1
          1. Request and response classes
          2. Security enhancements
          3. Bootstrapping and the front controller
          4. Validation library
          5. Other changes