Yii2 By Example
eBook - ePub

Yii2 By Example

  1. 344 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Yii2 By Example

Book details
Book preview
Table of contents
Citations

About This Book

Develop complete web applications from scratch through practical examples and tips for beginners and more advanced users

About This Book

  • Improve your programming experience and become a full stack developer
  • Master real-life web applications, and create and manage four different projects
  • Step-by-step guidance to develop real-world web applications smoothly

Who This Book Is For

This book is for anyone who wants to discover and explore Yii Framework. Basic programming experience with PHP and object oriented programming is assumed.

What You Will Learn

  • Understand basic concepts, along with the installation and customization of Yii
  • Discover models, controllers, and viewsโ€”concepts applied in a web contextโ€”and how they are employed in Yii
  • Use ActiveRecord to manipulate a database
  • Add access control to your web application through authentication and authorization
  • Install and customize an advanced template for multiple applications in the same project
  • Create a RESTful Web Service to allow remote access to data
  • Develop a console application to launch a command in the console as an automated task (cron job)
  • Make code reusable through widgets and components and localize text messages to make a multilanguage web app

In Detail

Yii is a high-performance PHP framework best for developing Web 2.0 applications. It provides fast, secure, and professional features to create robust projects, however, this rapid development requires the ability to organize common tasks together to build a complete application. It's all too easy to get confused; this is where this book comes in.

This book contains a series of practical project examples for developers starting from scratch. Each section contains the most relevant theories for every topic as you walk through developing each project, focusing on key aspects that commonly confuse users.

The book starts with all the framework's basic concepts, such as controllers and views, to introduce you to Yii and creating your first application, a simple news reader. You will be learn to configure URL rules to make a pretty URL, essential for search engine optimization. Next, you will walk through Model and ActiveRecord, key concepts in database interaction.

The second application you will develop is a reservation system that allows you to manage rooms, customers, and reservations. For this, you will use database connection through SQL and ActiveRecord. More complex than the first one, this application will introduce you to the advanced template of Yii 2, splitting the app into two parts: a frontend for all visitors and a backend for the admin. Finally, you will move on to the last two applications: one that allows connections from remote clients, through RESTful components of Yii 2, and another that creates and organizes automatic tasks using the console application structure of Yii 2.

Style and approach

This is a step-by-step guide with each topic introduced in the context of real-world applications, highlighting common cases where users may encounter difficulties.

Frequently asked questions

Simply head over to the account section in settings and click on โ€œCancel Subscriptionโ€ - itโ€™s as simple as that. After you cancel, your membership will stay active for the remainder of the time youโ€™ve paid for. Learn more here.
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
Both plans give you full access to the library and all of Perlegoโ€™s features. The only differences are the price and subscription period: With the annual plan youโ€™ll save around 30% compared to 12 months on the monthly plan.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, weโ€™ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes, you can access Yii2 By Example by Fabrizio Caldarelli in PDF and/or ePUB format, as well as other popular books in Computer Science & Programming in PHP. We have over one million books available in our catalogue for you to explore.

Information

Year
2015
ISBN
9781785287411
Edition
1

Yii2 By Example


Table of Contents

