background preloader

CodeIgniter, le framework au service des Zéros

CodeIgniter, le framework au service des Zéros

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. Enough with the sales pitch. (From Wikipedia) Model–View–Controller (MVC) is an architectural pattern used in software engineering. In simpler words- 1. So with such a nice introduction we get down to it! In the beginning We want our application to be at -> to list all contacts in the db – to delete contact with the id 12 and so on and so forth .. So we start off by creating the project directory `contacts`. Options -Indexes RewriteEngine on RewriteCond %{REQUEST_FILENAME} ! index.php Next we create the index file, index.php. <? <? .

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. 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 Although we will not be a couple of directories mentioned above for this tutorial, we should have them in place for future expansion. application – application specific code config – database/server configuration db – database backups library – framework code public – application specific js/css/images scripts – command-line utilities tmp – temporary data Once we have our directory structure ready, let us understand a few coding conventions. Coding Conventions 1. mySQL tables will always be lowercase and plural e.g. items, cars 2. Now we add index.php to our public folder view.php add.php

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

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:

Related: