Building Own Framework in PHP Part-1

Up-til now i am very much fan of famous PHP framework Laravel. The latest version of it 5.1 has very nice features to build web application using modern tool. It provides full-stack approach to build web application. After using Laravel from very long time i am very much familiar with it’s component.

But from last couple of weeks i was thinking to build own small framework which is completely written by my self and fulfil requirements to build web application in day to day life. In Laravel i feel that entry point is Routes and it is very good place to control application routes and flow. So i started thinking to build own router. I have searched on google and found few results. Among all result i like slim framework Route class and got inspiration from there and try to build own small router for specific actions only.

My Small own router.

We can also pass arguments in dynamic action method in call_user_func_array function. You can see i have passed empty array to keep this simple. But if required we can pass argument and can expect that argument in controller method.

Like

$action = "getOrderDetail";
call_user_func_array(array($orderController, $action), array(34));

that we have to write getOrderDetail method as follow

    public function getOrderDetail($order_id)
	{
		echo "Now you will receive order detail for order id :".$order_id;
	}

From the above code i can now have some confidence to build this router component generic using .htaccess file which provides nicer way to url rewrite feature in Apache web server.

Also dynamic languages like PHP, Ruby, Python prvoides such a nice facility so that dynamism is achieved using their core feature.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s