Yii2 By Example
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Starting with Yii2
Requirements and tools
Installing Yii2 with Composer
Application structure
Application properties
Common application components
Handling application events
The MVC pattern in Yii2
Naming convention
Configuring the debug toolbar
Using the logger
Example โ€“ Hello world from scratch with the Yii basic template and bootstrap template
Summary
2. Creating a Simple News Reader
Creating Controller and Action
Creating a view to display a news list
How the controller sends data to view
Example โ€“ create a controller to display the static news items list and details using the bootstrap template
Splitting the common view content into reusable views
Example โ€“ render partial in view
Creating static pages
Example โ€“ add a contact page
Sharing data between views and layout
Example โ€“ change the layout background based on a URL parameter
Layout with dynamic block
Example โ€“ add a dynamic box to display advertising info
Using multiple layouts
Example โ€“ using different layouts to create responsive and nonresponsive content layout for the same view
Summary
3. Making Pretty URLs
Using pretty URLs
Custom URL rules
Example โ€“ list news items by year or category
Default parameters in rules
Example โ€“ the index page to display the links list
The complete URL rule parameters
The URL pattern to support the multilanguage view
Creating the rule class
Summary
4. Creating a Room through Forms
Creating a Model
Example โ€“ a Model to store room data
Using ActiveForm
Example โ€“ creating a new room from the HTML form
Format date, time, and numbers
Uploading files
Example โ€“ uploading an image of a room
Summary
5. Developing a Reservation System
Configuring a DB connection
Example โ€“ creating rooms, customers, and reservations tables
Example โ€“ test connection and executing the SQL query
Using Gii to create room, customer, and reservation models
Using ActiveRecord to manipulate data
Example โ€“ query rooms list with ActiveRecord
Working with relationships
Example โ€“ using a relationship to connect rooms, reservations, and customers
How to save a model from a form
Example โ€“ creating and updating a room from a form
Setting up the GMT time zone
Using multiple database connections
Example โ€“ configuring a second DB connection to export data to a local SQLite DB
Summary
6. Using a Grid for Data and Relations
Introduction
DataProvider for grids
Using a grid
Custom columns in a grid
Example โ€“ displaying a reservations list by clicking on a customer grid row
Filters in GridView
Displaying and filtering ActiveRecord relational data in a grid's column
A summarized footer row in a grid
Example โ€“ extending GridView to customize the footer row in a grid
Multiple grids on one page
Example: managing the reservations and rooms grids in the same view
Summary
7. Working on the User Interface
Using Gii to generate CRUD
Example โ€“ using CRUD to manage rooms, reservations, and customers using Gii
Customize JavaScript and CSS
Example โ€“ using JavaScript and CSS to display advertising columns that disappear if not enough space is available
Using AJAX
Example โ€“ reservation details loaded from the customers' drop-down lists
Using the Bootstrap widget
Example: using datepicker
Multiple models in the same view
Example โ€“ saving multiple customers at the same time
Saving linked models in the same view
Example โ€“ creating a customer and reservation in the same view
Summary
8. Log in to the App
Creating a user login
Example โ€“ a login form to access
Configuring user authorization
Example โ€“ creating an ACF to authorize the users
RBAC
Example โ€“ configuring RBAC to set permissions for users
Mixing ACF and RBAC
Example โ€“ managing users' roles to access rooms, reservations, and customers
Summary
9. Frontend to Display Rooms to Everyone
Using an advanced template to split frontend and backend
Configuring an application using init
Example โ€“ creating frontend for public access
Sharing ActiveRecord models among applications
Example โ€“ displaying available rooms in the frontend site
Customizing a URL in the advanced template
Example โ€“ using the advanced template in the same domain
How to use the advanced template in the shared hosting
Summary
10. Localize the App
Setting the default language
File-based translations
Example โ€“ using file-based translation for the entire website
Placeholders formatting
DB-based translations
Example โ€“ translating room descriptions using DB
Summary
11. Creating an API for Use in a Mobile App
Configuring a REST app in the advanced template
Creating a controller
Example โ€“ creating a controller to manage rooms
Authentication
Example โ€“ using authentication to get a customers list
New controller action
Example โ€“ getting a rooms list for a reservation
Customizing authentication and response
Example โ€“ status response node in data received
Other forms of export โ€“ RSS
Example โ€“ creating an RSS with a list of available rooms
Summary
12. Create a Console Application to Automate the Periodic Task
Interacting with console applications
Creating a console controller
Example โ€“ setting an alarm flag for expired reservation
Formatting the output from the console
Implementing and executing cron jobs
Example โ€“ sending an e-mail with new reservations of the day
Summary
13. Final Refactoring
Creating widgets
Example โ€“ creating a widget with a carousel
Creating components
Example โ€“ creating a component that creates a backup of the MySQL database and sends an e-mail to the administrator
Creating modules
Generating an API documentation
Example โ€“ using an API documentation to generate a doc of app and services
Summary
Index

Yii2 By Example

Copyright ยฉ 2015 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 p...

Table of contents

  1. Yii2 By Example