What is PHPixie?
PHPixie is a lightweight, open source PHP web application framework that uses a straightforward implementation of the request-response flow yet still allows for the use of more complex models, for example, HMVC. PHPixie handles many things in a different manner from the full-stack frameworks making it a good option for small scale web apps and projects.
PHPixie's simple architecture and small size give it the fast performance that developers want for smaller projects and it's ideal for systems with limited resources such as those on a VPS. Further, PHPixie's code replaces functions that are process-intensive, e.g. regular expression, with more lightweight code.
PHPixie began in mid-2012 as a fork of the Kohana framework and was designed for simple read-only websites whose focus was on performance. In July 2012 the 1.0 version was released having been written from the ground up due to Kohana's core begin mostly patches.
Here are some of the key features of PHPixie framework:
- Package system
- Direct code flow
- MongoDB support
- Use of best practices
- Solidified security
- Direct support
What is PHPixie good for?
There are lots of frameworks available in the market so why should you use PHPixie as your PHP framework? Well, PHPixie gives more adaptability, as everything is effortlessly over-ridable, expandable and simple to learn. Actually, it is exceptionally helpful on the grounds that you will be responsible for what is going on in building your application. Besides that, PHPixie is useful as a part of any application due to its straightforward execution of the request-response flow. Also as opposed to many other frameworks that load class names with an auto loader, PHPixie does not force a naming convention leading to better readability.
These are some of the advantages of PHPixie framework:
- Concentrate on speed and page load time.
- Focusing on giving a stable and adaptable architecture.
- As opposed to other lightweight frameworks that do not give a full stack of features, PHPixie provides a restricted full stack that focuses on effectiveness.
- PHPixie should be easy to learn and understandable to anyone with experience in Codeigniter or Kohana.
- Provides a stable codebase that doesn't "get in the way" and allows the developer to write their own code how they see fit.
Example and code snippets
To explain the essentials of creating applications with the PHPixie framework we will make a little Poll application. Before the end of this instructional exercise, you will have a working survey application using PHPixie.
Before going on, ensure you download PHPixie from the project's site and extract the downloaded archive into the root web directory of your web server. Visit http://localhost/(or different location as proper) in your program and you ought to see the ‘Have fun coding!’ welcome message.
Simply follow the steps below for speedier inquiries.
Step one: Let's make our database
Initially, we will have to make two tables in the database: one we'll call “polls” which will store the questions, and “options” that will contain possible responses for each survey and the number of votes that each one got.
Open up your MySQL and run these queries:
CREATE TABLE polls (
id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
topic VARCHAR(255) NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE options (
id INTEGER NOT NULL AUTO_INCREMENT,
name VARCHAR(255) DEFAULT NULL,
poll_id INTEGER UNSIGNED NOT NULL,
votes INTEGER NOT NULL DEFAULT 0,
PRIMARY KEY (id),
FOREIGN KEY (poll_id) REFERENCES polls(id)
);
To configure the database connection, we alter the database.php file inside the application/config directory:
|
PHPixie can be configured to utilize numerous database connections, however since we are working with the single database we determine it as default. That is all the configuration required, so we can move on to writing the code now.
Step two: Let’s take a look at our model
Commonly, models handle operations like recovering data from the database and saving it. PHPixie deals with these operations utilizing an ORM layer so we do not have to compose any database queries at all. We simply need to characterize our models this way:
|
The above code should be placed in application/classes/model/poll.php.
|
The code for the options model is placed in application/classes/model/option.php:
Step three: The Controller
Every page must have an activity characterized for it inside the controller and we will require an HTML format for each page as well. Along these lines, a basic Controller that just shows the formats would appear like this:
|
Now our controller will look like this (save the following as application/classes/controller/polls.php):
|
Step four: HTML Layouts Using Views
Views are fundamentally HTML files with embedded PHP code to show the qualities appointed to place-holder variables from inside the controller. Our principal view should simply exhibit some regular HTML and incorporate a correct sub-template.
The following is application/views/main.php:
|
Step five: Creating Individual Pages
The polls page ought to simply display a rundown of accessible polls. It just requires a slight change to controller/polls.php.
|
The view of the page will be a straightforward rundown with a connection to the poll creation page. The following is code for views/index.php:
|
If we somehow managed to add a little data to the database now we would see the following while accessing to http://localhost/polls/index (list can be excluded from the URL as it is the default activity):
This is just a simple Poll application to demonstrate the basics on how PHPixie handles things and how easy it is to develop with it. If you would like to explore further you can find it on Github.
Conclusion
PHPixie began as a smaller scale framework and became a standout amongst the most prominent full stack PHP frameworks. This is thanks in part to its strict architecture that helps avoid common problems such as dependence on static methods, global scope, singletons and other antipatterns, making for readable, extendable, and testable code. Further, all PHPixie components boast full unit test coverage. It is the PHP framework that will never get in your way while giving the developer full control–yet it is still easy to learn.
Just as important the PHPixie community is friendly, active and supportive so you can anticipate getting an answers to your inquiries within minutes. The framework documentation is brimming with illustrations and is regularly updated with instructional exercises. So take some time and get to know this modern framework by going to the PHPixie website. Have fun learning!
Recent Stories
Top DiscoverSDK Experts
Compare Products
Select up to three two products to compare by clicking on the compare icon () of each product.
{{compareToolModel.Error}}
{{CommentsModel.TotalCount}} Comments
Your Comment