Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Memphis php 01 22-13 - laravel basics

2,904 views

Published on

Slides from http://www.memphisphp.org/events/93611422/ Memphis PHP user group meeting talking about the basics of the PHP Framework Laravel.

Published in: Technology
  • Be the first to comment

Memphis php 01 22-13 - laravel basics

  1. 1. Laravel Basics MemphisPHP.org 01-22-13Tonights Sponsor:
  2. 2. What is Laravel?● MVC PHP Framework● Created in April 2011● Incredibly well documented● "A framework for Web Artisans"● Ease of entry● Something for everyone ○ emphasizes flexibility and expressiveness.
  3. 3. What makes Laravel different?● Bundles ○ Laravels Package System ○ Easily add plugins to your project ○ Easily share your code with others● Eloquent ORM ○ Not everyone is a DBA ○ Using PHP ActiveRecord ○ Takes advantage of Fluent Query Builder ■ Uses prepared statements ■ Automatic defense against SQL injection● Flexible Application Logic ○ Route using controllers or directly via routes
  4. 4. What makes Laravel different?● RESTful controllers ○ Easily separate GET and POST requests● Class Autoloading ○ Just use your class, laravel takes care of the loading ○ Only required classes are loaded for each request● Migrations ○ Version control for your database schema● Unit Testing - PHPUnit tightly integrated● Automatic pagination● Reverse Routing ○ Easily change routes down the road ○ Using route names prevents broken links / routes
  5. 5. Laravel Project Structure/application - Most of your Application Code/bundles - Laravel Applications (plugins)/laravel - Core Framework Files/public - Webserver Document Root/storage - File store for services (Cache)/vendor - Code used by Laravel/artisan [file] - Laravel Command Line Interface/paths.php [file] - Used to determine file paths
  6. 6. Laravel Application Directory/config - Application configuration files/controllers - The application "Logic"/language - Localisation files/libraries - For "drop in" single file classes/migrations - DB Schema version control files/models - Classes to interact with a database/tasks - add custom tasks to the artisan CLI/tests - Unit Testing/views - HTML Templates
  7. 7. Laravel Application Directory (cont.)/bundles.php [file] - Manages active bundles/routes.php [file] - Application Routing Mappingstart.php [file] - Start up Routines
  8. 8. Using Controllersclass Account_Controller extends Base_Controller{ public function action_index() { echo "This is the profile page."; } public function action_login() { echo "This is the login form."; } public function action_logout() { echo "This is the logout action."; }}
  9. 9. Routes with ClosuresRoute::get(/, function(){ return View::make(home.index);});Here we are responding to requests to the rootof the web app, that use the HTTP verb GETwith a Closure that simply returns a View object
  10. 10. Passing Parameters to ClosuresTo pass parameters to your Closures, simply add the usual view placeholdersto the URI, and define parameters in your Closure, they will be matched in theorder from left to right,Route::get(user/(:any)/task/(:num), function($username, $task_number){ // $username will be replaced by the value of (:any) // $task_number will be replaced by the integer in place of (:num) $data = array( username => $username, task => $task_number ); return View::make(tasks.for_user, $data);});
  11. 11. More Information● http://daylerees.com/category/laravel- tutorials● http://laravel.com/docs/● http://forums.laravel.io/● #laravel on Freenode (IRC)● https://leanpub.com/codehappyMajor Credit to Dayle Rees and his CodeHappy book. Much of the content here wasfrom his tutorials. Support him by buying hisbook: https://leanpub.com/codehappy

×