SlideShare una empresa de Scribd logo
1 de 116
Descargar para leer sin conexión
T3CON09 Dallas                   Inspiring people to
                                 share
MVC for TYPO3 4.3 with Extbase
MVC workshop for TYPO3 4.3
                 15.04.2009


    Oliver Hader <oliver@typo3.org>
Sebastian Kurfürst <sebastian@typo3.org>
Abstract
 The current state of the art

 Core concepts - MVC and DDD     Hello world

   Extension building with       Blog example
           Extbase

                                  Persistence
   Outlook and conclusion

                                   Inspiring people to
MVC for TYPO3 4.3 with Extbase     share
Abstract
 The current state of the art

 Core concepts - MVC and DDD     Hello world

   Extension building with       Blog example
           Extbase

                                  Persistence
   Outlook and conclusion

                                   Inspiring people to
MVC for TYPO3 4.3 with Extbase     share
The current state
                                                                                             of the art




http://commons.wikimedia.org/wiki/File:Z%C3%BCrich_-_Seefeld_-_Heureka_IMG_1757.JPG
The current state of the art


The current state of the art
                 dispatches calls                 templates
        FE
                   fetches data                 JavaScript/CSS
      Plugin                        Resources
                  renders output                    images
           extends tslib_pibase                   TypoScript


                Database tables                      Frontend
                                                    Extension
                                                Inspiring people to
MVC for TYPO3 4.3 with Extbase                  share
The current state of the art


File structure




                                 Inspiring people to
MVC for TYPO3 4.3 with Extbase   share
The current state of the art


A new extension: Blogging with TYPO3
      Overview

          define features of the new blogging application

          implement the business logic

          define the look and feel

          take a look at security issues

          modify and extend the application



                                                           Inspiring people to
MVC for TYPO3 4.3 with Extbase                             share
The current state of the art


Blog features
                                                                 Blog
      administrate blogs, blog posts and blog comments

      list all available blogs
                                                                 Post
      list all blog posts of a blog

      list all comments of a blog post
                                                             Comment           Tag
      allow users to post new comments




                                                         Inspiring people to
MVC for TYPO3 4.3 with Extbase                           share
The current state of the art


Blog business logic
      dispatch method calls in tx_blog_pi1->main()
       public function main($content, $conf) {
          $this->conf = $conf;
          $this->pi_setPiVarDefaults();
          $this->pi_loadLL();

           if ($this->piVars['postUid']) {
              if ($this->piVars['newComment']) {
                  $this->storeNewComment();
              }
              $content = $this->renderPost();
           } elseif ($this->piVars['blogUid']) {
              $content = $this->renderBlog();
           } else {
              $content = $this->renderListOfBlogs();
           }
           return $this->pi_wrapInBaseClass($content);
       }


                                                         Inspiring people to
MVC for TYPO3 4.3 with Extbase                           share
The current state of the art


Task 1: Output a listing of blogs
      fetch available blogs from database

      implement a new method „renderListOfBlogs()“
       protected function renderListOfBlogs() {
          ...
          $blogs = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
              '*',
              'tx_blog_blog',
              'deleted=0 AND hidden=0 AND sys_language_uid=' .
                  $GLOBALS['TSFE']->sys_language_uid .
                  $this->cObj->enableFields('tx_blog_blog'),
              '',
              'name'
          );
          ...
       }



                                                                 Inspiring people to
MVC for TYPO3 4.3 with Extbase                                   share
The current state of the art


Task 1: Output a listing of blogs
      iterate through all blogs and render them
       protected function renderListOfBlogs() {
          $template = $this->cObj->fileResource($this->conf['template']);
          $blogElementSubpart = $this->cObj->getSubpart($template, '###SUBPART_BLOGELEMENT###');

           $blogs = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(...);
           foreach ($blogs as $blog) {
              $linkParameters = array('blogUid' => $blog['uid']);
              $markers = array(
                  '###BLOG_NAME###' => $blog['name'],
                  '###BLOG_LOGO###' => $this->cImage('uploads/tx_blog/' . $blog['logo']),
                  '###BLOG_DESCRIPTION###' => $this->pi_RTEcssText($blog['description']),
                  '###BLOG_MORELINK###' => $this->pi_linkTP('show blog', $linkParameters, true),
              );
              $blogElements.= $this->cObj->substituteMarkerArray($blogElementSubpart, $markers);
           }
           return $content;
       }



                                                                          Inspiring people to
MVC for TYPO3 4.3 with Extbase                                           share
The current state of the art


Task 1: Output a listing of blogs
      create the template with markers and subparts

       <!-- ###SUBPART_BLOGELEMENT### begin -->
       <div class=quot;blog elementquot;>
          ###BLOG_NAME###
          ###BLOG_LOGO###
          ###BLOG_DESCRIPTION###
          ###BLOG_MORELINK###
       </div>
       <!-- ###SUBPART_BLOGELEMENT### end -->




                                                      Inspiring people to
MVC for TYPO3 4.3 with Extbase                        share
The current state of the art


Task 2: Display a single post with its comments
      implement a new method „renderListOfBlogs()“
       protected function renderPost() {
          $post = $this->pi_getRecord('tx_blog_post', $this->piVars['postUid']);
          $comments = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
              '*',
              'tx_blog_comment',
              'deleted=0 AND hidden=0 AND sys_language_uid=' .
                  $GLOBALS['TSFE']->sys_language_uid .
                  ' AND post_uid=' . $this->piVars['postUid'] . ' AND post_table=quot;tx_blog_postquot;' .
                  $this->cObj->enableFields('tx_blog_comment'),
              '',
              'date DESC'
          );

           // fill marker arrays and substitute in template
           // return content
       }




                                                                          Inspiring people to
MVC for TYPO3 4.3 with Extbase                                            share
The current state of the art


Task 3: Add a new comment to a blog post
      the whole plugin is cached („USER“)

      dynamic user input won‘t be handled by the rendering when cached

      define uncached behavior in TypoScript

        [globalVar = _POST:tx_blog_pi1|newComment = 1]
           plugin.tx_blog_pi1 = USER_INT
        [global]




                                                                   Inspiring people to
MVC for TYPO3 4.3 with Extbase                                     share
The current state of the art


Task 3: Add a new comment to a blog post
      store new comment in database
        protected function storeNewComment() {
           $fields = array(
               'post_uid' => $this->piVars['postUid'],
               'post_table' => 'tx_blog_post',
               'date' => time(),
               'author' => $this->piVars['author'],
               'email' => $this->piVars['email'],
               'content' => $this->piVars['content'],
           );

            $GLOBALS['TYPO3_DB']->exec_INSERTquery(
               'tx_blog_comment', $fields
            );
        }




                                                         Inspiring people to
MVC for TYPO3 4.3 with Extbase                           share
The current state of the art


Take a look at security issues
      possibility of SQL injections

      unvalidated information submitted by a user

          is there really a mail address where it was expected?

          are integers really integers?

      malicious information submitted by a user (XSS)

          is there a possibility to inject JavaScript code?



                                                                  Inspiring people to
MVC for TYPO3 4.3 with Extbase                                    share
The current state of the art


Security: SQL injections
      unescaped or unchecked values that are transferred to the database directly
        $comments = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
        '*',
        'tx_blog_comment',
        'deleted=0 AND hidden=0 AND sys_language_uid=' . $GLOBALS['TSFE']->sys_language_uid .
           ' AND post_uid=' . $this->piVars['postUid'] . ' AND post_table=quot;tx_blog_postquot;' .
        $this->cObj->enableFields('tx_blog_comment')
        );


        with &postUid=1; INSERT INTO be_users SET ...; SELECT * FROM tx_blog_comment WHERE 1=1

        SELECT * FROM tx_blog_comment WHERE post_uid=1;
        INSERT INTO be_users SET ...;
        SELECT * FROM tx_blog_comment WHERE 1=1 AND post_table=“tx_blog_post“ ...




                                                                          Inspiring people to
MVC for TYPO3 4.3 with Extbase                                            share
The current state of the art


Security: SQL injections
      always escape or cast variables from outside
        ' AND post_uid=' . intval($this->piVars['postUid']) . ' AND post_table=quot;tx_blog_postquot;' .




                                                                          Inspiring people to
MVC for TYPO3 4.3 with Extbase                                            share
The current state of the art


Modify and extend the blog application
      store information on different DBMS (e.g. move from MySQL to Oracle)

          are there any SQL statements that won‘t work in Oracle?

          what about the length of the table names?

      integrate spam protection for posting new comments

          add validation to the arguments submitted by a user

      integrate a PDF and RSS version of all blogs

          implement new business logic for each new output format

                                                                     Inspiring people to
MVC for TYPO3 4.3 with Extbase                                       share
Abstract
 The current state of the art

 Core concepts - MVC and DDD     Hello world

   Extension building with       Blog example
           Extbase

                                  Persistence
   Outlook and conclusion

                                   Inspiring people to
MVC for TYPO3 4.3 with Extbase     share
Core concepts
                                               Model        Domain
                                               View         Driven
                                               Controller   Design




http://www.flickr.com/photos/seier/501370105/
Core concepts


Model View Controller




                                 Inspiring people to
MVC for TYPO3 4.3 with Extbase   share
Core concepts - MVC


Layered architecture


              View

              Controller

              Domain Model (Domain Layer)




                                            Inspiring people to
MVC for TYPO3 4.3 with Extbase              share
http://www.flickr.com/photos/bunchofpants/106465356/sizes/o/




The model is a small
   representation of
             reality.
Core concepts - MVC


Application domain
      Example: Car rental application

      Application domain contains: Car, Sales Agent, Customer, Sale, Billing

      defines properties and behavior of these (real world) objects




                                                                        Inspiring people to
MVC for TYPO3 4.3 with Extbase                                          share
Core concepts - MVC


Model
      Object representation of data and behavior

      represents the application domain in software

      FLOW3: Domain Models




                                                      Inspiring people to
MVC for TYPO3 4.3 with Extbase                        share
Core concepts - MVC


Model: Car rental example




                                 Inspiring people to
MVC for TYPO3 4.3 with Extbase   share
The view
                        Topictext


                                                                               renders
                        View
                                                                                 data.
                                  renders data for different output mediums

                                  it‘s only about displaying data

                                  includes all output logic




                                                                              Inspiring people to
                        MVC for TYPO3 4.3 with Extbase                        share
http://www.sxc.hu/photo/1157763
The controller steers
    the data flow and
    triggers actions




http://www.sxc.hu/browse.phtml?f=view&id=956017
Response
Request

          Controller

                                  View




                       Model
Core concepts - MVC


Conclusion MVC
      Model: stores data and behavior

      View: renders data

      Controller: connects model and view, reacts to user input




                                                                  Inspiring people to
MVC for TYPO3 4.3 with Extbase                                    share
Domain
                                 Driven
                                 Design




http://www.sxc.hu/photo/585791
Core concepts - Domain Driven Design


Layered architecture

                              View
       Presentation
                              Controller

                              Application Logic (Service Layer)
          Domain
                              Domain Model (Domain Layer)


                              Data Mapper
        Data source
                              Data Source Abstraction




                                                                  Inspiring people to
MVC for TYPO3 4.3 with Extbase                                    share
Core concepts - Domain Driven Design


Layered architecture

                              View
       Presentation
                              Controller

                              Application Logic (Service Layer)
          Domain
                              Domain Model (Domain Layer)


                              Data Mapper
        Data source
                              Data Source Abstraction




                                                                  Inspiring people to
MVC for TYPO3 4.3 with Extbase                                    share
Principles of Domain Driven Design




                                     Inspiring people to
MVC for TYPO3 4.3 with Extbase       share
Domain describes activity or
    business of user.
Focus
           on the
          Domain
http://www.sxc.hu/photo/59950
Having your domain rules in software




                          http://www.sxc.hu/photo/768598
The Tower of Babel
Core concepts - Domain Driven Design


Ubiquitous language
      common vocabulary is an important prerequisite to work together

      you should use the same vocabulary for discussion, modelling, development and
      documentation




                                                                    Inspiring people to
MVC for TYPO3 4.3 with Extbase                                      share
Core concepts - Domain Driven Design


Principles of Domain Driven Design
      Domain = activity or business of user

      focus on the domain

      build rules of the domain in software

      ubiquitous language




                                              Inspiring people to
MVC for TYPO3 4.3 with Extbase                share
Core concepts - Domain Driven Design


 Example: Phone book




 Not in the         showEntries()
PhoneBook           checkIfUserCanDeleteEntry()
                    exportPhoneBook()
  domain            logChanges()




                                                  Inspiring people to
 MVC for TYPO3 4.3 with Extbase                   share
Why should you use DDD?




                                        Inspiring people to
