SlideShare una empresa de Scribd logo
1 de 32
Descargar para leer sin conexión
#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

Más contenido relacionado

La actualidad más candente

Your first sinatra app
Your first sinatra appYour first sinatra app
Your first sinatra app
Rubyc Slides
 
How Danga::Socket handles asynchronous processing and how to write asynchrono...
How Danga::Socket handles asynchronous processing and how to write asynchrono...How Danga::Socket handles asynchronous processing and how to write asynchrono...
How Danga::Socket handles asynchronous processing and how to write asynchrono...
Gosuke Miyashita
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Tatsuhiko Miyagawa
 

La actualidad más candente (20)

Laravel 101
Laravel 101Laravel 101
Laravel 101
 
CPAN Dependency Heaven
CPAN Dependency HeavenCPAN Dependency Heaven
CPAN Dependency Heaven
 
Intro to Laravel 4
Intro to Laravel 4Intro to Laravel 4
Intro to Laravel 4
 
Perlbal Tutorial
Perlbal TutorialPerlbal Tutorial
Perlbal Tutorial
 
Laravel - Website Development in Php Framework.
Laravel - Website Development in Php Framework.Laravel - Website Development in Php Framework.
Laravel - Website Development in Php Framework.
 
Migraine Drupal - syncing your staging and live sites
Migraine Drupal - syncing your staging and live sitesMigraine Drupal - syncing your staging and live sites
Migraine Drupal - syncing your staging and live sites
 
Your first sinatra app
Your first sinatra appYour first sinatra app
Your first sinatra app
 
Building web framework with Rack
Building web framework with RackBuilding web framework with Rack
Building web framework with Rack
 
How Danga::Socket handles asynchronous processing and how to write asynchrono...
How Danga::Socket handles asynchronous processing and how to write asynchrono...How Danga::Socket handles asynchronous processing and how to write asynchrono...
How Danga::Socket handles asynchronous processing and how to write asynchrono...
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
 
appache_1
appache_1appache_1
appache_1
 
HTML5 tutorial: canvas, offfline & sockets
HTML5 tutorial: canvas, offfline & socketsHTML5 tutorial: canvas, offfline & sockets
HTML5 tutorial: canvas, offfline & sockets
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
Master the New Core of Drupal 8 Now: with Symfony and Silex
Master the New Core of Drupal 8 Now: with Symfony and SilexMaster the New Core of Drupal 8 Now: with Symfony and Silex
Master the New Core of Drupal 8 Now: with Symfony and Silex
 
Wykorzystanie form request przy implementacji API w Laravelu
Wykorzystanie form request przy implementacji API w LaraveluWykorzystanie form request przy implementacji API w Laravelu
Wykorzystanie form request przy implementacji API w Laravelu
 
Intro to PSGI and Plack
Intro to PSGI and PlackIntro to PSGI and Plack
Intro to PSGI and Plack
 
Ruby MVC from scratch with Rack
Ruby MVC from scratch with RackRuby MVC from scratch with Rack
Ruby MVC from scratch with Rack
 
Tatsumaki
TatsumakiTatsumaki
Tatsumaki
 
Plack - LPW 2009
Plack - LPW 2009Plack - LPW 2009
Plack - LPW 2009
 
Flask
FlaskFlask
Flask
 

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

Laying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme developmentLaying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme development
Tammy Hart
 
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Lorvent56
 

Similar a WP Weekend #2 - Corcel, aneb WordPress přes Laravel (20)

Getting to know Laravel 5
Getting to know Laravel 5Getting to know Laravel 5
Getting to know Laravel 5
 
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
 
DevOps in PHP environment
DevOps in PHP environment DevOps in PHP environment
DevOps in PHP environment
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
 
RESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher PecoraroRESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher Pecoraro
 
Laravel presentation
Laravel presentationLaravel presentation
Laravel presentation
 
New PHP Exploitation Techniques
New PHP Exploitation TechniquesNew PHP Exploitation Techniques
New PHP Exploitation Techniques
 
The Enterprise Wor/d/thy/Press
The Enterprise Wor/d/thy/PressThe Enterprise Wor/d/thy/Press
The Enterprise Wor/d/thy/Press
 
6. Add numbers in Laravel
6. Add numbers in Laravel6. Add numbers in Laravel
6. Add numbers in Laravel
 
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
 
From CakePHP to Laravel
From CakePHP to LaravelFrom CakePHP to Laravel
From CakePHP to Laravel
 
Pecl Picks
Pecl PicksPecl Picks
Pecl Picks
 
