CakePHP

I love PHP. That’s a fact that I managed to prove ever since college. I self studied the language as well as the underlying platform due to my interest in learning; which comes from the fact that I know its purpose. For this post, I’m going to put some perspective on how do we create a CakePHP application and put the bootstrap in to make a more responsive user interface design for the web.

Since the birth of boostrap a lot of developers created their own mix and match using the front-end framework. Either you download an existing one or create your own. For this tutorial, lets download an existing one: CakePHP Theme

I was once challenge to create a proposal for a mid-size application that can have millions of potential users. The experience is not easy as I need to meet up with the same client over and over again to discuss the high level solution, innovations made, justify estimates, explain the overall process, expectation on both parties and what the solution will be the final solution be like after.

I will try to give out as much detail as I can, but I need to protect the integrity of my documents as well as my client.

Client Use Case: I want to create e-Learning System that will allow enthusiastic knowledge sharer to have a venue for them to teach and possibly earn.

With this client use case, I come up with a Conceptual System design. The Functional Aspects include (note that what I’m going to show here is just a specific phase of the project):

User Dashboards

Learn – Venue for users that wants to learn

Teach – Venue for users that wants to teach

Community forum – discussions on topics, courses and other related activities

Account Management – users will be able to manage their accounts using a specific sub-system

What I did is separate these systems requirementsand break them down to smaller manageable (yet still high level solutions) modules. I will not further elaborate how I did them but here is the screenshot of the documentation I made (with the break down). Basically, these are all intuition based, if you are knowledgable how Software Apps work – you’ll eventually end up having an idea on how to solve each specific case.

So to list all details that I did for the proposal:

Details that as much as you can, can be explain or elaborated to the most non-technical person on the client side

Complete Systems requirements versus technical solution

list of solution and innovations (why does your solution stands out of the rest – what is special about it)

Process / methodology – We need to give them a bit of how we do things and this is how effective we are – give them the benefits that they will acquire with your preferred methodology – not just your own benefit.

Give them the comfortable detail they need for them to trust the solution

I tried preparing all of this items as it will give the client a better perspective and understanding on what and how are the projects will be executed:

I put up a list as of features with respect to its technical conceptual design. These features look a lot like functional ones but a closer look at each will give you the idea that they are also separated by technical implementation (how to implement each).

Created Pre-requisites – to identify if there are features that needs to be done first before the feature is considering fully working. Description – is just the purpose of the module. Solution, Effort and Cost Driver – table that consist of the solution, explanation of effort and its cost driver.

Next is the cost breakdown – the cost break down is based on the average hourly rate of the developer – I wanted to make this project as formal as possible as I’m looking at it back then to be the initial pilot project and that the process established will be re-used for succeeding ones.

The cost gives an overall breakdown of cost with respect to: technology stack, platform, effort resourcing and external service needed.

Technology Stack Diagram and implementation scheme – Its important that you align the methodology or at the very least, the strategy of implementation. I used Agile – and aligned its benefits and the high probably of quality result by using actual user stories.

Application Stack:

Since this is a Website: Systems Architecture (Hosting)

Agile: Systems Integration Architecture / Process View

Traceability Matrix – Map System requirements to High Level Solution module (note that this is from a different project)

The bottom line here is that: Give them the correct details they need for them to be comfortable with how you will do the solution and of course your depth knowledge to finish them off with the highest quality possible.

Sometimes, the exciting part in configuring a virtual software server (web or application) is the activity to understand how it works and how can you manipulate it the way you want. For this post, I would like to give a basic how to on relocating (or pointing) your apache to scan a specific directory as its DocRoot directory. 🙂

The DocRoot directory – Every PHP developer must ‘ve known or ask regarding about this. Did you ever wonder if you can customise your XAMPP/LAMP or MAMP to detect or interpret PHP files on a folder other than the docroot folder? Here is how!

Locate httpd.conf file on the apache folder – This is where you can edit that settings!

Agility – In Software Development, having this characteristic is one of the key to success these days. A lot of talented startups are using their flexible business models to quickly adapt to changes and widen their customer base. Developers are now adapting and embracing the “Jack of all trades” on a platform level as the demand for such is increasing day by day. Yet with all those agile web programming platforms, PHP stood out for me. Its simplicity and straight forward approach makes every developer feel the fulfilment of crafting an application. With the addition of several frameworks developed on top of it like cakePHP, yii, codeigniter etc, the capability of it just keeps getting better and better.

Moving on though, I’d like to show you how simple and agile a developer can be with one of the best Agile / Rapid Web Application Development Framework available: CakePHP

What are we going to do: Simple Registration process it has to have:

Register a new person

Edit an existing person

Delete an existing person

View all of the person

User Interface for all

Its also note worthy that I will be doing all of these stuff as I write this down. I would say it may take you 15mins including the cakePHP initial code setup.

Assumptions:

I use MAC so this tutorial is solely for MAC users – although the only difference is the scripts and system path configuration which is the same as setting up environment variables in windows.

Locate htdocs inside MAMP < this is where you will locate your cakePHP and projects as this is the default directory recognised by your web server and php parser (you can actually change it to any custom directory you want, this can be done by changing the DocumentRoot of httpd.conf inside the apache folder).

Download the latest cake distro here: http://cakephp.org/

Put it inside your htdocs folder (start your XAMPP to test).

if you see the screen below, then your on the right track!

Check the video for the .bash_profile: http://www.youtube.com/watch?v=KOBO-kEakQ0 for the environment variables.

Export the following variables and values < This is to put the cake library in your classpath. This is important for you to easily access the commands for baking (code generation tool)

Test it!

Database Setup: Lets setup your database and table objects

Create a table named persons < This is cakePHP’s naming convention, tables are “recommended” to be plural as this will have multiple entries of a specific business data.

Type the location on where you want to put the app. In this case, put in htdocs folder.

Skeleton folder is the default one so just press enter. Type in Y when ask if “Look okay?”.

Create a Database Connection called “default”.

Database: Mysql

Persistent Connection: For now, N

Database Host: 127.0.0.1

Port: 3306

Username: <your db username>

Password: <your db password>

Database Name: registration_sample

Press Enter all the way.

This will create a new “bakeable” project source code. Type in cake bake -app <location of the project source code>. This will run the cake bake command and will display a menu of code generators (screenshot below).

Generate Model Codes first: Press M

Use the “default” datasource

Choose 1. Persons

Primary Key: 1. Id

Display Field: first_name

Validation Criteria for Fields: Y – this is where you define the validation. This will affect the validations on the user interface.

Press Enter all the way

Generate Controller Codes: Press C

Choose 1. People

Press Enter up until the generation of basic class methods.

Would you like to create some basic class methods index(), add(), view(), edit())? (y/n) = Y

Would you like to create the basic class methods for admin routing? (y/n) = N

Would you like this controller to use other helpers besides HtmlHelper and FormHelper? (y/n) = N

Would you like this controller to use any components? (y/n) = N

Would you like to use Session flash messages? (y/n) = Y

Press Enter all the way

Generate View Codes: Press V

Choose 1. People

Press enter all the way

Go to: http://localhost/RegistrationPersons/People

and your done! You may now create, edit, delete and view all persons! All of these generated by the bake command.

As I was playing along with CakePHP on my machine, I noticed that it took me some extra steps to configure it correctly on my Mac machine, unlike in Windows that is fairly very straight forward.

First the cake core console configuration on the system path – You need to define the cake core first on the classpath, this will allow the user / developer to call the cake and bake commands from the terminal.

Download CakePHP and put it under your Server Document Root (you can configure this on httpd.conf of you web server)

Open console and type: nano .bash_profile

This will open a console base text editor and .bash_profile file – note that the bash_profile is one of the recognized system classpath file in which users can declare console classpath (libraries). Now include the cake bin folder as shown on the screen.