MVC for TYPO3 4.3 with Extbase          share
Read lots of TypoScript
                                   Mix PHP and HTML template
  and core API docs
                                   to build a template-based
                                             layout
    Build frontend forms
     with error handling

                          Implement application logic
     Care about security
                                              adapt to the coding style,
                        Build complex         structure and thinking of
                         SQL queries             different developers
http://www.sxc.hu/photo/929504
Implement application logic
Flow [flō] is the mental state of operation in
                                 which the person is fully immersed in what he
                                 or she is doing by a feeling of energized focus,
                                 full involvement, and success in the process of
                                 the activity.




http://www.sxc.hu/photo/768249
Abstract
 The current state of the art

 Core concepts - MVC and DDD     Hello world

   Extension building with       Blog example
           Extbase

                                  Persistence
   Outlook and conclusion

                                   Inspiring people to
MVC for TYPO3 4.3 with Extbase     share
http://www.sxc.hu/photo/516864/




                                                 Extension building
                                                      with Extbase
                                  How to build a typo3
                                  v4 based app
Extension building with Extbase


File structure




                                  Inspiring people to
MVC for TYPO3 4.3 with Extbase    share
Extension building with Extbase


Hello World
      Task: Output “Hello World”




                                   Inspiring people to
MVC for TYPO3 4.3 with Extbase     share
Extension building with Extbase


Controller
      all controllers inherit from Tx_Extbase_MVC_Controller_ActionController

      Controllers contain actions: *Action

      Default action: indexAction




                                                                    Inspiring people to
MVC for TYPO3 4.3 with Extbase                                      share
Topictext


Hello World
      Demo



                         DEMO

                                 Inspiring people to
MVC for TYPO3 4.3 with Extbase   share
Break until 11:00
                            -> Start screenflow again




                                                       Inspiring people to
MVC for TYPO3 4.3 with Extbase                         share
Abstract
 The current state of the art

 Core concepts - MVC and DDD     Hello world

   Extension building with       Blog example
           Extbase

                                  Persistence
   Outlook and conclusion

                                   Inspiring people to
MVC for TYPO3 4.3 with Extbase     share
Blog example




                                      Inspiring people to
MVC for TYPO3 4.3 with Extbase        share
Extension building with Extbase


Task 1: Output a listing of blog postings
      You want to output the postings of a predefined blog.



       // inside the BlogController:
       public function showAction() {
         $blogUid = 1;
         // Fetch blog with UID 1
         // pass blog to view so it can be rendered
       }




                                                             Inspiring people to
MVC for TYPO3 4.3 with Extbase                               share
How would you fetch a blog?
Extension building with Extbase - Blog Example


Model




                                                 Inspiring people to
MVC for TYPO3 4.3 with Extbase                   share
Extension building with Extbase - Blog Example


Aggregates
                    BlogRepository                Aggregate Root
                                           Blog


                                           Post


                                       Comment          Tag


                                          Aggregate


                                                                   Inspiring people to
MVC for TYPO3 4.3 with Extbase                                     share
Extension building with Extbase - Blog Example


Aggregates
      Idea: Put your objects into a tree / hierarchical structure

      Root of the tree: aggregate root

      Aggregate roots are accessible through Repositories




                                                                    Inspiring people to
MVC for TYPO3 4.3 with Extbase                                      share
Model classes are POPOs (almost)
   POPO = Plain Old PHP Object
Extension building with Extbase - Blog Example


Model examples
Extension building with Extbase - Blog Example


Model examples
Extension building with Extbase - Blog Example


Model examples
Extension building with Extbase - Blog Example


Repositories
      Encapsulate all data access

      SQL is allowed only in the Repository

      Magic methods: findBy*, findOneBy*
Extension building with Extbase - Blog Example


Repositories                                     Blog übergeben
Extension building with Extbase - Blog Example


Task 1: Output a listing of blog postings
      You want to output the postings of a predefined blog.


       // inside the BlogController:
       public function showAction() {
         $blogUid = 1;
         $blog = $this->blogRepository->findOneByUid($blogUid);
         // pass blog to view so it can be rendered

       }




                                                             Inspiring people to
MVC for TYPO3 4.3 with Extbase                               share
Extension building with Extbase - Blog Example


Task 1: Output a listing of blog postings
      You want to output the postings of a predefined blog.


       // inside the BlogController:
       public function showAction() {
         $blogUid = 1;
         $blog = $this->blogRepository->findOneByUid($blogUid);
         $this->view->assign('blog', $blog);
         return $this->view->render(); // can be omitted
       }




                                                             Inspiring people to
MVC for TYPO3 4.3 with Extbase                               share
Extension building with Extbase - Blog Example


     Task 1: Output a listing of blog postings
            Inside the template:


<h1>Welcome to {blog.name}</h1>

<f:for each=quot;{blog.posts}quot; as=quot;postquot;>
     <h1>{post.title}</h1>
     <f:actionlink controller=quot;Postquot; action=quot;showquot;
                   arguments=quot;{postUid : post.uid}quot;>read more </f:actionlink>
</f:for>




                                                             Inspiring people to
     MVC for TYPO3 4.3 with Extbase                          share
Extension building with Extbase - Blog Example


Task 2: Display a single blog post
      Display a post with comments



       // inside the PostController:
       public function showAction() {
         // Get the Post UID
         // Fetch post with UID X
         // Pass post to view so it can be rendered
       }




                                                      Inspiring people to
MVC for TYPO3 4.3 with Extbase                        share
Extension building with Extbase - Blog Example


Arguments

       /**
         * Action that displays one single post
         *
         * @param int $postUid The uid of a post
         * @return string The rendered view
         */
       public function showAction($postUid) {
       }




                                                   Inspiring people to
MVC for TYPO3 4.3 with Extbase                     share
Extension building with Extbase - Blog Example


Arguments
      All arguments must be registered.

      Registration of expected arguments happens through defining them as method
      parameters.

      PHPDoc is mandatory as it is used for data type validation




                                                                   Inspiring people to
MVC for TYPO3 4.3 with Extbase                                     share
Extension building with Extbase - Blog Example


Arguments - more advanced

/**
  * Action that displays one single post
  *
  * @param int $postUid The uid of a post
  * @return string The rendered view
  */
public function showAction($postUid = 1) {
}

                                                 Default values


                                                          Inspiring people to
MVC for TYPO3 4.3 with Extbase                           share
Extension building with Extbase - Blog Example


Arguments - more advanced
/**
  * Action that displays one single post
                                                    Do
  *
  * @param string $title Title of the post additional validation
  * @param string $content Content of the post
  * @validate $title Length(maximum=100)
  * @return string The rendered view
  */
public function createAction($title, $content)
{
}




                                                       Inspiring people to
MVC for TYPO3 4.3 with Extbase                         share
Extension building with Extbase - Blog Example


Task 2: Display a single blog post
      Display a post with comments


       // inside the PostController:
       /**
         * @param int $postUid The post UID to be displayed
         */
       public function showAction($postUid = 0) {
          // Fetch post with UID X
          // Pass post to view so it can be rendered
       }




                                                         Inspiring people to
MVC for TYPO3 4.3 with Extbase                           share
Extension building with Extbase - Blog Example


Aggregates - continued
                     BlogRepository
                                            Blog Aggregate Root

                      PostRepository
                                            Post


                                        Comment        Tag


                                           Aggregate


                                                                  Inspiring people to
MVC for TYPO3 4.3 with Extbase                                    share
Extension building with Extbase - Blog Example


Task 2: Display a single blog post
      Display a post with comments


       // inside the PostController:
       /**
         * @param int $postUid The post UID to be displayed
         */
       public function showAction($postUid = 0) {
          $post = $this->postRepository->findOneByUid($postUid);
          // Pass post to view so it can be rendered
       }




                                                         Inspiring people to
MVC for TYPO3 4.3 with Extbase                           share
Extension building with Extbase - Blog Example


Task 2: Display a single blog post
      Display a post with comments


       // inside the PostController:
       /**
         * @param int $postUid The post UID to be displayed
         */
       public function showAction($postUid = 0) {
          $post = $this->postRepository->findOneByUid($postUid);
          $this->view->assign('post', $post);
       }




                                                         Inspiring people to
MVC for TYPO3 4.3 with Extbase                           share
Topictext


Task 2: Display a single blog post - template




                                    Inspiring people to
MVC for TYPO3 4.3 with Extbase      share
Extension building with Extbase - Blog Example


Task 3: Add a new comment
      a new comment needs to be stored for a given post

      1. Create the template

      2. Add the comment in the controller




                                                          Inspiring people to
MVC for TYPO3 4.3 with Extbase                            share
Extension building with Extbase - Blog Example


Task 3: Add a new comment
      1. The template




                                                 Inspiring people to
MVC for TYPO3 4.3 with Extbase                   share
Abstract
 The current state of the art

 Core concepts - MVC and DDD     Hello world

   Extension building with       Blog example
           Extbase

                                  Persistence
   Outlook and conclusion

                                   Inspiring people to
MVC for TYPO3 4.3 with Extbase     share
Persistence




                                       Inspiring people to
MVC for TYPO3 4.3 with Extbase         share
Persistence


Aggregates revisited
               BlogRepository
                                  Blog Aggregate Root

               PostRepository
                                  Post


                                Comment      Tag


                                 Aggregate


                                                        Inspiring people to
MVC for TYPO3 4.3 with Extbase                          share
Persistence


 adding a blog
        the blog is an aggregate root
                                                                                      Persistent objects
                                                             BlogRepository
                    $blogRepository->add(Blog $blog);

Blog




        Now, the Blog is a managed object - changes are now automatically persisted!


                                                                          Inspiring people to
 MVC for TYPO3 4.3 with Extbase                                           share
Persistence


adding a blog
      the blog is an aggregate root
                                                                                    Persistent objects
                                                           BlogRepository
                  $blogRepository->add(Blog $blog);



                                                          Blog




      Now, the Blog is a managed object - changes are now automatically persisted!


                                                                        Inspiring people to
MVC for TYPO3 4.3 with Extbase                                          share
Persistence


  adding a comment
         Comment is no aggregate root
                                                                             Persistent objects
         Thus, Comment is automatically persisted   PostRepository




                                                         Post



Comment


                                                                 Inspiring people to
  MVC for TYPO3 4.3 with Extbase                                 share
Persistence


Transparent object persistence
      All objects (and their child-objects) managed by a repository are automatically
      persisted

      changes to these objects are automatically persisted




                                                                       Inspiring people to
MVC for TYPO3 4.3 with Extbase                                         share
Inspiring people to
MVC for TYPO3 4.3 with Extbase   share
Persistence


Summary: Domain objects




                                 Inspiring people to
MVC for TYPO3 4.3 with Extbase   share
Persistence


Summary: Domain objects
      we start with the business logic (PHP classes)

      Objects represent things in the real world, with their attributes and behavior

      we don't care about the database backend / persistence layer




                                                                        Inspiring people to
MVC for TYPO3 4.3 with Extbase                                          share
Persistence


Excursus: ActiveRecord
      Introduced with Ruby on Rails

      Starts with the data structures in the database

      attributes are not explicitly in the objects - taken from the database

     class User < ActiveRecord::Base

     end

              Very intransparent!
                                                                        Inspiring people to
MVC for TYPO3 4.3 with Extbase                                          share
Abstract
 The current state of the art

 Core concepts - MVC and DDD     Hello world

   Extension building with       Blog example
           Extbase

                                  Persistence
   Outlook and conclusion

                                   Inspiring people to
MVC for TYPO3 4.3 with Extbase     share
Outlook




                                     Inspiring people to
MVC for TYPO3 4.3 with Extbase       share
Outlook


Availability and documentation
     Extbase will be included in TYPO3 4.3

     full-blown replacement for pibase

     new preferred way to write extensions

     futureproof, with concepts of FLOW3

     Currently no documentation, but will be available with the final release




                                                                      Inspiring people to
MVC for TYPO3 4.3 with Extbase                                        share
Outlook


New kickstarter
     currently ongoing project by the core development team

     will be released shortly after 4.3

     Domain Driven Design - Don't think in databases, think in Objects!




                                                                      Inspiring people to
MVC for TYPO3 4.3 with Extbase                                        share
Resources and links
    Project web site: http://forge.typo3.org/projects/show/typo3v4-mvc

    SVN: https://svn.typo3.org/TYPO3v4/CoreProjects/MVC/

    we will provide documentation until the release of TYPO3 4.3

    First release with TYPO3 4.3 alpha3: http://typo3.org/download/packages/




                                                                   Inspiring people to
MVC for TYPO3 4.3 with Extbase                                     share
Conclusion




                                      Inspiring people to
MVC for TYPO3 4.3 with Extbase        share
+
    Greatly reusable
      components
+
      Easy and
    consistent API
+   Easily testable
-


