Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Yii Application Development Cookbook - Second Edition

You're reading from   Yii Application Development Cookbook - Second Edition This book is the perfect way to add the capabilities of Yii to your PHP5 development skills. Dealing with practical solutions through real-life recipes and screenshots, it enables you to write applications more efficiently.

Arrow left icon
Product type Paperback
Published in Apr 2013
Publisher Packt
ISBN-13 9781782163107
Length 408 pages
Edition 2nd Edition
Languages
Tools
Arrow right icon
Toc

Table of Contents (20) Chapters Close

Yii Application Development Cookbook Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Under the Hood 2. Router, Controller, and Views FREE CHAPTER 3. AJAX and jQuery 4. Working with Forms 5. Testing Your Application 6. Database, Active Record, and Model Tricks 7. Using Zii Components 8. Extending Yii 9. Error Handling, Debugging, and Logging 10. Security 11. Performance Tuning 12. Using External Code 13. Deployment Index

Implementing single table inheritance


Relational databases do not support inheritance. If we need to store inheritance in the database, we should somehow support it through code. This code should be efficient, so it should generate as few JOINs as possible. A common solution to this problem was described by Martin Fowler and is named as single table inheritance.

When we use this pattern, we store all the class tree data in a single table and use the type field to determine a model for each row.

As an example, we will implement the single table inheritance for the following class tree:

Car
 |- SportCar
 |- FamilyCar

Getting ready

  1. Create a new application by using yiic webapp as described in the official guide.

  2. Create and set up a database. Add the following table:

    CREATE TABLE `car` (
        `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
        `name` varchar(255) NOT NULL,
        `type` varchar(100) NOT NULL,
        PRIMARY KEY (`id`)
    );
    
    INSERT INTO `car` (`name`, `type`)
    VALUES ('Ford Focus', 'family')...
lock icon The rest of the chapter is locked
Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Yii Application Development Cookbook - Second Edition
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Modal Close icon
Modal Close icon