19. deep dive
0.
The request will only go to
craft if the server routes it
to the index.php file.
[2] Request Handling
20. deep dive
1. Is it an action?
If the URL begins with
actions/ it gets routed to a
controller.
[2] Request Handling
21. deep dive
1. Is it an action?
The controller is either
built-in, or provided by a
module or plugin.
[2] Request Handling
22. 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
23. deep dive
2. Is it an element?
Does it match an element's URI?
[2] Request Handling
24. deep dive
element:
a thing that can hold data
craftelementsAsset
craftelementsCategory
craftelementsEntry
craftelementsGlobalSet
craftelementsMatrixBlock
craftelementsTag
craftelementsUser
verbbsupertableelementsSuperTableBlockElement
[2] Request Handling
25. 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
27. 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
28. 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
29. deep dive
4. Does the URI match a template?
@webroot/templates/single.twig
[2] Request Handling
30. deep dive
4. Does the URI match a template?
@webroot/templates/single.twig
Yii alias
[2] Request Handling
39. deep dive
Plugins and modules are
basically justYii modules
(sort of like Craft is!)
[4] Module & Plugin Overview
40. 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