subscription Blogger
In this little post I will make a brief review the most important reasons to use a PHP Framework, to make our developments more quickly and efficiently (and what's hot, it must be said).
first thing you should do is see what position you are. A framework is designed for people who have a domain, at least half of the programming language in which it is made (in this case PHP) and they want their projects in a more orderly quick. If you are starting with php this is NOT the way you should go. You should start learning PHP "bareback" and then choose the best framework for your caso.También is thankful to be familiar with the model of object-oriented programming in PHP.
Code Igniter Why?
When I caught the bug of frameworks in PHP, I was looking for opinions about which one to use. Obviously, everyone has their preferences, but something that everyone agrees is that Code Igniter is a great documentation and community, a prerequisite if you're starting in this business, because sooner or later we have questions and someone will have to ask ... no?
addition, Code Igniter is highly extensible, fast, supports PHP 4 (the latest stable version, 1.7.2). Future versions will not support PHP 4, PHP 5 to work required.
Code Igniter MVC uses a programming style in which the application is enter separate layers:
■ Model: The processing / get the data. Generally, we will use it primarily to manage the input and output data in our database.
■ View: Call from the driver, is the way to represent data on the screen. In Code Igniter (and any framework for web) is the mount all the html).
■ Controller: As the name suggests, is that "control" what happens in our aplicación.Básicamente, and roughly a controller receives a request, gets model data, processes, and passes the light for display properly.
addition, we Code Igniter helpers, hooks and bookstores, but we'll discuss this later. Broadly, the helpers are a set of functions grouped by functionality, ie, have a helper to create forms, have a helper to work with dates, etc.. The libraries are classes. We have libraries to send emails, we have libraries to validate the data that come from a form, etc.
Hello World!
Note: You must have a web server that supports php, installed, configured and running. For testing, we use a local machine using MAMP MacOs.Puedes Wamp running on Windows, Mac or Mamp Mamp in linux, or you can mount Apache + PHP + MySQL by hand.
started with a sample application, let us roll. Let Codeigniter.com and we downloaded the latest version (1.7.2 at the time of writing). Once downloaded, you will see that we have two directories: System and user_guide. User_guide folder is the documentation can be found on their website in HTML format, it is not necessary for our application to work.
Download and unzip to a directory accessible by our server web.Tendremos the system folder (which contains the framework itself), the directory application you see (is within the system, just that I move out to it all far apart) and the file index.php, which is responsible for implementing the entire framework. User_guide directory and the license file I deleted, because they are not required to use the framework.
The first thing to do is edit the file application / config / config.php and put the data from our server, the first parameter, $ config ['base_url'] = http://example . com /, changing our URL example.com, in my case: http://localhost/Sites/ci-baw/
Note: to assure you always end with the url: /
Now, we get to that directory using our favorite browser (or that words, web development, Firefox + Firebug)
We can see that everything went well. We get a default page, which tells us that the hearing welcome_message.php loaded and driver for the controllers / welcome.php.
Well, let's get to see the code, and understand that you have run the driver as welcome and the view is loaded.
applicattion Open the file / config / routes.php:
will see the following lines of code:
$ route ['default_controller'] = "welcome"
$ route ['scaffolding_trigger'] = ""; It is telling that the driver Code Igniter, if you do not specify any, will be "welcome." Scaffolding_trigger parameter will not see at the moment.
Now, open the file application / controllers / welcome.php.
class
Welcome extends Controller {function Welcome
()
{parent:: Controller ();}
function index ()
{$ this-> ; load-> view ('welcome_message');}
} Let's see, the driver is always called after the name of the file, but with the first in capitals, and must always extend the Controller class. If we declare a constructor (because we need it) in PHP 4 function Welcome () in PHP 5 function__construct (), the first thing we always do in the constructor is to call the constructor of the parent class, in this case, Parant :: Controller (). The constructor will define when we need to assign values \u200b\u200bto the whole class, or load libraries or helpers that use the entire class.
The index method is the running if we have not said otherwise. This method, all you do is load a view, 'welcome_message'. If we open the file application / views / welcome_message.php see that contains the code that generates the page we have seen in our browser.
Now, by way of example and finally, let's create a function within the controller Welcome.
function hello_world ()
{echo 'Hello World from Code Igniter';}
visited, the page with your browser, in my case go to:
http://localhost/Sites / ci-baw/index.php/welcome/hola_mundoNota: We'll see soon as you remove the index.php in the middle.
And so far this brief introduction, perhaps too abstract, but necessary when you see something new.
0 comments:
Post a Comment