Hosting & Domaining Forum

Hosting & Domaining development => Programming Discussion => Databases => Topic started by: uTracevv on Jul 17, 2023, 12:11 AM

Title: Yii Framework for Web Development
Post by: uTracevv on Jul 17, 2023, 12:11 AM
I have been programming in PHP for a long time, creating websites, online stores, and my own admin panel. However, despite my experience, I don't consider myself a programmer because I worked alone and didn't have anyone to learn from. Now I want to move to the next level and start writing more sophisticated code.

After researching options, I decided to explore using a framework and settled on Yii. Since I have never worked with frameworks before, I'm still trying to understand what exactly a "framework" is. I used to think it was just a collection of pre-built classes that solve common programming problems. However, I now realize that a framework is more than that. For example, Yii provides a ready-to-use web application architecture and database structure, serving as a foundation on which you can build your own applications.

Question 1: When working with Yii, does the "ready-made framework" refer to the client-side (frontend) or the administrative framework (backend)? Or is a framework simply a pre-defined file structure with classes and a database, while the client and admin parts have to be developed based on this framework? I apologize if my question is not clear; I'm trying to organize my thoughts and gain a better understanding.

When coding from scratch in PHP, I create the client-side of the website, including index.php, template files, classes, and databases. I also develop the admin section, which has its own index, templates, etc. In Yii, am I required to build the admin panel from scratch using framework classes, or does the admin part already exist and I just need to customize it according to my needs?

Question 2: To illustrate my question, let's say the website has sections such as "news," "articles," "events," "questions/answers," etc. I refer to all these sections as "lists." Each list has its own corresponding table in the database, like "articles." In the admin part of the site, I create a section where users can "add/edit/delete" elements of this list (articles). The admin section provides a template with a form including fields like "title," "text," "author," etc., specific to articles (each list has its own set of characteristics). Is the process of creating these "lists" and adding new tables (e.g., adding a table for "authors" when there are already news and articles) as automated as possible in Yii? Or do I have to manually create the table in the database ("authors" table), add columns, create a new section in the admin part, templates for editing it, a class to handle authors, etc., as I currently do?
Title: Re: Yii Framework for Web Development
Post by: vradeshoz on Jul 17, 2023, 01:54 AM
Question 1: In Yii, you don't have to build the admin panel from scratch using framework classes. Yii provides a set of predefined classes and components that you can use to create the backend functionality of your application. These classes handle common tasks like authentication, authorization, database access, and user management. You can customize and extend these classes to fit your specific needs without having to start from scratch.

Question 2: To create a new "list" like "authors," you can use Gii to generate the model class and CRUD operations for the authors table. This will automatically create the necessary files and code for adding/editing/deleting authors from the admin section. You can then customize the generated templates and add additional functionality if needed.

Overall, Yii aims to provide a framework that reduces repetitive tasks and helps you focus on building the specific features of your application. While there may still be some manual work involved in customizing and extending the framework, Yii provides many tools and conventions to make development more efficient.
Title: Re: Yii Framework for Web Development
Post by: makloy143 on Jul 17, 2023, 03:40 AM
I think it's important to start by studying the principles of OOP in general, followed by an understanding of MVC so that you can use the correct terminology effectively.
Now it seems like everything is quite confusing.

You are getting mixed up between the ideas of a framework and a CMS.

1. Yes, this is simply a framework, which means that you will have to write everything from scratch.
Yii has gii — a code generator that simplifies many repetitive tasks.
2. Here, you are referring to models and inheritance.
3. Yii provides a great deal of flexibility.
4. Some people use it solely for learning purposes. Lack of experience with such tools might make you perceive it as something extraordinary, but in reality, it is much simpler.

In that case, I suggest taking a look at www.phptherightway.com/. It might offer some additional insights on the topic.
Title: Re: Yii Framework for Web Development
Post by: Hodgibdiz on Jul 17, 2023, 05:32 AM
By and large, there is no specific framework in place. The current webapp serves as an illustration of how various implementations can be achieved.

 

Primarily, the framework consists of the original folder structure, which can be easily modified if you delve into the underlying structure.

 

After completing the webapp, we remove everything from protected/controllers, protected/models, protected/views, protected/data, and basically everything else, although I'm not entirely certain.

 

At this point, we have a clean version that can be further developed.

 

How should we proceed? Initially, there is no clear distinction between frontend and backend functionalities, but this can be resolved by devising or adopting a plan with predefined standard modules.

 

The code generator may present some challenges until we thoroughly understand what it generates. Once that's achieved, we can customize the generator templates or even create our own, allowing us to streamline repetitive tasks and focus on creating truly impressive features.

How flexible is the framework? Such examples can be easily implemented in any modern framework.

 

I'm not familiar with methods for migrating code from one framework to another, but many people experiment with different frameworks to find their personal favorites.


Yii is an excellent choice, especially if you're looking to rebuild your CMS.
Title: Re: Yii Framework for Web Development
Post by: Ambimbom on Jun 28, 2024, 02:30 AM
Your questions reveal a deep understanding of the underlying principles of web application development. Let me address them in the context of a programmer's perspective.

Question 1: The "ready-made framework" in Yii refers to both the client-side (frontend) and the administrative (backend) components of the web application. Yii provides a well-structured, Model-View-Controller (MVC) architecture that serves as a foundation for building your entire web application, including the public-facing client-side and the administrative backend.

In Yii, the framework encompasses a predefined file structure, a set of core classes, and a robust database integration layer. This means that when you start a new Yii project, you already have a solid infrastructure in place, allowing you to focus on developing the specific functionality and business logic of your application, rather than reinventing the wheel.

Regarding the admin panel, Yii does not provide a fully built-in admin interface out of the box. However, it does offer a set of tools and conventions that make it easier to create and customize the admin section of your application. You can leverage Yii's built-in CRUD (Create, Read, Update, Delete) generators to quickly generate the necessary code for managing your data models, including the admin-specific functionality.

Question 2: The process of creating and managing "lists" (such as news, articles, events, and Q&A) in Yii can be highly automated, thanks to the framework's robust data modeling and database integration capabilities.

In Yii, you would typically define your data models (e.g., Article, Event, Question) as Active Record classes. These classes represent the database tables and encapsulate the logic for interacting with the corresponding data. When you define a new data model, Yii can automatically generate the necessary CRUD actions and views for managing that model, including the admin-specific functionality.

The process of adding a new "list" (e.g., authors) in Yii would involve the following steps:

1. **Create the database table**: You would create a new table in your database for the authors, defining the necessary columns (e.g., id, name, email).
2. **Define the Active Record class**: You would create a new PHP class (e.g., Author) that extends Yii's ActiveRecord class and maps to the authors table.
3. **Generate the CRUD code**: Yii provides command-line tools that can generate the basic CRUD (Create, Read, Update, Delete) actions and views for the new Author model, including the admin-specific functionality.
4. **Customize as needed**: You can then further customize the generated code to add any additional functionality or styling specific to your application's requirements.

The beauty of Yii is that it abstracts away much of the boilerplate code required for basic CRUD operations, allowing you to focus on the unique aspects of your application. The framework handles the underlying database interactions, routing, and rendering, so you can quickly build sophisticated web applications without reinventing the wheel.

Transitioning to a framework like Yii will undoubtedly elevate your development process and allow you to create more robust, maintainable, and scalable web applications. The initial learning curve may be steeper, but the long-term benefits of working within a well-designed, battle-tested framework like Yii will become increasingly apparent as your project grows in complexity.