Needs initial
learning time
-    Extensions
    need proper
       planning
-

      You will
    get addicted
Feel the flow
 in TYPO3 v4
??????
      ?
     ?
    ?
  ??
 ?
 ?
inspiring people to share.

Más contenido relacionado

La actualidad más candente

Flask patterns
Flask patternsFlask patterns
Flask patterns
it-people
 
TurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsTurboGears2 Pluggable Applications
TurboGears2 Pluggable Applications
Alessandro Molina
 
Web2py tutorial to create db driven application.
Web2py tutorial to create db driven application.Web2py tutorial to create db driven application.
Web2py tutorial to create db driven application.
fRui Apps
 

La actualidad más candente (18)

Flask restfulservices
Flask restfulservicesFlask restfulservices
Flask restfulservices
 
Flask patterns
Flask patternsFlask patterns
Flask patterns
 
OSCON Google App Engine Codelab - July 2010
OSCON Google App Engine Codelab - July 2010OSCON Google App Engine Codelab - July 2010
OSCON Google App Engine Codelab - July 2010
 
Working With The Symfony Admin Generator
Working With The Symfony Admin GeneratorWorking With The Symfony Admin Generator
Working With The Symfony Admin Generator
 
TurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsTurboGears2 Pluggable Applications
TurboGears2 Pluggable Applications
 
Python RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutionsPython RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutions
 
Basic Crud In Django
Basic Crud In DjangoBasic Crud In Django
Basic Crud In Django
 
Building a Backend with Flask
Building a Backend with FlaskBuilding a Backend with Flask
Building a Backend with Flask
 
web2py:Web development like a boss
web2py:Web development like a bossweb2py:Web development like a boss
web2py:Web development like a boss
 
short_intro_to_CMake_(inria_REVES_team)
short_intro_to_CMake_(inria_REVES_team)short_intro_to_CMake_(inria_REVES_team)
short_intro_to_CMake_(inria_REVES_team)
 
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
 
Web2py tutorial to create db driven application.
Web2py tutorial to create db driven application.Web2py tutorial to create db driven application.
Web2py tutorial to create db driven application.
 
WordPress basic fundamental of plugin development and creating shortcode
WordPress basic fundamental of plugin development and creating shortcodeWordPress basic fundamental of plugin development and creating shortcode
WordPress basic fundamental of plugin development and creating shortcode
 
8 things to know about theming in drupal 8
8 things to know about theming in drupal 88 things to know about theming in drupal 8
8 things to know about theming in drupal 8
 
Building a Dynamic Website Using Django
Building a Dynamic Website Using DjangoBuilding a Dynamic Website Using Django
Building a Dynamic Website Using Django
 
Creating Custom Drupal Modules
Creating Custom Drupal ModulesCreating Custom Drupal Modules
Creating Custom Drupal Modules
 
backend
backendbackend
backend
 
Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: Your Next Microframework (SymfonyCon 2015)Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: Your Next Microframework (SymfonyCon 2015)
 

Similar a MVC for TYPO3 4.3 with extbase

Using Backbone.js with Drupal 7 and 8
Using Backbone.js with Drupal 7 and 8Using Backbone.js with Drupal 7 and 8
Using Backbone.js with Drupal 7 and 8
Ovadiah Myrgorod
 
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
ichikaway
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
Ankur Dongre
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
Ankur Dongre
 
Grails, Trails, and Sails: Rails Through a Coffee Filter
Grails, Trails, and Sails: Rails Through a Coffee FilterGrails, Trails, and Sails: Rails Through a Coffee Filter
Grails, Trails, and Sails: Rails Through a Coffee Filter
elliando dias
 
Laying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme developmentLaying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme development
Tammy Hart
 

Similar a MVC for TYPO3 4.3 with extbase (20)

Exploring Symfony's Code
Exploring Symfony's CodeExploring Symfony's Code
Exploring Symfony's Code
 
Creating Clean Code with AOP (WebExpo 2010)
Creating Clean Code with AOP (WebExpo 2010)Creating Clean Code with AOP (WebExpo 2010)
Creating Clean Code with AOP (WebExpo 2010)
 
Modul-Entwicklung für Magento, OXID eShop und Shopware (2013)
Modul-Entwicklung für Magento, OXID eShop und Shopware (2013)Modul-Entwicklung für Magento, OXID eShop und Shopware (2013)
Modul-Entwicklung für Magento, OXID eShop und Shopware (2013)
 
Using Backbone.js with Drupal 7 and 8
Using Backbone.js with Drupal 7 and 8Using Backbone.js with Drupal 7 and 8
Using Backbone.js with Drupal 7 and 8
 
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
 
Backbone js-slides
Backbone js-slidesBackbone js-slides
Backbone js-slides
 
Building Potent WordPress Websites
Building Potent WordPress WebsitesBuilding Potent WordPress Websites
Building Potent WordPress Websites
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
 
Laravel 8 export data as excel file with example
Laravel 8 export data as excel file with exampleLaravel 8 export data as excel file with example
Laravel 8 export data as excel file with example
 
Grails, Trails, and Sails: Rails Through a Coffee Filter
Grails, Trails, and Sails: Rails Through a Coffee FilterGrails, Trails, and Sails: Rails Through a Coffee Filter
Grails, Trails, and Sails: Rails Through a Coffee Filter
 
PHP MVC
PHP MVCPHP MVC
PHP MVC
 
SetFocus Portfolio
SetFocus PortfolioSetFocus Portfolio
SetFocus Portfolio
 
Back to Basics 2017: Mí primera aplicación MongoDB
Back to Basics 2017: Mí primera aplicación MongoDBBack to Basics 2017: Mí primera aplicación MongoDB
Back to Basics 2017: Mí primera aplicación MongoDB
 
CodeIgniter & MVC
CodeIgniter & MVCCodeIgniter & MVC
CodeIgniter & MVC
 
May the core be with you - JandBeyond 2014
May the core be with you - JandBeyond 2014May the core be with you - JandBeyond 2014
May the core be with you - JandBeyond 2014
 
Django workshop : let's make a blog
Django workshop : let's make a blogDjango workshop : let's make a blog
Django workshop : let's make a blog
 
Front End Development for Back End Developers - Devoxx UK 2017
 Front End Development for Back End Developers - Devoxx UK 2017 Front End Development for Back End Developers - Devoxx UK 2017
Front End Development for Back End Developers - Devoxx UK 2017
 
Laying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme developmentLaying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme development
 
