- Yii2 Framework
-
Introduction & Setup
- Introduction to Yii2 Framework
- Installing Yii2 (Basic & Advanced Templates)
- Understanding Yii2 Directory Structure
- Yii2 Configuration Basics
- Routing & Pretty URLs in Yii2
-
Yii2 Core Concepts
- Yii2 Application Bootstrapping & Lifecycle
- Understanding Yii2 Request & Response Handling
- Working with Yii2 Components & Helpers
- Yii2 Widgets & Using Built-in Widgets
- Yii2 Helpers & Utility Classes
-
Models & Database Operations
- Yii2 Models, Active Record & Database Connections
- CRUD Operations in Yii2
- Yii2 Query Builder & DAO (Direct SQL Queries)
- Handling Relationships in Yii2 Active Record
- Yii2 Migrations & Seeding
-
Views, Layouts & Themes
- Yii2 Views & Layouts
- Yii2 Asset Bundles & Asset Management
- Integrating Bootstrap in Yii2
- Yii2 Theme Integration
- Yii2 Custom Widgets & Reusable Components
-
Forms, Validation & Data Presentation
- Yii2 Forms & Validation
- Using Yii2 GridView & ListView Widgets
- Yii2 Pagination & Sorting
- Yii2 File Uploads
-
Security & User Management
- User Authentication in Yii2
- Role-Based Access Control (RBAC) in Yii2
- Yii2 Security Features
-
Console Commands & Advanced Features
- Yii2 Console Commands
- Yii2 Events & Behaviors
- Yii2 RESTful API Development
- Consuming Third-Party APIs in Yii2
- Yii2 Background Jobs & Queue System
-
Performance Optimization & Caching
- Yii2 Caching Techniques
- Yii2 Performance Optimization
- Debugging & Logging in Yii2
-
Deployment & Best Practices
- Deploying Yii2 Applications
- Yii2 Best Practices & Large-Scale Application Structure
- Yii2 Multilingual & Localization Support
- Yii2 Module Development
- Integrating Yii2 with Frontend Frameworks (Angular/Vue/React)
-
Special Topics
- Dependency Injection (DI) in Yii2
Understanding Yii2 Directory Structure
Add to BookmarkYii2 follows a well-organized directory structure that adheres to the Model-View-Controller (MVC) design pattern. Whether you are using the Basic Template or the Advanced Template, understanding the directory structure is crucial for efficient development.
1. Yii2 Basic Template Directory Structure
The Basic Template is suitable for small to medium-sized applications and has the following structure:
yii2-app-basic/
│── assets/
│── commands/
│── config/
│── controllers/
│── models/
│── runtime/
│── tests/
│── vendor/
│── views/
│── web/
│── widgets/
│── yii
Key Directories in Basic Template:
- assets/ → Contains asset bundles (CSS, JS, etc.).
- commands/ → Stores console command classes (for CLI operations).
- config/ → Holds configuration files (
web.php
,console.php
,db.php
). - controllers/ → Contains controller classes that handle user requests.
- models/ → Stores model classes for interacting with the database.
- runtime/ → Stores temporary files such as logs and cache.
- tests/ → Contains automated test scripts.
- vendor/ → Third-party dependencies managed by Composer.
- views/ → Holds view files for rendering UI.
- web/ → The entry point (
index.php
) and public assets (CSS, JS, images). - widgets/ → Contains reusable UI components.
- yii → The Yii2 framework bootstrap file.
2. Yii2 Advanced Template Directory Structure
The Advanced Template is designed for enterprise applications and consists of separate frontend and backend sections, along with a shared directory for common code.
yii2-app-advanced/
│── backend/
│── common/
│── console/
│── environments/
│── frontend/
│── vendor/
Key Directories in Advanced Template:
- backend/ → Contains controllers, models, views, and assets for the admin panel.
- frontend/ → Contains controllers, models, views, and assets for the main website.
- common/ → Stores code shared between frontend and backend (e.g., models, utilities).
- console/ → Stores Yii2 console applications (for migrations, CRON jobs).
- environments/ → Configuration files for different environments (dev, prod).
- vendor/ → Third-party dependencies (like in Basic Template).
Key Configuration Files in Advanced Template:
- common/config/main.php → Common application settings.
- common/config/main-local.php → Localized settings (like database credentials).
- backend/config/main.php → Backend-specific configurations.
- frontend/config/main.php → Frontend-specific configurations.
- console/config/main.php → Console application configurations.
3. Yii2 Follows the MVC Pattern
Yii2 is based on MVC architecture, which separates an application into three interconnected parts:
- Model (
models/
) → Manages data and business logic. - View (
views/
) → Handles the presentation layer (UI). - Controller (
controllers/
) → Receives user requests, processes them, and returns responses.
For example, when a user visits site/index
:
- The controller (
SiteController.php
) processes the request. - The model (
Post.php
) fetches data from the database (if needed). - The view (
views/site/index.php
) renders the response.
4. Best Practices for Organizing Code
- Follow Yii2’s directory structure to maintain code clarity.
- Place reusable components in widgets/.
- Keep business logic separate by using models/ instead of writing queries inside controllers.
- Store configuration in config/ instead of hardcoding values.
This tutorial provides a comprehensive understanding of Yii2’s directory structure. In the next tutorial, we will explore Yii2's configuration files and environment settings to customize our application.
Prepare for Interview
- SQL Interview Questions for 2–5 Years Experience
- SQL Interview Questions for 1–2 Years Experience
- SQL Interview Questions for 0–1 Year Experience
- SQL Interview Questions for Freshers
- Design Patterns in Python
- Dynamic Programming and Recursion in Python
- Trees and Graphs in Python
- Linked Lists, Stacks, and Queues in Python
- Sorting and Searching in Python
- Debugging in Python
- Unit Testing in Python
- Asynchronous Programming in PYthon
- Multithreading and Multiprocessing in Python
- Context Managers in Python
- Decorators in Python
Random Blogs
- Python Challenging Programming Exercises Part 2
- What Is SEO and Why Is It Important?
- Mastering SQL in 2025: A Complete Roadmap for Beginners
- Python Challenging Programming Exercises Part 1
- Role of Digital Marketing Services to Uplift Online business of Company and Beat Its Competitors
- Understanding AI, ML, Data Science, and More: A Beginner's Guide to Choosing Your Career Path
- Datasets for Natural Language Processing
- Types of Numbers in Python
- Top 10 Blogs of Digital Marketing you Must Follow
- String Operations in Python
- Store Data Into CSV File Using Python Tkinter GUI Library
- Transforming Logistics: The Power of AI in Supply Chain Management
- How AI Companies Are Making Humans Fools and Exploiting Their Data
- Best Platform to Learn Digital Marketing in Free
- Why to learn Digital Marketing?
Datasets for Machine Learning
- Amazon Product Reviews Dataset
- Ozone Level Detection Dataset
- Bank Transaction Fraud Detection
- YouTube Trending Video Dataset (updated daily)
- Covid-19 Case Surveillance Public Use Dataset
- US Election 2020
- Forest Fires Dataset
- Mobile Robots Dataset
- Safety Helmet Detection
- All Space Missions from 1957
- OSIC Pulmonary Fibrosis Progression Dataset
- Wine Quality Dataset
- Google Audio Dataset
- Iris flower dataset
- Artificial Characters Dataset