deep dive
deep dive[0] Introduction
$presentation = array(
'Introduction',
'Yii',
'Request Handling',
'Data Structure',
'Module & Plugin Overview',
'Q&A'
);
deep dive[1] Yii
deep dive[1] Yii
Yii is an object-oriented

model-view-controller

framework for PHP.
deep dive[1] Yii
deep dive[1] Yii
}
deep dive[1] Yii
Yii provides a way for
namespaces applications to
interact with each other.
deep dive[1] Yii
Yii provides routing.
deep dive[1] Yii
Yii provides twig.
deep dive[1] Yii
Yii provides error handling.
deep dive[1] Yii
Yii provides events.
deep dive[1] Yii
provides it's own routing.
🖕🖕
deep dive[1] Yii
provides its own twig.
🖕🖕
deep dive[1] Yii
doesn't provide it's
own error handling.
👍 👍
deep dive[1] Yii
doesn't provide it's
own events.
👍 👍
deep dive[1] Elements
use craftservicesElements;
deep dive[1] Elements
In Craft almost
everything is an element.
deep dive[2] Request Handling
Let's look at an incoming
Craft request.
deep dive
0.

The request will only go to
craft if the server routes it
to the index.php file.
[2] Request Handling
deep dive
1. Is it an action?

If the URL begins with
actions/ it gets routed to a
controller.
[2] Request Handling
deep dive
1. Is it an action?

The controller is either
built-in, or provided by a
module or plugin.
[2] Request Handling
deep dive
namespace craftcontrollers;
use Craft;
class UsersController extends Controller
{
public function actionLogin()
{
if (!Craft::$app->getUser()->getIsGuest()) {
// Too easy.
return $this->_handleSuccessfulLogin(false);
}
}
}
1. Is it an action?

The controller is
either built-in, or
provided by a
module or plugin.
GET /actions/users/active
POST /

<input type="hidden" name="action" value="users/save-user">
[2] Request Handling
deep dive
2. Is it an element?

Does it match an element's URI?
[2] Request Handling
deep dive
element:

a thing that can hold data
craftelementsAsset
craftelementsCategory
craftelementsEntry
craftelementsGlobalSet
craftelementsMatrixBlock
craftelementsTag
craftelementsUser
verbbsupertableelementsSuperTableBlockElement
[2] Request Handling
deep dive
craft_elements
id 28
fieldLayoutId 31
type craftelementsEntry
enabled 1
craft_elements_sites
id 32
elementId 28
siteId 1
slug about-us
uri company/about-us
[2] Request Handling
deep dive
craft_elements
id 28
fieldLayoutId 31
type craftelementsEntry
enabled 1
[2] Request Handling
deep dive
craft_elements
id 28
fieldLayoutId 31
type craftelementsEntry
enabled 1
craft_elements_sites
id 32
elementId 28
siteId 1
slug about-us
uri company/about-us
routing uri
[2] Request Handling
deep dive
3. Does the URI match a
route or URI rule?
return [
// Route blog/archive/YYYY to a controller action
'blog/archive/<year:d{4}>' => 'controller/action/path',
// Route blog/archive/YYYY to a template
'blog/archive/<year:d{4}>' => ['template' => 'blog/_archive'],
];
config/routes.php
<h1>Blog Entries from {{ year }}</h1>
[2] Request Handling
deep dive
4. Does the URI match a template?
@webroot/templates/single.twig
[2] Request Handling
deep dive
4. Does the URI match a template?
@webroot/templates/single.twig
Yii alias
[2] Request Handling
deep dive
5.Well I guess we'll just 404.
[2] Request Handling
deep dive[3] Data Structure
Let's visualize the
CraftCMS DB Structure
deep dive
Ok maybe let's not do that.
[3] Data Structure
deep dive
Let's look at the
Wordpress schema.
[3] Data Structure
deep dive[4] Module & Plugin Overview
Not suited for the complex
content architecture we require.
deep dive[4] Module & Plugin Overview
Let's talk about plugins.
deep dive
Plugins and modules are
basically justYii modules
(sort of like Craft is!)
[4] Module & Plugin Overview
deep dive
Plugins:
Installed through Composer,

can be turned on and off in admin.

(Usually) site-agnostic functionality
Modules:
Hardcoded into composer andYii
configs. Cannot be turned off in admin.

(Usually) site-specific functionality
[4] Module & Plugin Overview
deep dive[4] Module & Plugin Overview
deep dive
This is meta because Craft implements
all of these things on its own.
[4] Module & Plugin Overview
deep dive
CSS, JS, and Images needed in the
Admin side of Craft
[4] Module & Plugin Overview
deep dive
Tasks that can be run through
the Craft CLI
[4] Module & Plugin Overview
deep dive
Endpoints that are accessible
through a URL path
[4] Module & Plugin Overview
deep dive
Main application class file.
Registers hooks, events, etc
[4] Module & Plugin Overview
deep dive
New elements (like SuperTable
Blocks for example)
[4] Module & Plugin Overview
deep dive
New fields (like a markdown
editor that stores HTML)
[4] Module & Plugin Overview
deep dive
New queued tasks (like image
transformation)
[4] Module & Plugin Overview
deep dive
Installation / uninstallation
migrations
[4] Module & Plugin Overview
deep dive
A "template" for a custom data
structure
[4] Module & Plugin Overview
deep dive
A way to represent data
from a model and define
how it is stored / retrieved in
the DB
[4] Module & Plugin Overview
deep dive
The "business logic" of the
application/plugin/module
[4] Module & Plugin Overview
deep dive
Twig templates for the admin
side of your plugin
[4] Module & Plugin Overview
deep dive
Functional additions toTwig
(like twig-dig!)
[4] Module & Plugin Overview
deep dive
Add twig pages that appear
under "Utilities" in the Admin
[4] Module & Plugin Overview
deep dive
Add custom twig variables
accessible under the craft
namespace. (Like
{{ craft.testvariable }})
[4] Module & Plugin Overview
deep dive
Widgets for the admin dashboard.
[4] Module & Plugin Overview
deep dive[5] Q & A
Q&A

CraftCMS 3.x Deep Dive