Download - Word Camp Kansai 2014 - MVC Framework
WordPressを
MVC フレームワークとして使用する
Who?What?Why?
Where?How?
Who?What?Why?
Where?How?
Jeff Madsen@codebyjeff
Lead Developer,Alyte Creative (Australia)
YOU!中級レベルな
プログラムマー
Who?What?Why?
Where?How?
http://localhost/usertut/test
No pages found!
MVCフレームワーク
プラグイン
M - ModelV - ViewC - Controller
ex: Codeigniter, CakePhp, Rails, Django
コード の編成Code Organization
これもう一回見たことがあるか?
もう アカン!
Who?What?Why?
Where?How?
build pages with git/deployment tools
use Composer.org libraries
TESTABLE!!
Who?What?Why?
Where?How?
MU-PLUGINS #1最初 loading
(plugins もう大丈夫 )
Who?What?Why?
Where?How?
What do we need?Router ( ディスパッ
チ )Custom post types classViewsLibraries
WP-Router (https://wordpress.org/plugins/
wp-router/)
PlatesPHP(http://platesphp.com/)
-similar to Twig-framework agnostic
Plates
Composer (http://getcomposer.org)
Structure
Similar to CodeIgniterCakePHPRails
loader.php
require_once( 'alyte-core/system/plugin.php' );require_once('alyte-core/vendor/autoload.php');
...system/plugin.php
//load the core classes, scriptsadd_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 ...
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 HEREclass-routes.php
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'); }
View
Page