Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Laravel Framework Modern Website Building

Laravel Framework Modern Website Building

Avatar for 大澤木小鐵

大澤木小鐵

November 03, 2012
Tweet

More Decks by 大澤木小鐵

Other Decks in Programming

Transcript

  1. The Basic Features • 有效率地處理使⽤用者的請求。 • ⽤用更抽象化的⽅方式處理資料內容。 • 有效管理與整合前端⽂文件。 •

    快速回應各種不同格式的內容。 • 提供基本的安全防護。 • 完整的⽂文件。 • 易於擴充與佈署。
  2. About Laravel Framework • Taylor Otwell 於 2011 年 4

    月發表 • MIT License • 基於 PHP 5.3 的 MVC Framework • 豐富⽽而完整的⽂文件 • 易懂的 API ⽤用法 • 易於擴充新功能 http://laravel.com/
  3. Classy & Fluent Interface return Redirect::to('login') ->with_input(); $comments = Post::find(1)->comments;

    Asset::container('footer') ->add('example', 'js/example.js'); $url = URL::to_secure('some/uri');
  4. paths.php $environments = array( 'production' => array( 'http://www.example.com*'), 'testing' =>

    array( 'http://test.example.com*'), 'local' => array( 'http://localhost*', '*.dev'), );
  5. Custom Task // application/tasks/notify.php class Notify_Task { // php artisan

    notify taylor public function run($arguments) { // Do awesome notifying... } // php artisan notify:urgent public function urgent($arguments) { // This is urgent! } }
  6. Migration class Create_Users_Table { public function up() { Schema::table('users', function($table)

    { $table->create(); $table->increments('id'); $table->string('username'); $table->string('email')->unique(); $table->timestamps(); }); } public function down() { Schema::drop('users'); } }
  7. Migration php artisan migrate // 執⾏行 migration php artisan migrate:rollback

    // 撤消上⼀一步 http://laravel.com/docs/database/migrations
  8. Autoloader::namespaces Autoloader::namespaces(array( 'Doctrine' => path('libraries') . 'Doctrine', 'Zend' => path('libraries')

    . 'Zend', )); https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md
  9. RESTful Routing Route::get('user/(:num)', function($id) { // Get user information });

    Route::put('user/(:num)', function($id) { // Update user information });
  10. Input & Cookie Input::get($key); // All inputs Input::query($key); // Query

    String Input::file($key); // Files Input::json(); $name = Cookie::get('name'); Cookie::put('name', 'Jace', 60);
  11. Redirecting With Old Input return Redirect::to('login') ->with_input(); // Get old

    input Input::flash(); $name = Input::old('name'); http://laravel.com/docs/input#redirecting-with-old-input
  12. Validator $input = Input::all(); $rules = array( 'name' => 'required|max:50',

    'email' => 'required|email', ); $validation = Validator::make($input, $rules); if ($validation->fails()) { return $validation->errors; }
  13. ORM

  14. Has One class User extends Eloquent { public function phone()

    { return $this->has_one('Phone'); } } $phone = User::find(1)->phone;
  15. Belongs To class Phone extends Eloquent { public function user()

    { return $this->belongs_to('User'); } } echo Phone::find(1)->user->email;
  16. Has Many class Post extends Eloquent { public function comments()

    { return $this ->has_many('Comment'); } } $comments = Post::find(1)->comments; http://laravel.com/docs/database/eloquent
  17. Bundle Installation php artisan bundle:install bundle_name // application/bundles.php return array(

    'docs' => array('handles' => 'docs'), 'bundle_name' // 註冊 bundle );
  18. Bundle Tasks class Admin_Generate_Task { public function run($arguments) { //

    Generate the admin! } } php artisan admin::generate http://laravel.com/docs/bundles
  19. • Form • Errors & Logging • Localization • Authentication

    • IoC Container • Unit Testing Other Features http://laravel.com/docs
  20. • Is Good MVC ? • Secure Request • Fast

    Response • Simply Data Handling • Extendable The Points