Getting started with ExtBase

13
Starting with ExtBase

description

ExtBase starting tutorial from TYPO3 camp Regensburg #t3cr

Transcript of Getting started with ExtBase

Page 1: Getting started with ExtBase

Starting with ExtBase

Page 2: Getting started with ExtBase

Grundaufbau ExtBase/Fluid Model: Product

• Title • Price

Repository • findAll

• findByProperty

Controller • List • Show

Fluid Template • List

Fluid Template • Show

Page 3: Getting started with ExtBase

Grundaufbau ExtBase/Fluid

Model

Controller

Fluid Template

public function getTitle() { return $this->title; }

public function listAction() { $products = $this->productRepository->findAll(); $this->view->assign('products', $products); }

<f:for each="{products}" as="product"> <tr> <td> <f:link.action action="show" arguments="{product : product}"> {product.title} </f:link.action> </td> </tr> </f:for>

Page 4: Getting started with ExtBase

ViewHelper

Fluid Template {namespace as=TYPO3\AsViewhelper\ViewHelpers} <f:for each="{products}" as="product"> <tr> <td> <f:link.action action="show" arguments="{product : product}"> <as:uppercase value="{product.title}" /> </f:link.action> </td> </tr> </f:for>

ViewHelper class UppercaseViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper { public function render($value) { return strtoupper($value); } }

Page 5: Getting started with ExtBase

Extension Builder

Page 6: Getting started with ExtBase

Extension Builder

Page 7: Getting started with ExtBase

Extension Builder: Relations

• Hauptobjekt: Product – aggregate root

• Untertabellen: Color

• Relations: Drag & Drop mit dem Kreis

• More->Type: 1:1, 1:n, n:1, n:m

Page 8: Getting started with ExtBase

Verzeichnisstruktur

- Classes --- Controller --- Domain --- ViewHelpers - Configuration --- FlexForms --- TCA --- TypoScript - Resources --- Private ----- Templates --- Public ----CSS ----JS

Page 9: Getting started with ExtBase

Konventionen

• phpDoc vor Funktionen

• Camel-Case, Lower-Camel-Case, Unterstrich,…?

– Class: AsDemoExtbase

– Variable: asDemoExtbase

– Datenbank: as_demo_extbase

Page 10: Getting started with ExtBase

Datenbank: Repository

• Sehr viele Default-Funktionen: • findAll = SELECT * FROM table • findByName($val) =

SELECT * FROM table where name like „$val • findOneByArticleNo($id)

SELECT … limit 1 • Add, remove, update, replace, • $query->createQuery; $query->matching(),

constraints, $query->execute • SQL: $query->statement(„SELECT ….“)

Page 11: Getting started with ExtBase

ObjectManager

• PHP: new TYPO3: t3lib_div::createInstance

• Extbase: Singleton, DependencyInjection

• objectManager->get (Controller, Repository)

• objectManager->create (Model), danach im Repistory: $this->add($obj)

$prod=$this->objectManager->create

('TYPO3\\Asextbasedemo1\\Domain\\Model\\Product');

$prod->setTitle("AutoCreated");

$this->productRepository->add($prod);

2 Slashes in Namespace Path!

Page 12: Getting started with ExtBase

Nice to know

• piBased: $this->pi_getLL('languagekey')

• \TYPO3\CMS\Extbase\Utility\LocalizationUtility::tr

anslate('languagekey', $extensionName)

(extensionName: Ordnername in typo3conf/ext)

Page 13: Getting started with ExtBase

Links

• Tutorial: http://www.typo3lexikon.de/typo3-tutorials/extensions/fluid.html

• Extbase Buch Kurfürst: http://docs.typo3.org/typo3cms/ExtbaseFluidBook/

• Mittwald: ExtBase Referenz PDF https://www.mittwald.de/typo3-dokumentation/

• Tips: http://t3n.de/magazin/zehn-tipps-tricks-extbase-fluid-227639/

• Namespaces: http://www.speedprogs.de/anleitungen/detailansicht/extension-entwicklung-mit-namespaces.html