• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Einführung in FLOW3/ Blog Package
 

Einführung in FLOW3/ Blog Package

on

  • 5,539 views

Einführung in FLOW3 mit dem Blockpackage als Referenz.

Einführung in FLOW3 mit dem Blockpackage als Referenz.

Gehalten an der MFUG
http://www.mfug.de

Statistics

Views

Total Views
5,539
Views on SlideShare
4,514
Embed Views
1,025

Actions

Likes
2
Downloads
15
Comments
0

4 Embeds 1,025

http://flow3.typo3.org 719
http://www.mfug.de 244
http://mfug.de 61
http://translate.googleusercontent.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Einführung in FLOW3/ Blog Package Einführung in FLOW3/ Blog Package Presentation Transcript

    • Überblick über FLOW3 mit dem Blog-Package als Referenz
    • Agenda • Domain Model • Package Aufbau • Model • Validation • Association Mapping • Model und Repository • Repository • Blog Repsitory • Post Repository • Controller • View • Validation • RoutingDatum: 10.01.2012 FLOW3 Einführung / Blog Package www.cross-content.com @MarkusGoldbeck 2
    • Domain ModelDatum: 10.01.2012 FLOW3 Einführung / Blog Package www.cross-content.com @MarkusGoldbeck 3
    • Package AufbauDatum: 10.01.2012 FLOW3 Einführung / Blog Package www.cross-content.com @MarkusGoldbeck 4
    • Model • Namespace namespaceBlogDomainModel; • Namespace namespace TYPO3BlogDomainModel; • Namespace namespace TYPO3BlogDomainModel; • Namespace namespace TYPO3BlogDomainModel;Datum: 06.12.2011 FLOW3 Einführung / log Package www.cross-content.com @MarkusGoldbeck 5
    • TYPO3BlogDomainModel Post • Namespace namespace TYPO3BlogDomainModel; • Annotations use DoctrineORMMapping as ORM; use TYPO3FLOW3Annotations as FLOW3; • Class Post • Dieses Model nach den Konzepten von DDD eine Entitiy • Instanzen dieser Klasse können gespeichert werden /** * A blog * * @FLOW3Entity */ class Post {Datum: 10.01.2012 FLOW3 Einführung / Blog Package www.cross-content.com @MarkusGoldbeck 6
    • TYPO3BlogDomainModel Post • Properties • Variablen Deklaration als String • Validierung auf Datentyp und Länge • Validierung des Datentyps innerhalb des Models und Repositories /** * The post‘s title. * * @var string * @FLOW3Validate(type="Text") * @FLOW3Validate(type="StringLength", options={ "minimum"=1, "maximum"=80 }) * @ORMColumn(length=80) */ protected $title = ;Datum: 10.01.2012 FLOW3 Einführung / Blog Package www.cross-content.com @MarkusGoldbeck 7
    • TYPO3BlogDomainModel Post • Property $date • Deklaration als Date Objekt • Identity /** * @FLOW3Identity * @var DateTime */ protected $date; • Property $blog • Deklaration als Blog Objekt • Association Mapping OneToMany /** * @var TYPO3BlogDomainModelBlog * @ORMManyToOne(inversedBy="posts") */ protected $blog;Datum: 10.01.2012 FLOW3 Einführung / Blog Package www.cross-content.com @MarkusGoldbeck 8
    • Association Mapping • OneToMany <-> ManyToOne /** The posts contained in this blog * @var DoctrineCommonCollectionsCollection<TYPO3Blog DomainModelPost> * @ORMOneToMany(mappedBy="blog") * @ORMOrderBy({"date" = "DESC"}) */ protected $posts; Model Blog Model Post $posts $blog /**The blog * @var TYPO3BlogDomainModelBlog * @ORMManyToOne(inversedBy="posts") */ protected $blog;Datum: 10.01.2012 FLOW3 Einführung / Blog Package www.cross-content.com @MarkusGoldbeck 9
    • Association Mapping • ManyToMany <-> ManyToMany /** * @var DoctrineCommonCollectionsCollection<TYPO3Blog DomainModelTag> * @ORMManyToMany(inversedBy="posts") */ protected $tags; Model Post Model Tag $tags $posts /**The posts tagged with this tag * @var DoctrineCommonCollectionsCollection<TYPO3Blog DomainModelPost> * @ORMManyToMany(mappedBy="tags") */ protected $posts;Datum: 10.01.2012 FLOW3 Einführung / Blog Package www.cross-content.com @MarkusGoldbeck 10
    • TYPO3BlogDomainModel BlogDatum: 10.01.2012 FLOW3 Einführung / Blog Package www.cross-content.com @MarkusGoldbeck 11
    • TYPO3BlogDomainModel PostDatum: 10.01.2012 FLOW3 Einführung / Blog Package www.cross-content.com @MarkusGoldbeck 12
    • TYPO3BlogDomainModel Blog • Setter /**Sets this blogs title * @param string $title The blogs title * @return void */ public function setTitle($title) { $this->title = $title; } • Getter /**Returns the blogs title * @return string The blogs title */ public function getTitle() { return $this->title; }Datum: 10.01.2012 FLOW3 Einführung / Blog Package www.cross-content.com @MarkusGoldbeck 13
    • Model und RepositoriesDatum: 10.01.2012 FLOW3 Einführung / Blog Package www.cross-content.com @MarkusGoldbeck 14
    • Blog Repository • Standard Blog Repository <?php namespace TYPO3BlogDomainRepository; /* * This script belongs to the FLOW3 package "TYPO3.Blog". */ /** * A repository for Blogs * * @FLOW3Scope("singleton") */ class BlogRepository extends TYPO3FLOW3PersistenceRepository { // add customized methods here } ?>Datum: 10.01.2012 FLOW3 Einführung / Blog Package www.cross-content.com @MarkusGoldbeck 15
    • Blog Repository • Standard Methoden des Repositories • add • remove • findAll • findBy* (magic methods) • findOneBy* (magic methods) findBy* und findOneBy* sind sog. Magic Methods die durch das Repository zur Verfügung gestellt werden. Diese Methoden erlauben einen Objekte durch Properties zu finden. Das BlogRepository zum Beispiel erlaubt einem die Magic Methoden findByDescription(foo) oder findOneByTitle(bar)auszuführen.Datum: 10.01.2012 FLOW3 Einführung / Blog Package www.cross-content.com @MarkusGoldbeck 16
    • Post Repository • Post Repository spezifische Methode findByBlog /** * Finds posts by the specified blog * @param TYPO3BlogDomainModelBlog $blog The blog the post must refer to * @param integer $limit The number of posts to return at max * @return TYPO3FLOW3PersistenceQueryResultProxy The posts */ public function findByBlog(TYPO3BlogDomainModelBlog $blog) { $query = $this->createQuery(); return $query->matching($query->equals(blog, $blog)) ->setOrderings( array(date => QueryInterface::ORDER_DESCENDING)) ->execute(); }Datum: 10.01.2012 FLOW3 Einführung / Blog Package www.cross-content.com @MarkusGoldbeck 17
    • Post Repository • Post Repository spezifische Methode findByTagAndBlog /**Finds posts by the specified tag and blog * @param TYPO3BlogDomainModelTag $tag * @param TYPO3BlogDomainModelBlog $blog The blog the post must refer to * @return TYPO3FLOW3PersistenceQueryResultProxy The posts */ public function findByTagAndBlog(TYPO3BlogDomainModelTag $tag, TYPO3BlogDomainModelBlog $blog) { $query = $this->createQuery(); return $query->matching( $query->logicalAnd( $query->equals(blog, $blog), $query->contains(tags, $tag) ) ) ->setOrderings(array(date => QueryInterface::ORDER_DESCENDING)) ->execute(); }Datum: 10.01.2012 FLOW3 Einführung / Blog Package www.cross-content.com @MarkusGoldbeck 18
    • Post Repository • Post Repository spezifische Methode findRecentByBlog /** * Finds most recent posts by the specified blog * * @param TYPO3BlogDomainModelBlog $blog The blog the post must refer to * @param integer $limit The number of posts to return at max * @return TYPO3FLOW3PersistenceQueryResultProxy The posts */ public function findRecentByBlog(TYPO3BlogDomainModelBlog $blog, $limit = 5) { $query = $this->createQuery(); return $query->matching($query->equals(blog, $blog)) ->setOrderings(array(date => QueryInterface::ORDER_DESCENDING)) ->setLimit($limit) ->execute(); }Datum: 10.01.2012 FLOW3 Einführung / Blog Package www.cross-content.com @MarkusGoldbeck 19
    • Post Controller • Post Controller indexAction() /** * List action for this controller. Displays latest posts * @param TYPO3BlogDomainModelTag $tag The tag to display posts for * @param TYPO3BlogDomainModelCategory $category The category to display posts for * @return void */ public function indexAction(TYPO3BlogDomainModelTag $tag = NULL, TYPO3Blog DomainModelCategory $category = NULL) { if ($tag === NULL && $category === NULL) { $posts = $this->postRepository->findByBlog($this->blog); } elseif ($tag !== NULL) { $posts = $this->postRepository->findByTagAndBlog($tag, $this->blog); $this->view->assign(tag, $tag); } else { $posts = $this->postRepository->findByCategoryAndBlog($category, $this->blog); $this->view->assign(category, $category); } $this->view->assign(blog, $this->blog); $this->view->assign(posts, $posts); $this->view->assign(recentPosts, $this->postRepository->findRecentByBlog($this- >blog)); }Datum: 10.01.2012 FLOW3 Einführung / Blog Package www.cross-content.com @MarkusGoldbeck 20
    • Post Controller • Post Controller Dependency Injection /** * @FLOW3Inject * @var TYPO3BlogDomainRepositoryCategoryRepository */ protected $categoryRepository; /**Displays a form for creating a new post * @return void */ public function newAction() { $account = $this->findCurrentAccount(); $newPost = new TYPO3BlogDomainModelPost(); $newPost->setAuthor($account->getParty()->getName()->getFullName()); $this->view->assign(blog, $this->blog); $this->view->assign(existingPosts, $this->postRepository->findByBlog($this- >blog)); $this->view->assign(categories, $this->categoryRepository->findAll()); $this->view->assign(newPost, $newPost); }Datum: 10.01.2012 FLOW3 Einführung / Blog Package www.cross-content.com @MarkusGoldbeck 21
    • ViewDatum: 10.01.2012 FLOW3 Einführung / Blog Package www.cross-content.com @MarkusGoldbeck 22
    • View • Master Template - /Private/Layouts/Master.html <body> <div id="header"> <!-- some stuff --> </div> <div id="maincontainer"> <div id="mainbox"><f:render section="mainbox" /></div> • Post Template - /Private/Template/Post/Edit.html <f:layout name="Master" /> /Private/Layouts/Master.html <f:section name="mainbox"> <!-- some formular--> <f:render partial="FormErrors" arguments="{for: post}" /> </f:section> /Private/Partials/FormErrors.html • Partial Template - /Private/Partials/FormErrors.html <f:form.validationResults for="{for}"> <f:if condition="{validationResults.flattenedErrors}"> <!-- --> </f:if> </f:form.validationResults>Datum: 10.01.2012 FLOW3 Einführung / Blog Package www.cross-content.com @MarkusGoldbeck 23
    • View • security - /Private/Templates/Post/Index.html <f:security.ifHasRole role="Editor"> <div id="navigation"> <span class="buttons"><f:link.action action="new" controller="Post"><img src="{f:uri.resource(path: Icons/FamFamFam/page_add.png)}" title="{f:translate(value: Create a new post)}"/></f:link.action></span> <div class="clear"></div> </div> </f:security.ifHasRole>Datum: 10.01.2012 FLOW3 Einführung / Blog Package www.cross-content.com @MarkusGoldbeck 24
    • Validation • Partial Template - /Private/Partials/FormErrors.html <f:form.validationResults for="{for}"> Objekt Post wurde übergeben <f:if condition="{validationResults.flattenedErrors}"> <dl class="errors"> <f:for each="{validationResults.flattenedErrors}" key="propertyPath" as="errors"> <dt> {propertyPath}: </dt> <dd> <f:for each="{errors}" as="error">{error}</f:for> </dd> </f:for> </dl> </f:if> </f:form.validationResults> <f:render partial="FormErrors" arguments="{for: post}" />Datum: 10.01.2012 FLOW3 Einführung / Blog Package www.cross-content.com @MarkusGoldbeck 25
    • Routing Subroute • Route auf das TYPO3.Blog Package /Configuration/Routes.yaml ## # Blog subroutes - name: Blog uriPattern: <BlogSubroutes> defaults: @package: TYPO3.Blog @format: html subRoutes: BlogSubroutes: package: TYPO3.Blog • Routet auf das TYPO3.Blog Package /Packages/Application/TYPO3.Blog/ Routes.yaml • Erste zutreffende Regel in Routes.yaml wird ausgeführt. • nur Leerzeichen verwenden, keine Tabs.Datum: 10.01.2012 FLOW3 Einführung / Blog Package www.cross-content.com @MarkusGoldbeck 26
    • Routing Package • /Packages/Application/TYPO3.Blog/Routes.yaml - name: Post index uriPattern: (posts) defaults: @package: TYPO3.Blog @controller: Post @action: index @format: html • passt für http://mfug.demo/ und http://mfug.demo/posts, da durch die Klammern posts optional ist.Datum: 10.01.2012 FLOW3 Einführung / Blog Package www.cross-content.com @MarkusGoldbeck 27
    • Routing Package • Action Routing •/Packages/Application/TYPO3.Blog/Routes.yaml - name: Post actions 1 uriPattern: posts/{@action} defaults: @controller: Post • passt http://mfug.demo/posts/newDatum: 10.01.2012 FLOW3 Einführung / Blog Package www.cross-content.com @MarkusGoldbeck 28
    • Routing Package • Object Routes Part •/Packages/Application/TYPO3.Blog/Routes.yaml http://dev.tutorial.local/post/edit?post%5B__identity%5D=229e2b23-b6f3-4422-8b7a- efb196dbc88b - name: Post actions 2 uriPattern: posts/{post}/{@action} defaults: @controller: Post routeParts: post: objectType: TYPO3BlogDomainModelPost uriPattern: {date:Y}/{date:m}/{date:d}/{title} http://dev.tutorial.local/post/2010/01/18/post-title/editDatum: 10.01.2012 FLOW3 Einführung / Blog Package www.cross-content.com @MarkusGoldbeck 29
    • Quellen • FLOW3 Dokumentation http://flow3.typo3.org/documentation/guide.html • FLOW3 Blog Package TYPO3.Blog http://forge.typo3.org/projects/show/package-typo3-blogDatum: 10.01.2012 FLOW3 Einführung / Blog Package www.cross-content.com @MarkusGoldbeck 30
    • Kontakt Cross Content Media Twitter: @MarkusGoldbeck Gesellschaft für Online Business Solutions mbH E-Mail: mgoldbeck@cross-content.com Landshuter Allee 8 www.cross-content.com 80637 MünchenDatum: 10.01.2012 FLOW3 Einführung / Blog Package www.cross-content.com @MarkusGoldbeck 31