Home Software Blog Wallpapers Webtools
Yii - a PHP MVC framework
Saturday 26, May 2012   |   Post link

Which language should I use to develop my dream website?

The answer is easy when you are developing a website with static content, say putting up a picture gallery, plain HTML is all you need. However once you want people to interact with you, you need to be able to execute some code on your website. PHP is one of the cheapest options for doing this. Most web-hosting companies offer pHp where you can code using the language (pHp) and generate the HTML content which is finally displayed on the user’s web-browser.

Now most folks who come with a programming background will find it pretty easy to learn pHp even if they have not coded in pHp before. The really hard part is writing the code in a way that is is easily understood even after say one year of having looked at it.

With the above requirement, writing even a single web page which accepts some information from the user, store it to a persistent store like a database and then display the same information in a meaningful way is not easy at all.

Why is writing maintainable code for the web so difficult?

Its because:

  • First, there is no state as such. Everything is disconnected. You can't have a variable with some value set in one web-page and expect it to be available when the user navigates to another page
  • The entire UI has to be generated every time i.e. some processing needs to happen for every web-page
  • The processing can only happen when the browser sends a request to the server

Scripting languages like pHp offer the amazing ability to mix HTML with pHp and generate content on the fly. However, writing any kind of slightly complex code like displaying a list of products really makes the code hard to understand and above all maintainable. In a single pHp page, where do you connect to the database? Where do you display the data read and where do you update the information entered by the user? If a use selects a product in a shopping website should the code to add the item to the basket be in the item listing page or a different page?

There are no straight-forward answers to the above.

Enter the gurus. People have been developing such projects for many years and have discovered better ways to do such things. Recognition of such common situation have given rise to well-known programming patterns and one such pattern is the MVC (Model View Controller) pattern. A pattern is nothing but a set of rules or a way to write code. Frameworks are actual implementation of the rules using code.

Framework is nothing but a boiler-plate code where most of the decisions about where to put what has been taken by the framework author. The author has used his experience to come up with a set of rules which he thinks is the best way to develop – all frameworks have one important aim – this is to force the developer to write code in a specific way to increase maintainability and reuse. Once the basic idea behind a pattern is understood, developing within the framework becomes a lot faster than using the raw language (pHp in this case) directly.

While developing this very website, I went through a lot exciting experiences. Being a C++ developer (a control freak), I stayed away from frameworks and started building the website using pHp directly. The parts of this website which need programming is the ability to accept comments for software I am offering for download. Soon I needed ability to store number of times something has been downloaded. Thereafter I needed a nice way to create entries for things which can be downloaded and such requirements kept growing.

I almost spent a whole week writing pHp code without any framework support. Pretty soon I was struggling with all the questions about where to write what and maintain the slightest sort of discipline. This is when I thought about using a framework – why not a framework? I have been using the MFC (Microsoft Foundation Classes) and Visual Studio code generation/framework for years and most of my projects turned out that way I wanted.

The main reason for me to use a framework was to separate business logic, data and UI presentation. I needed an implementation of “model-view-controller” pattern.

I first started experimenting with the Zend framework. It’s been around for a long time and is quite well known. There are also lots of books written about it. I read online tutorials as well as reached almost half of the ‘Zend framework in action’ book.
All well written articles and books but for the life of me, I couldn’t figure out where to start writing actual code. I even tried using Zend studio which is a development environment specifically for building Zend framework based web applications. The problem here was that the code generated by the IDE was quite different from the code presented in the book which again differed from the code present in other articles and blogs.

I decided to try one more framework before giving up – this is when I chanced upon a relatively new framework on the block called Yii. Yii Logo I tried searching for more reading material but couldn’t find any books on Yii at the usual retailers. I then took a look at four videos which the Yii guys have put up on their website – each tutorial talks about a very specific step in the development of a website.

  • How to install Yii
  • How to create the first application
  • How to display something keeping data and UI separate
  • How to interact with data in a database keeping data objects separate

These four tutorials is all it took for me to believe that THIS is THE framework I am supposed to use.

The great thing about Yii is that it is able to generate boiler-plate code which will works out of the box. All you need to do is add your specific changes.

Yii does not need separate IDE for code generation to work, the Yii framework installation itself is capable of:

  • generating code to create a web-application which can then be customized
  • generating views
  • generating controllers
  • generating CRUD screens

This is just the tip of the iceberg. Yii has amazing support for almost everything that one would need to build a great website.
The directory structure used is very intuitive. The help documentation is good and the forum on their website has very good developer comments which are invaluable.

