Create the file structure
Create the following file structure and files. Explanation to the files is coming below:
Start in folder Packages:
- Applications
- Layh.Events
- Classes
- Layh
- Events
- EventController.php
- Events
- Layh
- Configuration
- Routes.yaml
- Meta
- Package.xml
- Resources
- Private
- Layouts
- Index.html
- Templates
- Event
- Index.html
- Event
- Layouts
- Public
- Private
- Classes
- Layh.Events
EventController.php
Setting the namespace is the first thing you have to do in every class. This has to be done in every php file in your complete project. Next step, add a default action, in this case it is the indexAction.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<?php namespace Layh\Events\Controller; use TYPO3\Flow\Annotations as Flow; /* * @Flow\Scope("singleton") */ class EventController extends \TYPO3\Flow\Mvc\Controller\ActionController { /** * @return void */ public function indexAction() { } } |
Routes.yaml
Define a route for the package. In this case, the uriPattern is empty so every request should match. We also define a default controller/action in the Routes.yaml
1 2 3 4 5 6 7 8 |
- name: 'Homepage' uriPattern: '' defaults: @package: Layh.Events @controller: Event @format: 'html' @action: 'index' |
1 2 3 4 5 6 7 |
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://typo3.org/ns/2008/flow3/package" version="1.0"> <key>Layh_Events</key> <title>Flow Events Package</title> <description>Demo application</description> <version>0.0.1</version> </package> |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
namespace Layh\Events; use TYPO3\FLOW3\Package\Package as BasePackage; use TYPO3\FLOW3\Annotations as FLOW3; /** * Package base class of the Layh.Events package. * * @FLOW3\Scope("singleton") */ class Package extends BasePackage { } |
Layouts/Index.html
Define your layout here. This file will be wrapped around each of you templates. Define your body-tag and head-tag here and tell Flow to render the content inside.
<f:base> is used to set the base URL.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<!DOCTYPE HTML> <html> <head> <title>TYPO3 Flow - Tutorial</title> <f:base/> </head> <body> <section class="content"> <f:render section="content"/> </section> </body> </html> |
Templates/Event/Index.html
The template for the default action. The naming of the path and file has to match the controller and the action. So the controller name is event, means that the folder has to be named “Event”.
The action name is index, so the template file has to be called “Index.html”.
If we add another action later, for example listAction, we have to create a file List.html for this action then.
1 2 3 4 5 6 |
<f:layout name="Index.html" /> <f:section name="content"> <!-- all content inside the section "content" will be displayed now --> Hello event package </f:section> |
Final Step
The package is finished now. There are to things left to do before we can start.
1. Tell FLOW3 that there exists a package with the name Events and activate the package. (/path/to/webroot/Configuration/PackageStates.php)
2. Tell FLOW3 where to find the package and for that we have to edit the Routes.yaml (/path/to/webroot/Configuration/Routes.yaml)
1 2 3 4 5 6 7 |
// add the following to the existing array in PackageStates.php 'Events' => array( 'state' => 'active', 'packagePath' => 'Application/Layh.Events', 'classesPath' => 'Classes' ), |
1 2 3 4 5 6 7 8 |
- name: 'Layh.Events' uriPattern: '<EventsSubroutes>' defaults: @format: 'html' subRoutes: EventsSubroutes: package: Layh.Events |
Package.xml
If you come from TYPO3, what I think is highly possible, this file is like ext_emconf.php, where you can that the package name and the version number.
Step 1 – Finished
If you call your URL now, you should see the content from the file Index.html in your Templates folder.
Can you please publish this example as ZIP file? That would help me a lot. Thank you
Hi Mario, bad news, I don’t have the source files for this tutorial anymore. I found some of the things in my github account and you can check if this helps you: https://github.com/tlayh/flow-playground