Unity University: College of Engineering, Technology and Computational Science Department of Computer Science and MIS
Unity University: College of Engineering, Technology and Computational Science Department of Computer Science and MIS
Instructor
MR. Ephrem Tesfaye
April-08-2023
Contents
1|Page
Abstract.......................................................................................................................................................3
Introduction.................................................................................................................................................4
1.0 The Previous and latest versions of YII framework.........................................................................5
1.1 Previous Version (YII 1.x):.............................................................................................................5
1.2 Latest Version (YII 2.x):..................................................................................................................6
2.0 From which language does YII developed.......................................................................................8
3.0 Advantages and Disadvantages of using YII...................................................................................9
4.0 Basic implementation of YII (How to use)....................................................................................10
5.0 For what types of system(Applications) does YII Applied............................................................11
6.0 Example of existing systems developed by the framework............................................................12
7.0 Sample code using YII...................................................................................................................13
8.0 Relating the sample code with other code written using pure programming language...................14
Summary...................................................................................................................................................17
Reference...................................................................................................................................................18
2|Page
YII framework
Abstract
The YII framework is a powerful and efficient web development framework that offers high
performance and a rich feature set. It follows the Model-View-Controller architectural pattern
and provides built-in tools and features for caching, authentication, and internationalization.
With extensive documentation and active community support, YII is a compelling option for
developers looking to build modern and efficient web applications. This file discusses the
advantages and disadvantages of using YII, compares the previous and latest versions of the
framework, explores its development language, and highlights the applications for which YII is
commonly used. Overall, YII is a reliable and popular option for web development, offering a
wealth of features, performance optimizations, and a supportive community.
Introduction
3|Page
The YII (yes it is) framework is a powerful and efficient web development framework that has
gained popularity around the world. It is known for its high performance and rich feature set,
making it an excellent choice for building robust and scalable web applications. YII follows the
Model-View-Controller (MVC) architectural pattern, which allows for clean separation of
concerns and promotes code reusability. It also provides a wide range of built-in tools and
features, such as caching, authentication, and internationalization, which greatly simplify the
development process. With its extensive documentation and active community support, YII is a
compelling option for developers looking to build modern and efficient web applications.
One of the key advantages of YII framework is its high performance. It is designed to be
lightweight and highly optimized for speed, making it an ideal choice for developing large-scale
applications with heavy traffic and complex functionality. YII achieves this by utilizing features
like lazy loading, caching, and query optimization, ensuring that the application responds quickly
to user requests.
Another notable feature of YII is its robust set of built-in security measures. The framework
includes various security features, such as input validation, output filtering, encryption, and
authentication. These features help developers build secure applications that are protected against
common web vulnerabilities like cross-site scripting (XSS), SQL injection, and cross-site request
forgery (CSRF).
Furthermore, YII offers a wide range of tools and utilities to streamline the development process.
It provides a command-line tool called Gii, which automates the generation of code, saving
developers time and effort. YII also supports a large number of extensions and widgets, which
can be easily integrated into the application to enhance its functionality.
In conclusion, YII framework is a powerful and efficient tool for developing web applications.
Its performance, security features, and developer-friendly tools make it an attractive choice for
building scalable and secure websites or web applications. Whether you are a beginner or an
4|Page
experienced developer, YII offers a solid foundation and an intuitive API that greatly simplifies
the development process.
YII is a high-performance, component-based PHP framework that is widely used for developing
robust and scalable web applications. Let's compare the previous and latest versions of YII:
YII 1.x was the first major release of the framework and gained substantial popularity for its
simplicity, extensibility, and excellent performance. It offered many features, including MVC
architecture, active-record, data caching, RBAC (Role-Based Access Control), client-side
validation, and internationalization support. Though it was highly regarded, YII 1.x faced some
limitations in terms of code reusability and scalability.
YII 1 is the first version of the YII framework, which was released in 2008. It quickly gained
popularity among developers in worldwide for its simplicity, performance, and ease of use. YII 1
follows the Model-View-Controller (MVC) architectural pattern, allowing for clean separation of
concerns and promoting code reusability.
One of the key features of YII 1 is its powerful and flexible code generator, GII, which helps
developers to quickly generate code for models, controllers, and views, reducing development
time. It also provides a rich set of tools and features, including caching, authentication, and
internationalization, making it easier to develop feature-rich web applications.
YII 1 incorporates various performance optimizations, such as lazy loading and efficient query
handling, which contribute to its fast execution speed. It also has excellent support for databases,
including popular ones like MySQL, PostgreSQL, and Oracle.
YII 1 has a large and active community, providing extensive documentation, tutorials, and
forums for developers to seek help and share knowledge. Although YII 1 is an older version, it
still remains a viable option for developers who prefer a stable and mature framework for their
web development projects.
YII 2.x is the most recent stable version of the framework, which introduced significant
improvements and enhancements over its predecessor. It addressed the limitations of YII 1.x and
embraced modern PHP development practices and technologies. Some key features of YII 2.x
include a more refined and modular architecture, improved security measures, enhanced testing
support, robust error handling, RESTful API development, better query builder functionality,
dependency injection container, and advanced caching mechanisms.
One notable change in YII 2.x is the adoption of Composer as the standard package manager,
allowing developers to easily integrate third-party libraries into their projects. The latest version
also focuses on better integration with frontend frameworks like Bootstrap and Vue.js, making it
more suitable for building modern, responsive web applications.
YII 2 also introduced a more robust and efficient implementation of the Model-View-Controller
(MVC) pattern, providing better separation of concerns and promoting code organization.
YII 2 comes with a wide range of built-in features and tools that simplify the development
process. It includes powerful caching mechanisms, authentication and authorization components,
and support for internationalization and localization. These features enable developers to build
secure, scalable, and user-friendly web applications more efficiently.
Another significant enhancement in YII 2 is its integration with popular third-party libraries and
frameworks. It seamlessly integrates with technologies like Bootstrap, jQuery, and SwiftMailer,
allowing developers to leverage the capabilities of these tools within their YII applications.
YII 2 also offers excellent performance optimizations, including aggressive query caching, lazy
loading of components, and efficient asset management. These optimizations contribute to faster
page load times and improved overall performance of YII 2 applications.
The YII 2 framework has a vibrant and active community, providing extensive documentation,
tutorials, and forums for developers to seek assistance and share their knowledge. It remains a
6|Page
popular choice for developers in who seek a modern, feature-rich, and well-supported framework
for building their web applications.
On the other hand, YII 2 brought substantial improvements and modernization to the framework.
With its modular and extensible architecture, enhanced performance optimizations, and
integration with popular libraries, YII 2 offered developers a more flexible and feature-rich
development experience. It also provided a wide range of built-in tools and components, making
it easier to develop secure and scalable web applications.
YII 3 is currently under development. It aims to further enhance the framework's performance,
flexibility, and ease of use. YII3 is being built with a focus on modern PHP standards and
practices, such as PSR-7 for HTTP, DI containers, and improved testing support. It also aims to
provide better interoperability with other frameworks and libraries. While YII 3 is not yet stable
for production use, Developers are eagerly anticipating its release for building cutting-edge web
applications.
In conclusion, both YII 1 and YII 2 have made significant contributions to the web development
landscape in worldwide. YII 1, as the first version of the framework, provided developers with a
simple, performant, and reliable solution for building web applications. It offered powerful code
generation tools, excellent database support, and a large and active community.
Both versions of YII have their own strengths and cater to different needs. YII 1 remains a stable
choice for developers who prefer a mature framework, while YII 2 offers a more modern and
flexible approach for those seeking the latest features and enhancements.
Ultimately, the choice between YII 1 and YII 2 depends on the specific requirements of the
project and the preferences of the developer. Regardless of the version chosen, the YII
framework continues to be a reliable and popular option for web development offering a wealth
of features, performance optimizations, and a supportive community.
YII (Yes It Is) framework was primarily developed by Qiang Xue. Qiang Xue is a software
engineer and a prominent figure in the PHP community. He created YII with the aim of
7|Page
providing a high-performance, secure, and flexible PHP framework for web application
development.
Qiang Xue started working on YII in 2008 and released the first version, YII 1.0, in December
2008. Over the years, he continued to lead the development of YII, incorporating community
feedback and contributions.
Additionally, YII has a strong and active open-source community of developers who have
contributed to its development and improvement. The community has played a significant role in
expanding the features, providing bug fixes, and enhancing the overall framework.
Qiang Xue's vision and leadership, along with the contributions from the YII community, have
made YII a popular choice for PHP developers seeking a robust and efficient framework for
building web applications.
The YII framework is developed primarily using the PHP programming language. PHP, which
stands for Hypertext Preprocessor, is a popular and widely-used server-side scripting language
specifically designed for web development. It is known for its simplicity, flexibility, and ease of
integration with various web technologies.
YII utilizes the power and versatility of PHP to provide a comprehensive framework for building
web applications. It leverages PHP's extensive libraries, functions, and syntax to create a robust
and efficient development environment. PHP allows YII to handle server-side processing,
interact with databases, and generate dynamic HTML content.
In addition to PHP, YII also incorporates other web technologies such as HTML, CSS, and
JavaScript. These languages are used for defining the structure, styling, and interactivity of web
pages. By combining PHP with these front-end languages, YII enables developers to create
dynamic, feature-rich, and visually appealing web applications.
Overall, YII's development is rooted in PHP, which serves as the foundation for its functionality
and extensibility. With the support of PHP and other web technologies, YII provides a powerful
framework for developers to build robust and scalable web applications.
8|Page
YII framework is a popular web development framework that offers several advantages for
developers. Some of the advantages include:
1. Learning Curve: YII framework has a steeper learning curve compared to some other
frameworks. It may take some time for developers to grasp its concepts and best
practices.
2. Lack of Flexibility: While YII framework provides a solid foundation for web
development, it may not be as flexible as some other frameworks. Customizing certain
aspects of the framework or integrating third-party libraries might require more effort.
3. Documentation: Although YII framework has comprehensive documentation, it may not
be as extensive or beginner-friendly as some other frameworks. Developers may need to
rely on community resources or external tutorials to find answers to specific questions or
problems.
Overall, YII framework can be a powerful choice for web development projects in Ethiopia,
offering high performance, security, and rapid development capabilities. However, developers
9|Page
should consider the learning curve and flexibility aspects before deciding to use it in their
projects.
To provide a basic implementation of using the YII framework, follow these steps:
Install YII: Start by downloading and installing YII framework on your local
development environment or server. You can find the installation guide and the necessary
files on the official YII website.
Create a new YII project: Use the YII command-line tool called "YII Console" to create a
new project. Open your terminal or command prompt, navigate to the desired directory,
and run the following command:
Copy
YII create-project --prefer-dist YIIsoft/YII2-app-basic <project-name>
Replace <project-name> with the desired name for your project.
Configure your project: YII provides a configuration file (config/web.php) where you can
set up your project settings, such as database connection, URL rules, and other
application components. Edit this file to match your requirements.
Create a controller: YII follows the MVC pattern, so you need to create a controller to
handle the application's logic. In the controllers directory, create a new PHP file,
e.g., SiteController.php, and define a class that extends YII\web\Controller. Add action
methods inside the class to handle different requests.
Create a view: In the views directory, create a subdirectory with the same name as your
controller (e.g., site). Inside that directory, create a PHP file for each action method in
your controller. These view files will contain the HTML markup and presentation logic
for each page.
Define routes: In the config/web.php file, you can configure URL rules using
the urlManager component. This allows you to define user-friendly URLs that map to
your controller actions.
Access your application: Start a local web server or upload the project to your hosting
server. Access your application by entering the URL in your web browser. You should be
10 | P a g e
able to see the default YII welcome page or the page you defined in your controller and
view.
This basic implementation will get you started with YII. You can then explore more advanced
features, such as models, database interactions, authentication, and additional components
provided by the framework, to build more complex and feature-rich web applications.
YII (Yes It Is) is a high-performance PHP framework that can be applied to various types of
systems. Here are some of the best applications for YII:
Web Applications: YII is well-suited for developing complex web applications with
features like user authentication, role-based access control, and caching. It provides a
robust architecture that ensures scalability and security.
Content Management Systems (CMS): YII's modular structure and extensibility make it a
great choice for building CMS platforms. It offers features like user management, content
publishing, and customizable templates, making it ideal for creating dynamic websites.
E-commerce Platforms: YII's ability to handle large amounts of data and its support for
database abstraction make it suitable for developing e-commerce systems. It provides
tools for managing products, orders, and payments, facilitating the creation of secure and
efficient online stores.
Enterprise Resource Planning (ERP) Systems: YII's performance and scalability make it a
good fit for developing ERP systems. It allows for managing various business processes,
such as inventory management, human resources, and accounting, providing a
comprehensive solution for organizations.
Social Networking Platforms: YII's MVC (Model-View-Controller) architectural pattern
and built-in features like user authentication and authorization make it suitable for
building social networking platforms. It enables the creation of user profiles, messaging
systems, and activity feeds.
These are just a few examples of the types of systems that YII can be applied to. Its versatility
and flexibility make it a popular choice for developing a wide range of applications.
11 | P a g e
6.0 Example of existing systems developed by the framework
These are just a few examples of the existing systems developed using the YII framework. YII's
flexibility, performance, and extensive feature set make it a popular choice for building robust
and scalable applications.
namespace app\controllers;
use YII\web\Controller;
12 | P a g e
use app\models\Post;
$posts = Post::find()->all();
$post = Post::findOne($id);
if (!$post) {
In the above code, we have a PostController class that extends the Controller class. It includes
two action methods: actionIndex() and actionView($id).
In the actionIndex() method, we retrieve all posts from the Post model using the find() method
and pass them to the index view template for rendering.
13 | P a g e
In the actionView($id) method, we retrieve a specific post based on the provided $id parameter
using the findOne() method. If the post does not exist, we throw a NotFoundHttpException.
Otherwise, we pass the post to the view view template for rendering.
This code showcases a more structured approach, utilizing the YII model to fetch data and
handle exceptions gracefully.
Remember, this is just a brief sample to demonstrate a well-designed code structure. In a real-
world application, you would implement additional features, validation, and security measures.
8.0 Relating the sample code with other code written using pure programming
language
class PostController
$posts = $this->getAllPosts();
include 'views/index.php';
$post = $this->getPostById($id);
if (!$post) {
14 | P a g e
throw new Exception('The requested post does not exist.');
include 'views/view.php';
// Code logic to retrieve all posts from the database or any data source
// ...
// Code logic to retrieve a specific post from the database or any data source
// ...
In the pure PHP code equivalent, we have a PostController class that doesn't rely on any
framework. It includes the same action methods: index() and view($id). However, there are a
few differences:
15 | P a g e
In the YII framework code, we extend the Controller class provided by YII. In the pure PHP
code, we don't have any inheritance from a framework-specific class.
The YII framework code uses the render() method to render the view templates, while the pure
PHP code includes the view template files directly using include statements.
In the YII framework code, we utilize the Post model to fetch posts from the database using the
framework's query methods. In the pure PHP code, we have separate private methods
(getAllPosts() and getPostById($id)) to handle data retrieval.
The YII framework code throws a NotFoundHttpException when a requested post doesn't exist,
while the pure PHP code throws a generic Exception.
The YII framework code leverages the framework's routing system to map URLs to actions
automatically. In the pure PHP code, we would need to handle routing separately.
It's important to note that frameworks like YII provide additional features, such as routing,
database abstraction, and built-in security measures, which can simplify development and
provide a standardized structure. Pure PHP code requires more manual implementation of these
features.
These examples demonstrate the differences between using a framework like YII and writing
code in pure PHP. The choice between using a framework or pure PHP depends on the specific
requirements, complexity, and scalability of the project.
Summary
YII (yes it is) is a high-performance, component-based PHP framework that enables developers
to rapidly develop web applications. The framework provides efficient tools and features to
handle common web development tasks, allowing developers to focus on writing clean and
maintainable code.
It has two versions which are YII(1) and YII(2) and also currently developing YII(3)
16 | P a g e
The YII framework is developed primarily using the PHP programming language. PHP, which
stands for Hypertext Preprocessor, is a popular and widely-used server-side scripting language
specifically designed for web development. It is known for its simplicity, flexibility, and ease of
integration with various web technologies
It offers several advantages for developers. Some of the advantages include high performance,
security, rapid development, extensibility
YII (Yes It Is) is a high-performance PHP framework that can be applied to a variety of systems.
It is well-suited for developing complex web applications, content management systems, e-
commerce platforms, enterprise resource planning systems, and social networking platforms. It
offers features such as user authentication, role-based access control, caching, and modular
structure, making it versatile and flexible for the development of various applications. Some
examples of existing systems developed using YII include Hum-Hub, an open-source social
networking platform, OSEM, an event management system, Snipe-IT, an IT asset management
system, Invoice Ninja, an invoicing and billing platform, and Next-cloud, a file hosting and
collaboration platform. YII's performance, scalability, and extensive feature set make it a popular
choice for building robust and scalable applications.
Reference
"Yii Rapid Application Development Hotshot" by Lauren J. O'Meara
"Yii Application Development Cookbook - Third Edition" by Alexander Makarov and Dmitry
Eliseev
"Agile Web Application Development with Yii1.1 and PHP5" by Jeffrey Winesett
17 | P a g e
"Yii2 By Example" by Fabrizio Caldarelli
18 | P a g e