I believe Yii has taken developing pHp based websites to the next level.
If you are thinking of building a pHp based webstie, I’d strongly advise you to take a look at Yii.


Posts By Year

2024 (1)
2023 (5)
2022 (10)
2021 (5)
2020 (12)
2019 (6)
2018 (8)
2017 (11)
2016 (6)
2015 (17)
2014 (2)
2013 (4)
2012 (2)

Posts By Category

.NET (4)
.NET Core (2)
AWS (5)
AWS API Gateway (1)
Android (1)
Apache Camel (1)
Architecture (1)
Audio (1)
Azure (2)
Book review (3)
Business (1)
C# (3)
C++ (2)
CloudHSM (1)
Containers (4)
Corporate culture (1)
Database (3)
Database migration (1)
Desktop (1)
Docker (1)
DotNet (3)
DotNet Core (2)
ElasticSearch (1)
Entity Framework (3)
Git (3)
IIS (1)
JDBC (1)
Java (9)
Kibana (1)
Kubernetes (1)
Lambda (1)
Learning (1)
Life (7)
Linux (1)
Lucene (1)
Multi-threading (1)
Music (1)
OData (1)
Office (1)
PHP (1)
Photography (1)
PowerShell (2)
Programming (28)
Rants (5)
SQL (2)
SQL Server (1)
Security (2)
Software (1)
Software Engineering (1)
Software development (2)
Solr (1)
Sql Server (2)
Storage (1)
T-SQL (1)
TDD (1)
TSQL (5)
Tablet (1)
Technology (1)
Test Driven (1)
Unit Testing (1)
Unit Tests (1)
Utilities (3)
VC++ (1)
VMWare (1)
VSCode (1)
Visual Studio (2)
Wallpapers (1)
Web API (2)
Win32 (1)
Windows (9)
XML (2)

Posts By Tags

.NET(6) API Gateway(1) ASP.NET(4) AWS(3) Adults(1) Advertising(1) Android(1) Anti-forgery(1) Asynch(1) Authentication(2) Azure(2) Backup(1) Beliefs(1) BlockingQueue(1) Book review(2) Books(1) Busy(1) C#(4) C++(3) CLR(1) CORS(1) CSRF(1) CTE(1) Callbacks(1) Camel(1) Certificates(1) Checkbox(1) CloudHSM(1) Cmdlet(1) Company culture(1) Complexity(1) Consumer(1) Consumerism(1) Containers(3) Core(2) Custom(2) DPI(1) Data-time(1) Database(4) Debugging(1) Delegates(1) Developer(2) Dockers(2) DotNetCore(3) EF 1.0(1) Earphones(1) Elastic Search(2) ElasticSearch(1) Encrypted(1) Entity framework(1) Events(1) File copy(1) File history(1) Font(1) Git(2) HierarchyID(1) Hyper-V(1) IIS(1) Installing(1) Intelli J(1) JDBC(1) JSON(1) JUnit(1) JWT(1) Java(3) JavaScript(1) Kubernetes(1) Life(1) LinkedIn(1) Linux(2) Localization(1) Log4J(1) Log4J2(1) Lucene(1) MVC(4) Management(2) Migration history(1) Mirror(1) Mobile Apps(1) Modern Life(1) Money(1) Music(1) NGINX(1) NTFS(1) NUnit(2) OData(1) OPENXML(1) Objects(1) Office(1) OpenCover(1) Organization(1) PHP(1) Paths(1) PowerShell(2) Producer(1) Programming(2) Python(2) QAAC(1) Quality(1) REDIS(2) REST(1) Runtimes(1) S3-Select(1) SD card(1) SLF4J(1) SQL(2) SQL Code-first Migration(1) SSH(2) Sattelite assemblies(1) School(1) Secrets Manager(1) Self reliance(1) Service(1) Shell(1) Solr(1) Sony VAIO(1) Spirituality(1) Spring(1) Sql Express(1) System Image(1) TDD(1) TSQL(3) Table variables(1) Tables(1) Tablet(1) Ubuntu(1) Url rewrite(1) VMWare(1) VSCode(1) Validation(2) VeraCode(1) Wallpaper(1) Wallpapers(1) Web Development(4) Windows(2) Windows 10(2) Windows 2016(2) Windows 8.1(1) Work culture(1) XML(1) Yii(1) iTunes(1) renew(1) security(1) static ip address(1)