Cake PHP 3 Presentaion
Cake PHP 3 PresentaionCake PHP 3 Presentaion
Cake PHP 3 Presentaion
 

Más de Sebastian Kurfürst

Más de Sebastian Kurfürst (10)

The Current State of TYPO3 Phoenix -- T3CON11
The Current State of TYPO3 Phoenix -- T3CON11The Current State of TYPO3 Phoenix -- T3CON11
The Current State of TYPO3 Phoenix -- T3CON11
 
FLOW3 Goes Semantic
FLOW3 Goes SemanticFLOW3 Goes Semantic
FLOW3 Goes Semantic
 
Advanced Fluid
Advanced FluidAdvanced Fluid
Advanced Fluid
 
Fluid for Designers
Fluid for DesignersFluid for Designers
Fluid for Designers
 
Workshop Extension-Entwicklung mit Extbase und Fluid
Workshop Extension-Entwicklung mit Extbase und FluidWorkshop Extension-Entwicklung mit Extbase und Fluid
Workshop Extension-Entwicklung mit Extbase und Fluid
 
Schulung Fluid Templating
Schulung Fluid TemplatingSchulung Fluid Templating
Schulung Fluid Templating
 
Fluid - Templating for professionals - T3CON09
Fluid - Templating for professionals - T3CON09Fluid - Templating for professionals - T3CON09
Fluid - Templating for professionals - T3CON09
 
Fluid - The Zen of Templating
Fluid - The Zen of TemplatingFluid - The Zen of Templating
Fluid - The Zen of Templating
 
FLOW3 - der aktuelle Stand. TYPO3 Usergroup Dresden
FLOW3 - der aktuelle Stand. TYPO3 Usergroup DresdenFLOW3 - der aktuelle Stand. TYPO3 Usergroup Dresden
FLOW3 - der aktuelle Stand. TYPO3 Usergroup Dresden
 
Continuous Integration at T3CON08
Continuous Integration at T3CON08Continuous Integration at T3CON08
Continuous Integration at T3CON08
 

Último

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 

