background preloader

Développement Framework

Facebook Twitter

CodeIgniter, le framework au service des Zéros. Creating a PHP5 Framework - Part 1. With websites becoming more and more dynamic and interactive, developers often look to frameworks to help build websites and web apps rapidly. While there are a number of great frameworks available, a custom framework gives you the ability to easily customize the framework as you need, and to build with it even quicker - as you would already know the ins and outs of it before working with it.

In this series of tutorials, we are going to build our very own PHP5 Development Framework! Let's start with planning our framework and put the basic structure into place. *Note - Running the demo should display "PCA Framework version 0.1 the HTML output" - which demonstrates the first stage of our framework. Step 1: This Series In this series, we will create our own PHP5 Framework from scratch.

Over the next few weeks, during these tutorials we will cover: Step 2: Design Patterns and their use within our Framework Step 3: Files and Folders Some commonly used functions / objects.Business logic.A design. Write your own PHP5 MVC framework : the blog of ndungi kyalo. Let there be Lite Although there are as many frameworks out there as there are programmers, very few frameworks allow the programmer room to code his/her own way. Most are bloated with libraries and features you will never use. And most impose arcane rules to application development, creating a whole new programming language the programmer now has to learn.

Whereas our unnamed framework is not the answer to all your problems, it gives the web developer more leverage in deciding how to use the framework, changing the conventions, or even trashing it etc It is dead simple. And it would be useless without a simple do-it-yoursel tutorial of how it is built and how it works, because this is the whole point of wrestling control from popular mainstream frameworks and giving it back to the programmer. Enough with the sales pitch. (From Wikipedia) Model–View–Controller (MVC) is an architectural pattern used in software engineering. In simpler words- 1. In the beginning and so on and so forth .. <? <? . Développer son propre micro-framework MVC en PHP. Imaginons que vous avez besoin de réaliser une API REST qui cause en JSON. Vous aimez bien les trucs simple et super rapide.

Donc utiliser un framework à la Zend ou Symfony est totalement overkill même avec Silex. Et puis comme vous aimez réinventer la roue vous avez décidé de développer votre propre micro-framework minimaliste. Notre framework MVC Voici les fonctionalités que l'on veut mettre en oeuvre : Séparation modèle, vue et contrôleurAucune dépendance, doit pouvoir fonctionner sans d'autres bibliothèques PHPLe plus simple possibleRapideDoit pouvoir appeler un contrôleur en fonction d'une URL et d'une méthode HTTP (GET, POST, PUT, DELETE).

On va diviser notre framework en plusieurs parties : Request : Gère la requête HTTPRouter : Execute une action en fonction de l'URL et du verbe HTTPResponse : Retourne la réponse au client qui peut-être du JSON Implémentation Voici ce que l'on veut obtenir, une requête GET sur la ressource /team/123 doit nous retourner une réponse en JSON. <? La réponse. Write your own PHP MVC Framework (Part 1) | anant garg. What is MVC? From Wikipedia– Model–View–Controller (MVC) is an architectural pattern used in software engineering. Successful use of the pattern isolates business logic from user interface considerations, resulting in an application where it is easier to modify either the visual appearance of the application or the underlying business rules without affecting the other.

In MVC, the model represents the information (the data) of the application; the view corresponds to elements of the user interface such as text, checkbox items, and so forth; and the controller manages the communication of data and the business rules used to manipulate the data to and from the model. In simpler words- 1. Why should I write my own framework? This tutorial is by no means a comprehensive/definitive solution to your framework needs. So why should you write your own framework? More importantly, you have complete control over your framework. Lets dive right in The Directory Structure Coding Conventions view.php add.php. PHP Frameworks? Just roll your own! – PART 1. There are quite a few php frameworks out there. Some huge, some small; Some useful, some not. I often hear developers, even myself, complain about frameworks in php not having or not doing something the way they/we want it too.

So my solution? Roll your own framework! This series of articles is going to give you a brief and quick intro on how to do just that. Mini-series Overview Week 1: URL Routing and Directory SetupWeek 2: TemplatingWeek 3: Database Interaction To get started let’s setup our directory structure. MyWebApp/ '---actions/ '---helloworld/ '--- actions.php '--- models.php '--- templates/ '--- yourTemplateHere.php '---system/ '--- template.php '--- database.php '--- dispatch.php '---www/ '--- js/ '--- css/ '--- images/ '--- index.php Let’s break this structure down, it’s simple. MyWebApp: the root of your web app that will be using our “Peanut” framework Now that we have a directory structure, let’s setup a virtual host in Apache to accommodate for Peanut. Roll Your Own PHP Framework: Part II. A little over a week ago, we looked at how to set up our file structure and how to get URL routing working in our little framework.

So we now have something to handle urls and display a page, but we want to make the page a little more attractive. Since there is nothing fun about making php print html, let’s add a template piece to the puzzle. We won’t have to do too much since php is a great template language by itself. Mini-series Overview Part 1: URL Routing and Directory SetupPart 2: TemplatingPart 3: Database Interaction Note: I’m assuming you have a little OOP (Object Oriented Programming) experience. We are going to create a class Template and add a little code to it so it will return our pretty new page to our browser. Wipe out system/template.php and add the following code to it: Well hello templating! Require(PEANUT_ROOT_DIR . ’system/template.php’); Right underneath the dispatch.php require statement. So inside actions/helloworld/templates/helloworld.php template put the following: