SlideShare a Scribd company logo
WP Weekend #2 - Corcel, aneb WordPress přes Laravel
#wpweekendcz | @hlavacm
#wpweekendcz | @hlavacm
#wpweekendcz | @hlavacm
Composer?
Bedrock,
aneb WordPress
přes Composer
Brilo (Team) Blog:
brilo.cz/bedrock-aneb-wordpress-pres-composer
#wpweekendcz | @hlavacm
Téma a obsah
1. Laravel framework
2. Knihovna Corcel
3. WordPress demo
#wpweekendcz | @hlavacm
1. Laravel
PHP MVC framework, který je
optimalizovaný pro reálný svět
https://laravel.com
#wpweekendcz | @hlavacm
Laravel - služby
Laravel & Lumen
Homestead & Valet
Laracasts & Laracon
Cashier & Spark
Forge & Envoyer
a další ...
#wpweekendcz | @hlavacm
Laravel 5.4 - požadavky
■ PHP >= 5.6.4
■ OpenSSL PHP Extension
■ PDO PHP Extension
■ Mbstring PHP Extension
■ Tokenizer PHP Extension
■ XML PHP Extension
#wpweekendcz | @hlavacm
Laravel - instalace
$ composer global require "laravel/installer"
$ laravel new blog
$ composer create-project --prefer-dist "laravel/laravel" blog
#wpweekendcz | @hlavacm
Laravel - konzole
$ php artisan make:controller
UserController --resource
#wpweekendcz | @hlavacm
Laravel - kód
<?php
namespace AppHttpControllers;
use AppUser;
use AppHttpControllersController;
class UserController extends Controller
{
public function show($id)
{
return view("user.profile", ["user" => User::findOrFail($id)]);
}
}
#wpweekendcz | @hlavacm
Laravel - routování
Route::get/post/put/patch/delete/options($uri, $callback);
Route::get("user/{id}", function ($id) {
return "User: $id";
});
Route::get("profile", "UserController@show")->middleware("auth");
Route::resource("users", "UserController");
#wpweekendcz | @hlavacm
Laravel - šablony
<html>
<head>
<title>App Name - @yield("title")</title>
</head>
<body>
@while (true)
<p>I"m looping forever.</p>
@endwhile
<div class="container">
@yield("content")
</div>
</body>
</html>
#wpweekendcz | @hlavacm
Laravel - Eloquent (ORM)
$users = AppUser::all();
foreach ($users as $user) {
echo $user->display_name;
}
$users = AppUser::where("user_status", 1)
->orderBy("user_registered", "desc")
->take(10)
->get();
$user = AppUser::find(1);
$user = AppUser::where("user_status", 0)->first();
#wpweekendcz | @hlavacm
2. Corcel
This package allows you to use
WordPress as backend (admin panel) and
retrieve its data using Eloquent, with any
PHP project or even framework.
https://github.com/corcel/corcel
#wpweekendcz | @hlavacm
Corcel - instalace
$ composer require jgrossi/corcel
#wpweekendcz | @hlavacm
Corcel - konfigurace
<?php // File: /config/database.php
"connections" => [
"mysql" => [ … ],
"wordpress" => [
"driver" => "mysql",
"host" => "localhost",
"database" => "corcel",
"username" => "admin",
"password" => "secret",
"charset" => "utf8",
"collation" => "utf8_unicode_ci",
"prefix" => "wp_",
"strict" => false,
"engine" => null,
],
],
#wpweekendcz | @hlavacm
Corcel - modely
<?php // File: app/Post.php
namespace App;
use CorcelPost as Corcel;
class Post extends Corcel {
protected $connection = "wordpress";
}
#wpweekendcz | @hlavacm
Corcel - volání
// using the "wordpress" connection
$posts = AppPost::all();
// using the "default" Laravel connection
$posts = CorcelPost::all();
#wpweekendcz | @hlavacm
Corcel - posty
// All published posts
$posts = Post::published()->get();
$posts = Post::status("publish")->get();
// A specific post
$post = Post::find(31);
echo $post->post_title;
// Filter by meta/custom field
$posts = Post::published()->hasMeta("field")->get();
$posts = Post::hasMeta("acf")->get();
#wpweekendcz | @hlavacm
Corcel - save
$post = new Post;
$post->save();
$post = Post::find(1);
$post->meta->username = "juniorgrossi";
$post->meta->url = "http://grossi.io";
$post->save();
#wpweekendcz | @hlavacm
Corcel - custom post type
// using type() method
$videos = Post::type("video")->status("publish")->get();
// using your own class
class Video extends CorcelPost
{
protected $postType = "video";
}
$videos = Video::status("publish")->get();
#wpweekendcz | @hlavacm
Corcel - uživatelé
// only all categories and posts connected with it
$cat = Taxonomy::where("taxonomy", "category")
->with("posts")->get();
$cat->each(function($category) {
echo $category->name;
});
// clean and simple all posts from a category
$cat = Category::slug("uncategorized")->posts()->first();
$cat->posts->each(function($post) {
echo $post->post_title;
});
#wpweekendcz | @hlavacm
Corcel - uživatelé
// All users
$users = User::get();
// A specific user
$user = User::find(1);
echo $user->user_login;
#wpweekendcz | @hlavacm
Corcel - co umí?
■ Posts
■ Advanced Custom Fields (ACF)
■ Custom Post Type
■ Shortcodes
■ Taxonomies
■ Post Format
■ Pages
■ Categories & Taxonomies
■ Attachment and Revision
■ Menu
■ Users
■ Authentication
#wpweekendcz | @hlavacm
Corcel - kdekoliv?
require __DIR__ . "/vendor/autoload.php";
$params = array(
"database" => "database_name",
"username" => "username",
"password" => "pa$$word",
"prefix" => "wp_"
);
CorcelDatabase::connect($params);
#wpweekendcz | @hlavacm
#wpweekendcz | @hlavacm
3. Demo + #kimnaslidu
#wpweekendcz | @hlavacm
Shrnutí
Laravel + Corcel = ♥
#wpweekendcz | @hlavacm
Front End
Framework Knihovna
Využití
Programátoři
Front end
Neumí vše ⚠
#wpweekendcz | @hlavacm
WP Weekend #2 - Corcel, aneb WordPress přes Laravel

More Related Content

WP Weekend #2 - Corcel, aneb WordPress přes Laravel

  • 5. Composer? Bedrock, aneb WordPress přes Composer Brilo (Team) Blog: brilo.cz/bedrock-aneb-wordpress-pres-composer #wpweekendcz | @hlavacm
  • 6. Téma a obsah 1. Laravel framework 2. Knihovna Corcel 3. WordPress demo #wpweekendcz | @hlavacm
  • 7. 1. Laravel PHP MVC framework, který je optimalizovaný pro reálný svět https://laravel.com #wpweekendcz | @hlavacm
  • 8. Laravel - služby Laravel & Lumen Homestead & Valet Laracasts & Laracon Cashier & Spark Forge & Envoyer a další ... #wpweekendcz | @hlavacm
  • 9. Laravel 5.4 - požadavky ■ PHP >= 5.6.4 ■ OpenSSL PHP Extension ■ PDO PHP Extension ■ Mbstring PHP Extension ■ Tokenizer PHP Extension ■ XML PHP Extension #wpweekendcz | @hlavacm
  • 10. Laravel - instalace $ composer global require "laravel/installer" $ laravel new blog $ composer create-project --prefer-dist "laravel/laravel" blog #wpweekendcz | @hlavacm
  • 11. Laravel - konzole $ php artisan make:controller UserController --resource #wpweekendcz | @hlavacm
  • 12. Laravel - kód <?php namespace AppHttpControllers; use AppUser; use AppHttpControllersController; class UserController extends Controller { public function show($id) { return view("user.profile", ["user" => User::findOrFail($id)]); } } #wpweekendcz | @hlavacm
  • 13. Laravel - routování Route::get/post/put/patch/delete/options($uri, $callback); Route::get("user/{id}", function ($id) { return "User: $id"; }); Route::get("profile", "UserController@show")->middleware("auth"); Route::resource("users", "UserController"); #wpweekendcz | @hlavacm
  • 14. Laravel - šablony <html> <head> <title>App Name - @yield("title")</title> </head> <body> @while (true) <p>I"m looping forever.</p> @endwhile <div class="container"> @yield("content") </div> </body> </html> #wpweekendcz | @hlavacm
  • 15. Laravel - Eloquent (ORM) $users = AppUser::all(); foreach ($users as $user) { echo $user->display_name; } $users = AppUser::where("user_status", 1) ->orderBy("user_registered", "desc") ->take(10) ->get(); $user = AppUser::find(1); $user = AppUser::where("user_status", 0)->first(); #wpweekendcz | @hlavacm
  • 16. 2. Corcel This package allows you to use WordPress as backend (admin panel) and retrieve its data using Eloquent, with any PHP project or even framework. https://github.com/corcel/corcel #wpweekendcz | @hlavacm
  • 17. Corcel - instalace $ composer require jgrossi/corcel #wpweekendcz | @hlavacm
  • 18. Corcel - konfigurace <?php // File: /config/database.php "connections" => [ "mysql" => [ … ], "wordpress" => [ "driver" => "mysql", "host" => "localhost", "database" => "corcel", "username" => "admin", "password" => "secret", "charset" => "utf8", "collation" => "utf8_unicode_ci", "prefix" => "wp_", "strict" => false, "engine" => null, ], ], #wpweekendcz | @hlavacm
  • 19. Corcel - modely <?php // File: app/Post.php namespace App; use CorcelPost as Corcel; class Post extends Corcel { protected $connection = "wordpress"; } #wpweekendcz | @hlavacm
  • 20. Corcel - volání // using the "wordpress" connection $posts = AppPost::all(); // using the "default" Laravel connection $posts = CorcelPost::all(); #wpweekendcz | @hlavacm
  • 21. Corcel - posty // All published posts $posts = Post::published()->get(); $posts = Post::status("publish")->get(); // A specific post $post = Post::find(31); echo $post->post_title; // Filter by meta/custom field $posts = Post::published()->hasMeta("field")->get(); $posts = Post::hasMeta("acf")->get(); #wpweekendcz | @hlavacm
  • 22. Corcel - save $post = new Post; $post->save(); $post = Post::find(1); $post->meta->username = "juniorgrossi"; $post->meta->url = "http://grossi.io"; $post->save(); #wpweekendcz | @hlavacm
  • 23. Corcel - custom post type // using type() method $videos = Post::type("video")->status("publish")->get(); // using your own class class Video extends CorcelPost { protected $postType = "video"; } $videos = Video::status("publish")->get(); #wpweekendcz | @hlavacm
  • 24. Corcel - uživatelé // only all categories and posts connected with it $cat = Taxonomy::where("taxonomy", "category") ->with("posts")->get(); $cat->each(function($category) { echo $category->name; }); // clean and simple all posts from a category $cat = Category::slug("uncategorized")->posts()->first(); $cat->posts->each(function($post) { echo $post->post_title; }); #wpweekendcz | @hlavacm
  • 25. Corcel - uživatelé // All users $users = User::get(); // A specific user $user = User::find(1); echo $user->user_login; #wpweekendcz | @hlavacm
  • 26. Corcel - co umí? ■ Posts ■ Advanced Custom Fields (ACF) ■ Custom Post Type ■ Shortcodes ■ Taxonomies ■ Post Format ■ Pages ■ Categories & Taxonomies ■ Attachment and Revision ■ Menu ■ Users ■ Authentication #wpweekendcz | @hlavacm
  • 27. Corcel - kdekoliv? require __DIR__ . "/vendor/autoload.php"; $params = array( "database" => "database_name", "username" => "username", "password" => "pa$$word", "prefix" => "wp_" ); CorcelDatabase::connect($params); #wpweekendcz | @hlavacm
  • 29. 3. Demo + #kimnaslidu #wpweekendcz | @hlavacm
  • 30. Shrnutí Laravel + Corcel = ♥ #wpweekendcz | @hlavacm Front End Framework Knihovna
  • 31. Využití Programátoři Front end Neumí vše ⚠ #wpweekendcz | @hlavacm