Lithium Framework: Getting Started

Posted by Unknown on Monday, May 19, 2014

Lithium is a lean but mean PHP framework (machine?) built for PHP 5.3 and up. It is designed to provide a good toolset for starting your web application, but one that is not too confining.


Lithium uses the Model-View-Controller(MVC) architecture and this is what we are going to look at in this article. I will show you how it works and how you can define some of your application’s business and presentation logic using this framework. There are a few things we will do in this respect.


We will set up a Controller to route URL requests to. This Controller will get and process some information from the database with the help of a data Model. This information will then be displayed in the browser using a View. All standard MVC stuff, but a real pleasure to perform with Lithium.


I will assume you already have the framework set up on your server to the point that you can at least see the default app starting page if you navigate to the URL. Additionally, you’ll need a database populated with some information. I’ll use MySQL but Lithium supports a number of other storage systems like MongoDB or CouchDB.


I have set up a Git repository that you can clone if you want to follow along. The master branch contains the vanilla Lithium framework whereas the MVC branch contains the code from this article. Don’t forget to also init and update the lithium submodule. To connect your database, make a copy of the connections_default.php file located in the app/config/bootstrap folder and rename it connections.php. Then add your credentials inside that file.


Let’s begin.


The data


Before getting into the fun MVC stuff, let’s get a table into our database with some information. I will be working with dummy page data so my table (called pages) will contain an id column (INT, auto increment and primary key), a title column (varchar 255), a content column (text) and a created column (INT). And in this table I have 2 sample rows. If you want to follow along exactly, here is the table create statement:



CREATE TABLE `pages` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(255) DEFAULT NULL,
`content` text,
`created` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;


And here are my dummy rows:


Continue reading %Lithium Framework: Getting Started%




more

{ 0 comments... » Lithium Framework: Getting Started read them below or add one }

Post a Comment

Popular Posts