MVC for TYPO3 4.3 with extbase

  • 1. T3CON09 Dallas Inspiring people to share MVC for TYPO3 4.3 with Extbase
  • 2. MVC workshop for TYPO3 4.3 15.04.2009 Oliver Hader <oliver@typo3.org> Sebastian Kurfürst <sebastian@typo3.org>
  • 3. Abstract The current state of the art Core concepts - MVC and DDD Hello world Extension building with Blog example Extbase Persistence Outlook and conclusion Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 4. Abstract The current state of the art Core concepts - MVC and DDD Hello world Extension building with Blog example Extbase Persistence Outlook and conclusion Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 5. The current state of the art http://commons.wikimedia.org/wiki/File:Z%C3%BCrich_-_Seefeld_-_Heureka_IMG_1757.JPG
  • 6. The current state of the art The current state of the art dispatches calls templates FE fetches data JavaScript/CSS Plugin Resources renders output images extends tslib_pibase TypoScript Database tables Frontend Extension Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 7. The current state of the art File structure Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 8. The current state of the art A new extension: Blogging with TYPO3 Overview define features of the new blogging application implement the business logic define the look and feel take a look at security issues modify and extend the application Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 9. The current state of the art Blog features Blog administrate blogs, blog posts and blog comments list all available blogs Post list all blog posts of a blog list all comments of a blog post Comment Tag allow users to post new comments Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 10. The current state of the art Blog business logic dispatch method calls in tx_blog_pi1->main() public function main($content, $conf) { $this->conf = $conf; $this->pi_setPiVarDefaults(); $this->pi_loadLL(); if ($this->piVars['postUid']) { if ($this->piVars['newComment']) { $this->storeNewComment(); } $content = $this->renderPost(); } elseif ($this->piVars['blogUid']) { $content = $this->renderBlog(); } else { $content = $this->renderListOfBlogs(); } return $this->pi_wrapInBaseClass($content); } Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 11. The current state of the art Task 1: Output a listing of blogs fetch available blogs from database implement a new method „renderListOfBlogs()“ protected function renderListOfBlogs() { ... $blogs = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( '*', 'tx_blog_blog', 'deleted=0 AND hidden=0 AND sys_language_uid=' . $GLOBALS['TSFE']->sys_language_uid . $this->cObj->enableFields('tx_blog_blog'), '', 'name' ); ... } Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 12. The current state of the art Task 1: Output a listing of blogs iterate through all blogs and render them protected function renderListOfBlogs() { $template = $this->cObj->fileResource($this->conf['template']); $blogElementSubpart = $this->cObj->getSubpart($template, '###SUBPART_BLOGELEMENT###'); $blogs = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(...); foreach ($blogs as $blog) { $linkParameters = array('blogUid' => $blog['uid']); $markers = array( '###BLOG_NAME###' => $blog['name'], '###BLOG_LOGO###' => $this->cImage('uploads/tx_blog/' . $blog['logo']), '###BLOG_DESCRIPTION###' => $this->pi_RTEcssText($blog['description']), '###BLOG_MORELINK###' => $this->pi_linkTP('show blog', $linkParameters, true), ); $blogElements.= $this->cObj->substituteMarkerArray($blogElementSubpart, $markers); } return $content; } Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 13. The current state of the art Task 1: Output a listing of blogs create the template with markers and subparts <!-- ###SUBPART_BLOGELEMENT### begin --> <div class=quot;blog elementquot;> ###BLOG_NAME### ###BLOG_LOGO### ###BLOG_DESCRIPTION### ###BLOG_MORELINK### </div> <!-- ###SUBPART_BLOGELEMENT### end --> Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 14. The current state of the art Task 2: Display a single post with its comments implement a new method „renderListOfBlogs()“ protected function renderPost() { $post = $this->pi_getRecord('tx_blog_post', $this->piVars['postUid']); $comments = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( '*', 'tx_blog_comment', 'deleted=0 AND hidden=0 AND sys_language_uid=' . $GLOBALS['TSFE']->sys_language_uid . ' AND post_uid=' . $this->piVars['postUid'] . ' AND post_table=quot;tx_blog_postquot;' . $this->cObj->enableFields('tx_blog_comment'), '', 'date DESC' ); // fill marker arrays and substitute in template // return content } Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 15. The current state of the art Task 3: Add a new comment to a blog post the whole plugin is cached („USER“) dynamic user input won‘t be handled by the rendering when cached define uncached behavior in TypoScript [globalVar = _POST:tx_blog_pi1|newComment = 1] plugin.tx_blog_pi1 = USER_INT [global] Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 16. The current state of the art Task 3: Add a new comment to a blog post store new comment in database protected function storeNewComment() { $fields = array( 'post_uid' => $this->piVars['postUid'], 'post_table' => 'tx_blog_post', 'date' => time(), 'author' => $this->piVars['author'], 'email' => $this->piVars['email'], 'content' => $this->piVars['content'], ); $GLOBALS['TYPO3_DB']->exec_INSERTquery( 'tx_blog_comment', $fields ); } Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 17. The current state of the art Take a look at security issues possibility of SQL injections unvalidated information submitted by a user is there really a mail address where it was expected? are integers really integers? malicious information submitted by a user (XSS) is there a possibility to inject JavaScript code? Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 18. The current state of the art Security: SQL injections unescaped or unchecked values that are transferred to the database directly $comments = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( '*', 'tx_blog_comment', 'deleted=0 AND hidden=0 AND sys_language_uid=' . $GLOBALS['TSFE']->sys_language_uid . ' AND post_uid=' . $this->piVars['postUid'] . ' AND post_table=quot;tx_blog_postquot;' . $this->cObj->enableFields('tx_blog_comment') ); with &postUid=1; INSERT INTO be_users SET ...; SELECT * FROM tx_blog_comment WHERE 1=1 SELECT * FROM tx_blog_comment WHERE post_uid=1; INSERT INTO be_users SET ...; SELECT * FROM tx_blog_comment WHERE 1=1 AND post_table=“tx_blog_post“ ... Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 19. The current state of the art Security: SQL injections always escape or cast variables from outside ' AND post_uid=' . intval($this->piVars['postUid']) . ' AND post_table=quot;tx_blog_postquot;' . Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 20. The current state of the art Modify and extend the blog application store information on different DBMS (e.g. move from MySQL to Oracle) are there any SQL statements that won‘t work in Oracle? what about the length of the table names? integrate spam protection for posting new comments add validation to the arguments submitted by a user integrate a PDF and RSS version of all blogs implement new business logic for each new output format Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 21.
  • 22. Abstract The current state of the art Core concepts - MVC and DDD Hello world Extension building with Blog example Extbase Persistence Outlook and conclusion Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 23. Core concepts Model Domain View Driven Controller Design http://www.flickr.com/photos/seier/501370105/
  • 24. Core concepts Model View Controller Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 25. Core concepts - MVC Layered architecture View Controller Domain Model (Domain Layer) Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 27. Core concepts - MVC Application domain Example: Car rental application Application domain contains: Car, Sales Agent, Customer, Sale, Billing defines properties and behavior of these (real world) objects Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 28. Core concepts - MVC Model Object representation of data and behavior represents the application domain in software FLOW3: Domain Models Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 29. Core concepts - MVC Model: Car rental example Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 30. The view Topictext renders View data. renders data for different output mediums it‘s only about displaying data includes all output logic Inspiring people to MVC for TYPO3 4.3 with Extbase share http://www.sxc.hu/photo/1157763
  • 31. The controller steers the data flow and triggers actions http://www.sxc.hu/browse.phtml?f=view&id=956017
  • 32. Response Request Controller View Model
  • 33. Core concepts - MVC Conclusion MVC Model: stores data and behavior View: renders data Controller: connects model and view, reacts to user input Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 34.
  • 35. Domain Driven Design http://www.sxc.hu/photo/585791
  • 36. Core concepts - Domain Driven Design Layered architecture View Presentation Controller Application Logic (Service Layer) Domain Domain Model (Domain Layer) Data Mapper Data source Data Source Abstraction Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 37. Core concepts - Domain Driven Design Layered architecture View Presentation Controller Application Logic (Service Layer) Domain Domain Model (Domain Layer) Data Mapper Data source Data Source Abstraction Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 38. Principles of Domain Driven Design Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 39. Domain describes activity or business of user.
  • 40. Focus on the Domain http://www.sxc.hu/photo/59950
  • 41. Having your domain rules in software http://www.sxc.hu/photo/768598
  • 42. The Tower of Babel
  • 43. Core concepts - Domain Driven Design Ubiquitous language common vocabulary is an important prerequisite to work together you should use the same vocabulary for discussion, modelling, development and documentation Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 44. Core concepts - Domain Driven Design Principles of Domain Driven Design Domain = activity or business of user focus on the domain build rules of the domain in software ubiquitous language Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 45. Core concepts - Domain Driven Design Example: Phone book Not in the showEntries() PhoneBook checkIfUserCanDeleteEntry() exportPhoneBook() domain logChanges() Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 46. Why should you use DDD? Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 47. Read lots of TypoScript Mix PHP and HTML template and core API docs to build a template-based layout Build frontend forms with error handling Implement application logic Care about security adapt to the coding style, Build complex structure and thinking of SQL queries different developers
  • 50. Flow [flō] is the mental state of operation in which the person is fully immersed in what he or she is doing by a feeling of energized focus, full involvement, and success in the process of the activity. http://www.sxc.hu/photo/768249
  • 51.
  • 52.
  • 53. Abstract The current state of the art Core concepts - MVC and DDD Hello world Extension building with Blog example Extbase Persistence Outlook and conclusion Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 54. http://www.sxc.hu/photo/516864/ Extension building with Extbase How to build a typo3 v4 based app
  • 55. Extension building with Extbase File structure Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 56. Extension building with Extbase Hello World Task: Output “Hello World” Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 57. Extension building with Extbase Controller all controllers inherit from Tx_Extbase_MVC_Controller_ActionController Controllers contain actions: *Action Default action: indexAction Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 58. Topictext Hello World Demo DEMO Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 59. Break until 11:00 -> Start screenflow again Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 60. Abstract The current state of the art Core concepts - MVC and DDD Hello world Extension building with Blog example Extbase Persistence Outlook and conclusion Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 61. Blog example Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 62. Extension building with Extbase Task 1: Output a listing of blog postings You want to output the postings of a predefined blog. // inside the BlogController: public function showAction() { $blogUid = 1; // Fetch blog with UID 1 // pass blog to view so it can be rendered } Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 63. How would you fetch a blog?
  • 64. Extension building with Extbase - Blog Example Model Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 65. Extension building with Extbase - Blog Example Aggregates BlogRepository Aggregate Root Blog Post Comment Tag Aggregate Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 66. Extension building with Extbase - Blog Example Aggregates Idea: Put your objects into a tree / hierarchical structure Root of the tree: aggregate root Aggregate roots are accessible through Repositories Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 67. Model classes are POPOs (almost) POPO = Plain Old PHP Object
  • 68. Extension building with Extbase - Blog Example Model examples
  • 69. Extension building with Extbase - Blog Example Model examples
  • 70. Extension building with Extbase - Blog Example Model examples
  • 71. Extension building with Extbase - Blog Example Repositories Encapsulate all data access SQL is allowed only in the Repository Magic methods: findBy*, findOneBy*
  • 72. Extension building with Extbase - Blog Example Repositories Blog übergeben
  • 73. Extension building with Extbase - Blog Example Task 1: Output a listing of blog postings You want to output the postings of a predefined blog. // inside the BlogController: public function showAction() { $blogUid = 1; $blog = $this->blogRepository->findOneByUid($blogUid); // pass blog to view so it can be rendered } Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 74. Extension building with Extbase - Blog Example Task 1: Output a listing of blog postings You want to output the postings of a predefined blog. // inside the BlogController: public function showAction() { $blogUid = 1; $blog = $this->blogRepository->findOneByUid($blogUid); $this->view->assign('blog', $blog); return $this->view->render(); // can be omitted } Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 75. Extension building with Extbase - Blog Example Task 1: Output a listing of blog postings Inside the template: <h1>Welcome to {blog.name}</h1> <f:for each=quot;{blog.posts}quot; as=quot;postquot;> <h1>{post.title}</h1> <f:actionlink controller=quot;Postquot; action=quot;showquot; arguments=quot;{postUid : post.uid}quot;>read more </f:actionlink> </f:for> Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 76.
  • 77. Extension building with Extbase - Blog Example Task 2: Display a single blog post Display a post with comments // inside the PostController: public function showAction() { // Get the Post UID // Fetch post with UID X // Pass post to view so it can be rendered } Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 78. Extension building with Extbase - Blog Example Arguments /** * Action that displays one single post * * @param int $postUid The uid of a post * @return string The rendered view */ public function showAction($postUid) { } Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 79. Extension building with Extbase - Blog Example Arguments All arguments must be registered. Registration of expected arguments happens through defining them as method parameters. PHPDoc is mandatory as it is used for data type validation Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 80. Extension building with Extbase - Blog Example Arguments - more advanced /** * Action that displays one single post * * @param int $postUid The uid of a post * @return string The rendered view */ public function showAction($postUid = 1) { } Default values Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 81. Extension building with Extbase - Blog Example Arguments - more advanced /** * Action that displays one single post Do * * @param string $title Title of the post additional validation * @param string $content Content of the post * @validate $title Length(maximum=100) * @return string The rendered view */ public function createAction($title, $content) { } Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 82. Extension building with Extbase - Blog Example Task 2: Display a single blog post Display a post with comments // inside the PostController: /** * @param int $postUid The post UID to be displayed */ public function showAction($postUid = 0) { // Fetch post with UID X // Pass post to view so it can be rendered } Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 83. Extension building with Extbase - Blog Example Aggregates - continued BlogRepository Blog Aggregate Root PostRepository Post Comment Tag Aggregate Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 84. Extension building with Extbase - Blog Example Task 2: Display a single blog post Display a post with comments // inside the PostController: /** * @param int $postUid The post UID to be displayed */ public function showAction($postUid = 0) { $post = $this->postRepository->findOneByUid($postUid); // Pass post to view so it can be rendered } Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 85. Extension building with Extbase - Blog Example Task 2: Display a single blog post Display a post with comments // inside the PostController: /** * @param int $postUid The post UID to be displayed */ public function showAction($postUid = 0) { $post = $this->postRepository->findOneByUid($postUid); $this->view->assign('post', $post); } Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 86. Topictext Task 2: Display a single blog post - template Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 87. Extension building with Extbase - Blog Example Task 3: Add a new comment a new comment needs to be stored for a given post 1. Create the template 2. Add the comment in the controller Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 88. Extension building with Extbase - Blog Example Task 3: Add a new comment 1. The template Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 89.
  • 90. Abstract The current state of the art Core concepts - MVC and DDD Hello world Extension building with Blog example Extbase Persistence Outlook and conclusion Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 91. Persistence Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 92. Persistence Aggregates revisited BlogRepository Blog Aggregate Root PostRepository Post Comment Tag Aggregate Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 93. Persistence adding a blog the blog is an aggregate root Persistent objects BlogRepository $blogRepository->add(Blog $blog); Blog Now, the Blog is a managed object - changes are now automatically persisted! Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 94. Persistence adding a blog the blog is an aggregate root Persistent objects BlogRepository $blogRepository->add(Blog $blog); Blog Now, the Blog is a managed object - changes are now automatically persisted! Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 95. Persistence adding a comment Comment is no aggregate root Persistent objects Thus, Comment is automatically persisted PostRepository Post Comment Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 96. Persistence Transparent object persistence All objects (and their child-objects) managed by a repository are automatically persisted changes to these objects are automatically persisted Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 97. Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 98. Persistence Summary: Domain objects Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 99. Persistence Summary: Domain objects we start with the business logic (PHP classes) Objects represent things in the real world, with their attributes and behavior we don't care about the database backend / persistence layer Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 100. Persistence Excursus: ActiveRecord Introduced with Ruby on Rails Starts with the data structures in the database attributes are not explicitly in the objects - taken from the database class User < ActiveRecord::Base end Very intransparent! Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 101.
  • 102. Abstract The current state of the art Core concepts - MVC and DDD Hello world Extension building with Blog example Extbase Persistence Outlook and conclusion Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 103. Outlook Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 104. Outlook Availability and documentation Extbase will be included in TYPO3 4.3 full-blown replacement for pibase new preferred way to write extensions futureproof, with concepts of FLOW3 Currently no documentation, but will be available with the final release Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 105. Outlook New kickstarter currently ongoing project by the core development team will be released shortly after 4.3 Domain Driven Design - Don't think in databases, think in Objects! Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 106. Resources and links Project web site: http://forge.typo3.org/projects/show/typo3v4-mvc SVN: https://svn.typo3.org/TYPO3v4/CoreProjects/MVC/ we will provide documentation until the release of TYPO3 4.3 First release with TYPO3 4.3 alpha3: http://typo3.org/download/packages/ Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 107. Conclusion Inspiring people to MVC for TYPO3 4.3 with Extbase share
  • 108. + Greatly reusable components
  • 109. + Easy and consistent API
  • 110. + Easily testable
  • 112. - Extensions need proper planning
  • 113. - You will get addicted
  • 114. Feel the flow in TYPO3 v4
  • 115. ?????? ? ? ? ?? ? ?