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.

Word Camp Kansai 2014 - MVC Framework

3,373 views

Published on

Notes from my presentation at Word Camp Kansai 2014. Be sure to visit http://codebyjeff.com/blog/2014/03/make-your-own-wordpress-mvc-plugin as well for a tutorial on creating this yourself

Published in: Technology
  • Be the first to comment

Word Camp Kansai 2014 - MVC Framework

  1. 1. WordPress を MVC フレームワーク として使用する
  2. 2. Who? What? Why? Where? How?
  3. 3. Who? What? Why? Where? How?
  4. 4. Jeff Madsen @codebyjeff Lead Developer, Alyte Creative (Australia)
  5. 5. YOU! 中級レベルな プログラムマー
  6. 6. Who? What? Why? Where? How?
  7. 7. http://localhost/usertut/test
  8. 8. No pages found!
  9. 9. MVC フレームワーク プラグイン
  10. 10. M - Model V - View C - Controller ex: Codeigniter, CakePhp, Rails, Django
  11. 11. コード の編成 Code Organization
  12. 12. これもう一回見たことがある か?
  13. 13. もう アカン!
  14. 14. Who? What? Why? Where? How?
  15. 15. build pages with git/deployment tools
  16. 16. use Composer.org libraries
  17. 17. TESTABLE!!
  18. 18. Who? What? Why? Where? How?
  19. 19. MU-PLUGINS #1 最初 loading (plugins もう大丈夫 )
  20. 20. Who? What? Why? Where? How?
  21. 21. What do we need? Router  ( ディスパッ チ ) Custom post types class Views Libraries
  22. 22. WP-Router (https://wordpress.org/plugins/ wp-router/)
  23. 23. Custom Post Type Class http://github.com/ jjgrainger/ wp-custom-post-type- class/
  24. 24. PlatesPHP (http://platesphp.com/) -similar to Twig -framework agnostic Plates
  25. 25. Composer (http://getcomposer.org)
  26. 26. Structure Similar to CodeIgniter CakePHP Rails
  27. 27. loader.php require_once( 'alyte-core/system/plugin.php' ); require_once('alyte-core/vendor/autoload.php'); ... system/plugin.php //load the core classes, scripts add_action( 'plugins_loaded', 'alyte_plugins_loaded' ); add_action( 'wp_enqueue_styles', 'alyte_load_styles' ); add_action( 'wp_enqueue_scripts', 'alyte_load_scripts' ); ... call the bootstrap.php ...
  28. 28. static function show_student_profile( $router ) { $args = array( 'path' => '^profile/(.*?)$', 'query_vars' => array( 'user_id' => 1, ), 'page_callback' => array( 'Alyte_Students','get' ), 'page_arguments' => array('user_id'), 'access_callback' => true, 'title' => 'Your Student Profile', 'template' => array('page.php', dirname(__FILE__).DIRECTORY_SEPARATOR.'page.php') ); $router->add_route( 'show-student-profile-route', $args ); } MAGIC HAPPENS HERE class-routes.php
  29. 29. Student Class static function get($id) { $user = new User($id); $data = array( 'id' =>$id, 'user' => $user, ); // Plates PHP $template = self::make_template(); $template->data($data); return $template->render('students/profile_view'); }
  30. 30. View
  31. 31. Page

×