Überblick über FLOW3 mit dem  Blog-Package als Referenz
Agenda     • Domain Model     • Package Aufbau     • Model        • Validation        • Association Mapping     • Model un...
Domain ModelDatum: 10.01.2012   FLOW3 Einführung / Blog Package www.cross-content.com   @MarkusGoldbeck                   ...
Package AufbauDatum: 10.01.2012   FLOW3 Einführung / Blog Package www.cross-content.com   @MarkusGoldbeck                 ...
Model    • Namespace    namespaceBlogDomainModel;   • Namespace    namespace TYPO3BlogDomainModel;    • Namespace    names...
TYPO3BlogDomainModel Post    • Namespace    namespace TYPO3BlogDomainModel;   • Annotations    use DoctrineORMMapping as O...
TYPO3BlogDomainModel Post    • Properties       • Variablen Deklaration als String       • Validierung auf Datentyp und Lä...
TYPO3BlogDomainModel Post    • Property $date       • Deklaration als Date Objekt       • Identity    /**    * @FLOW3Ident...
Association Mapping    • OneToMany <-> ManyToOne     /** The posts contained in this blog     * @var DoctrineCommonCollect...
Association Mapping    • ManyToMany <-> ManyToMany    /**    * @var DoctrineCommonCollectionsCollection<TYPO3Blog    Domai...
TYPO3BlogDomainModel BlogDatum: 10.01.2012   FLOW3 Einführung / Blog Package www.cross-content.com   @MarkusGoldbeck      ...
TYPO3BlogDomainModel PostDatum: 10.01.2012   FLOW3 Einführung / Blog Package www.cross-content.com   @MarkusGoldbeck      ...
TYPO3BlogDomainModel Blog    • Setter     /**Sets this blogs title     * @param string $title The blogs title     * @retur...
Model und RepositoriesDatum: 10.01.2012   FLOW3 Einführung / Blog Package www.cross-content.com   @MarkusGoldbeck         ...
Blog Repository    • Standard Blog Repository    <?php    namespace TYPO3BlogDomainRepository;    /*      * This script be...
Blog Repository    • Standard Methoden des Repositories       • add       • remove       • findAll       • findBy* (magic me...
Post Repository    • Post Repository spezifische Methode findByBlog    /**      * Finds posts by the specified blog      * @...
Post Repository    • Post Repository spezifische Methode findByTagAndBlog    /**Finds posts by the specified tag and blog   ...
Post Repository    • Post Repository spezifische Methode findRecentByBlog    /**    * Finds most recent posts by the specifi...
Post Controller    • Post Controller indexAction()    /**    * List action for this controller. Displays latest posts    *...
Post Controller    • Post Controller Dependency Injection    /**    * @FLOW3Inject    * @var TYPO3BlogDomainRepositoryCate...
ViewDatum: 10.01.2012   FLOW3 Einführung / Blog Package www.cross-content.com   @MarkusGoldbeck                           ...
View    • Master Template - /Private/Layouts/Master.html    <body>       <div id="header">           <!-- some stuff -->  ...
View    • security - /Private/Templates/Post/Index.html    <f:security.ifHasRole role="Editor">       <div id="navigation"...
Validation    • Partial Template - /Private/Partials/FormErrors.html    <f:form.validationResults for="{for}">      Objekt...
Routing Subroute    • Route auf das TYPO3.Blog Package /Configuration/Routes.yaml    ##    # Blog subroutes    -        nam...
Routing Package    • /Packages/Application/TYPO3.Blog/Routes.yaml    -        name: Post index        uriPattern:    (post...
Routing Package    • Action Routing    •/Packages/Application/TYPO3.Blog/Routes.yaml    -        name: Post actions 1     ...
Routing Package    • Object Routes Part    •/Packages/Application/TYPO3.Blog/Routes.yaml    http://dev.tutorial.local/post...
Quellen    • FLOW3 Dokumentation      http://flow3.typo3.org/documentation/guide.html    • FLOW3 Blog Package TYPO3.Blog   ...
Kontakt    Cross Content Media                                      Twitter: @MarkusGoldbeck    Gesellschaft für Online Bu...
Upcoming SlideShare
Loading in …5
×

Einführung in FLOW3/ Blog Package

7,346 views

Published on

Einführung in FLOW3 mit dem Blockpackage als Referenz.

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

Published in: Education
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
7,346
On SlideShare
0
From Embeds
0
Number of Embeds
1,072
Actions
Shares
0
Downloads
19
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Einführung in FLOW3/ Blog Package

  1. 1. Überblick über FLOW3 mit dem Blog-Package als Referenz
  2. 2. 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
  3. 3. Domain ModelDatum: 10.01.2012 FLOW3 Einführung / Blog Package www.cross-content.com @MarkusGoldbeck 3
  4. 4. Package AufbauDatum: 10.01.2012 FLOW3 Einführung / Blog Package www.cross-content.com @MarkusGoldbeck 4
  5. 5. 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
  6. 6. 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
  7. 7. 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
  8. 8. 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
  9. 9. 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
  10. 10. 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
  11. 11. TYPO3BlogDomainModel BlogDatum: 10.01.2012 FLOW3 Einführung / Blog Package www.cross-content.com @MarkusGoldbeck 11
  12. 12. TYPO3BlogDomainModel PostDatum: 10.01.2012 FLOW3 Einführung / Blog Package www.cross-content.com @MarkusGoldbeck 12
  13. 13. 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
  14. 14. Model und RepositoriesDatum: 10.01.2012 FLOW3 Einführung / Blog Package www.cross-content.com @MarkusGoldbeck 14
  15. 15. 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
  16. 16. 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
  17. 17. 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
  18. 18. 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
  19. 19. 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
  20. 20. 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
  21. 21. 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
  22. 22. ViewDatum: 10.01.2012 FLOW3 Einführung / Blog Package www.cross-content.com @MarkusGoldbeck 22
  23. 23. 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
  24. 24. 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
  25. 25. 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
  26. 26. 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
  27. 27. 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
  28. 28. 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
  29. 29. 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
  30. 30. 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
  31. 31. 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

×