[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development
 
WCLA12 JavaScript
WCLA12 JavaScriptWCLA12 JavaScript
WCLA12 JavaScript
 
Laying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme developmentLaying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme development
 
Apache and PHP: Why httpd.conf is your new BFF!
Apache and PHP: Why httpd.conf is your new BFF!Apache and PHP: Why httpd.conf is your new BFF!
Apache and PHP: Why httpd.conf is your new BFF!
 
Vagrant WordCamp Hamilton
Vagrant  WordCamp HamiltonVagrant  WordCamp Hamilton
Vagrant WordCamp Hamilton
 
Using WordPress as your application stack
Using WordPress as your application stackUsing WordPress as your application stack
Using WordPress as your application stack
 
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
 
Os Treat
Os TreatOs Treat
Os Treat
 

Más de Brilo Team

Más de Brilo Team (20)

PHP Vysočina - WordPress - 25.10.2018
PHP Vysočina - WordPress - 25.10.2018PHP Vysočina - WordPress - 25.10.2018
PHP Vysočina - WordPress - 25.10.2018
 
Nástroj Calfou.cz - WP Weekend #3
Nástroj Calfou.cz - WP Weekend #3Nástroj Calfou.cz - WP Weekend #3
Nástroj Calfou.cz - WP Weekend #3
 
WPML - jak na vícejazyčný web - WP Weekend #3
WPML - jak na vícejazyčný web - WP Weekend #3WPML - jak na vícejazyčný web - WP Weekend #3
WPML - jak na vícejazyčný web - WP Weekend #3
 
HTML stack pro WP šablonu - WP Weekend #3
HTML stack pro WP šablonu - WP Weekend #3HTML stack pro WP šablonu - WP Weekend #3
HTML stack pro WP šablonu - WP Weekend #3
 
WordPress "root" skripty - WP Weekend #3
WordPress "root" skripty - WP Weekend #3 WordPress "root" skripty - WP Weekend #3
WordPress "root" skripty - WP Weekend #3
 
PoSobota 96 ČB 28.4.2018
PoSobota 96 ČB 28.4.2018PoSobota 96 ČB 28.4.2018
PoSobota 96 ČB 28.4.2018
 
WP Frameworky - WordCamp Praha 2018
WP Frameworky - WordCamp Praha 2018WP Frameworky - WordCamp Praha 2018
WP Frameworky - WordCamp Praha 2018
 
Jak spolehlivě potopit web nebo e-shop | Pux 1.11.17
Jak spolehlivě potopit web nebo e-shop | Pux 1.11.17Jak spolehlivě potopit web nebo e-shop | Pux 1.11.17
Jak spolehlivě potopit web nebo e-shop | Pux 1.11.17
 
WordCamp Bratislava 2017 - Martin Hlaváč
WordCamp Bratislava 2017 - Martin HlaváčWordCamp Bratislava 2017 - Martin Hlaváč
WordCamp Bratislava 2017 - Martin Hlaváč
 
WordCamp Bratislava 2017 - Jakub Hladký
WordCamp Bratislava 2017 - Jakub HladkýWordCamp Bratislava 2017 - Jakub Hladký
WordCamp Bratislava 2017 - Jakub Hladký
 
Pux 28.2.2017 Úvod do internetového marketingu
Pux 28.2.2017 Úvod do internetového marketinguPux 28.2.2017 Úvod do internetového marketingu
Pux 28.2.2017 Úvod do internetového marketingu
 
WordCamp Praha 2017 - Tomáš Kocifaj
WordCamp Praha 2017 - Tomáš KocifajWordCamp Praha 2017 - Tomáš Kocifaj
WordCamp Praha 2017 - Tomáš Kocifaj
 
WordCamp Praha 2017 - Martin Hlaváč
WordCamp Praha 2017 - Martin HlaváčWordCamp Praha 2017 - Martin Hlaváč
WordCamp Praha 2017 - Martin Hlaváč
 
Jihočeské vzdělávání dospělých - SEO část
Jihočeské vzdělávání dospělých - SEO částJihočeské vzdělávání dospělých - SEO část
Jihočeské vzdělávání dospělých - SEO část
 
Jihočeské vzdělávání dospělých
Jihočeské vzdělávání dospělýchJihočeské vzdělávání dospělých
Jihočeské vzdělávání dospělých
 
Chytrá propagace e-shopu pomocí témat - Eshopvíkend 2016
Chytrá propagace e-shopu pomocí témat - Eshopvíkend 2016Chytrá propagace e-shopu pomocí témat - Eshopvíkend 2016
Chytrá propagace e-shopu pomocí témat - Eshopvíkend 2016
 
Základy Sociálních médií - WP Konference 2016 Praha
Základy Sociálních médií - WP Konference 2016 PrahaZáklady Sociálních médií - WP Konference 2016 Praha
Základy Sociálních médií - WP Konference 2016 Praha
 
Základy Marketingu - WP Konference 2016 Praha
Základy Marketingu - WP Konference 2016 PrahaZáklady Marketingu - WP Konference 2016 Praha
Základy Marketingu - WP Konference 2016 Praha
 
Plánování webu - WP Konference 2016 Praha
Plánování webu - WP Konference 2016 PrahaPlánování webu - WP Konference 2016 Praha
Plánování webu - WP Konference 2016 Praha
 
Brilo team zaklady SEO WPkonference 25.6.2016
Brilo team zaklady SEO WPkonference 25.6.2016Brilo team zaklady SEO WPkonference 25.6.2016
Brilo team zaklady SEO WPkonference 25.6.2016
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Último (20)

Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

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

  • 1.
  • 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