Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Unleashing Creative
Freedom with
Who am I?
Mark Hamstra
Founder & CEA at modmore
Freelance MODX Developer
my doggies
Turbo
Bommel
Agenda
• What is MODX, for whom, available
features, how to build a MODX site
• Tour of the MODX Manager (back-end)
• The ...
MOD-what?
• Open Source
• Written in PHP (of course)
• Primarily used with MySQL, other drivers available
• Already 10 yea...
https://twitpic.com/3pvrmw
All the features of a CMS
rich text editor versioning user groups
multisite templates multilingual extensions
markdown med...
Installs without Assumptions
Elements as Building Blocks
Templates
TemplateVariables
Chunks
Snippets
Plugins
Templates
• Usually HTML
• Contains MODX tags
• One template per page
Template Variables
• Custom field for resources
• Commonly “TV”
• Tied to templates
• Text, image, select, checkbox,
date, ...
Chunks
• Usually HTML
• Reusable piece of code
• [[$name-of-chunk]]
Template
Chunk “head”
Snippets
• PHP!
• Comparable to a function
• Accepts properties
• [[name-of-snippet]] or 

[[!name-of-snippet]]
Snippet “h...
Snippets
But wait, there’s more!
• [[name-of-snippet]]
• [[!name-of-snippet]]
• = uncached!
• [[++name-of-setting]]

[[!++name-of-s...
But wait, there’s even more!
• [[helloWorld?

&property=`value`

]]
• [[$head?

&extraCss=`<link rel=.. href=..>`

]]
Plugins
• PHP!
• Event-based, so no tags
• Can read and often
influence behaviour
No need to reinvent

the wheel
• Packages (aka extras, add-
ons, extensions, third party
components…) provide
common funct...
Example: getResources
• Lists resources matching
conditions
• Uses a Chunk as template
• Use Cases:
• Article listings
• D...
Time for a Manager Tour!
http://localhost/tmp/phpfrl/manager/
MODX Architecture
Secure by Design
• Automatic $_GET, $_POST, $_REQUEST
sanitisation in the request handler
• xPDO ORM prevents SQL Injectio...
xPDO
• Object Relational Bridge / ORM
• Open Source (modxcms/xpdo)
• Extension to PHP’s PDO
• Support for MySQL, sqlsrv (a...
Fetching a Single Object
$c = 5;
$obj = $modx->getObject(‘modChunk’, $c);
$c2 = array(‘name’ => ‘head’);
$obj = $modx->get...
Easy Query Builder
$c = $modx->newQuery(‘modResource’);
$c->where([
‘parent’ => 0,
‘AND:pagetitle:LIKE => ‘%About%’
]);
$m...
Automatic Filtering
$search = $_POST[‘search’];
$c = $modx->newQuery(‘modResource’);
$c->where([
‘introtext:LIKE’ => “%{$s...
Custom Models with xPDO
1. Create an xPDO Package Schema (XML)
2. Use build script to write schema into the actual
model f...
xPDO Package Schema - Head
<?xml version="1.0" encoding="UTF-8"?>
<model package="phpfrl"
baseClass="xPDOSimpleObject"
pla...
xPDO Package Schema - Object
<?xml version="1.0" encoding="UTF-8"?>
<model package=“phpfrl” …
<object class="frlMeetup" ta...
xPDO Package Schema - Fields
<?xml version="1.0" encoding="UTF-8"?>
<model package=“phpfrl” …
<object class="frlMeetup" ta...
xPDO Package Schema - Indices
<?xml version="1.0" encoding="UTF-8"?>
<model package=“phpfrl” …
<object class="frlMeetup" t...
xPDO Package Schema - Relations
<?xml version="1.0" encoding="UTF-8"?>
<model package=“phpfrl” baseClass=“xPDOSimpleObject...
xPDO Generated Model
<?php

class frlMeetup extends xPDOSimpleObject {
}
<?php
class frlMeetup_mysql extends frlMeetup {
}
Interacting with that model
$modx->addPackage(‘phpfrl’, ‘/path/to/model/‘);
$c = $modx->newQuery(‘frlMeetup’);

$c->sortby...
The Future of MODX
• MODX 3 & MODX Next
• Backwards incompatible release (semver)
• Cleaning up legacy code no longer rele...
Interesting links:
• MODX.com => official website
• rtfm.modx.com => official documentation
• github.com/modxcms/revolutio...
Upcoming SlideShare
Loading in …5
×

Unleashing Creative Freedom with MODX - 2015-08-26 at PHP Zwolle

530 views

Published on

Introducing MODX Revolution and the concept of Creative Freedom at the first PHP Zwolle Meetup on August 27th.

Relevant links:

MODX.com => official website
rtfm.modx.com => official documentation
github.com/modxcms/revolution => source code
MODX.today => daily links/articles about MODX
modmore.com => premium extras for MODX
https://joind.in/talk/view/15031 => for feedback on the talk

Published in: Internet
  • Be the first to comment

  • Be the first to like this

Unleashing Creative Freedom with MODX - 2015-08-26 at PHP Zwolle

  1. 1. Unleashing Creative Freedom with
  2. 2. Who am I? Mark Hamstra Founder & CEA at modmore Freelance MODX Developer my doggies Turbo Bommel
  3. 3. Agenda • What is MODX, for whom, available features, how to build a MODX site • Tour of the MODX Manager (back-end) • The Architecture of MODX, xPDO ORM, extending and overriding, the future
  4. 4. MOD-what? • Open Source • Written in PHP (of course) • Primarily used with MySQL, other drivers available • Already 10 years old young • Content Management System Framework Platform
  5. 5. https://twitpic.com/3pvrmw
  6. 6. All the features of a CMS rich text editor versioning user groups multisite templates multilingual extensions markdown media browser hierarchical page tree commercial support automatic menu builder blogging permissions seo friendly urls server-side caching
  7. 7. Installs without Assumptions
  8. 8. Elements as Building Blocks Templates TemplateVariables Chunks Snippets Plugins
  9. 9. Templates • Usually HTML • Contains MODX tags • One template per page
  10. 10. Template Variables • Custom field for resources • Commonly “TV” • Tied to templates • Text, image, select, checkbox, date, radio, richtext, tag and custom types available • [[*name-of-tv]]
  11. 11. Chunks • Usually HTML • Reusable piece of code • [[$name-of-chunk]] Template Chunk “head”
  12. 12. Snippets • PHP! • Comparable to a function • Accepts properties • [[name-of-snippet]] or 
 [[!name-of-snippet]] Snippet “helloWorld” Template
  13. 13. Snippets
  14. 14. But wait, there’s more! • [[name-of-snippet]] • [[!name-of-snippet]] • = uncached! • [[++name-of-setting]]
 [[!++name-of-setting]] • [[$name-of-chunk]]
 [[!$name-of-chunk]] • [[*name-of-field]]
 [[!*name-of-field]]
  15. 15. But wait, there’s even more! • [[helloWorld?
 &property=`value`
 ]] • [[$head?
 &extraCss=`<link rel=.. href=..>`
 ]]
  16. 16. Plugins • PHP! • Event-based, so no tags • Can read and often influence behaviour
  17. 17. No need to reinvent
 the wheel • Packages (aka extras, add- ons, extensions, third party components…) provide common functionality • Install via Package Installer inside the manager
  18. 18. Example: getResources • Lists resources matching conditions • Uses a Chunk as template • Use Cases: • Article listings • Dynamic (sub)menus • RSS feed generation Template Chunk “blogListItem”
  19. 19. Time for a Manager Tour! http://localhost/tmp/phpfrl/manager/
  20. 20. MODX Architecture
  21. 21. Secure by Design • Automatic $_GET, $_POST, $_REQUEST sanitisation in the request handler • xPDO ORM prevents SQL Injections • 28 CVE entries, 8 since 2014 • WordPress: 906, already ~85 in 2015 • Drupal: 915, already ~120 in 2015 2015-07, cve.mitre.org
  22. 22. xPDO • Object Relational Bridge / ORM • Open Source (modxcms/xpdo) • Extension to PHP’s PDO • Support for MySQL, sqlsrv (and more)
  23. 23. Fetching a Single Object $c = 5; $obj = $modx->getObject(‘modChunk’, $c); $c2 = array(‘name’ => ‘head’); $obj = $modx->getObject(‘modChunk’, $c2)
  24. 24. Easy Query Builder $c = $modx->newQuery(‘modResource’); $c->where([ ‘parent’ => 0, ‘AND:pagetitle:LIKE => ‘%About%’ ]); $matches = $modx->getCollection(‘modResource’, $c); foreach ($matches as $modResource) { . . . }
  25. 25. Automatic Filtering $search = $_POST[‘search’]; $c = $modx->newQuery(‘modResource’); $c->where([ ‘introtext:LIKE’ => “%{$search}%”, ]); $modx->setPlaceholder(‘search’, sanitise($search)); function sanitise($value) { return htmlentities($value, ENT_QUOTES, ‘UTF-8’); } 👍 ⚠
  26. 26. Custom Models with xPDO 1. Create an xPDO Package Schema (XML) 2. Use build script to write schema into the actual model files/classes 3. Register it before use ($modx->addPackage) 4. Use any xPDO method (getObject, getCollection) on your custom model
  27. 27. xPDO Package Schema - Head <?xml version="1.0" encoding="UTF-8"?> <model package="phpfrl" baseClass="xPDOSimpleObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
  28. 28. xPDO Package Schema - Object <?xml version="1.0" encoding="UTF-8"?> <model package=“phpfrl” … <object class="frlMeetup" table=“meetups”> .. fields .. </object> <object class="frlSpeaker" table=“speakers”> … </object> </model>
  29. 29. xPDO Package Schema - Fields <?xml version="1.0" encoding="UTF-8"?> <model package=“phpfrl” … <object class="frlMeetup" table=“meetups"> <field 
 key="name" 
 dbtype="varchar" 
 precision="100" 
 phptype="string" 
 null="false" 
 default=“PHP FRL Meetup" />
  30. 30. xPDO Package Schema - Indices <?xml version="1.0" encoding="UTF-8"?> <model package=“phpfrl” … <object class="frlMeetup" table=“meetups">
 <field key="name" dbtype=“varchar" …
 <field key=“starts_on" dbtype=“datetime"
 <field key="name" dbtype=“varchar" … <index alias="name" name="name" primary="false" unique="false" type="BTREE">
 <column key="name" length="" collation="A" null="false" />
 </index>
 </object>
  31. 31. xPDO Package Schema - Relations <?xml version="1.0" encoding="UTF-8"?> <model package=“phpfrl” baseClass=“xPDOSimpleObject" … <object class="frlMeetup" table=“meetups">
 <field key="name" dbtype=“varchar” …> <composite alias=“Speakers” class=“frlSpeaker” local=“id” foreign=“meetup” cardinality=“many” owner=“local” />
 </object> <object class="frlSpeaker" table=“speakers">
 <field key="name" dbtype=“varchar” …>
 <field key="meetup" dbtype=“int” …> <aggregate alias=“Meetup” class=“frlMeetup” local=“meetup” foreign=“id” cardinality=“one” owner=“foreign” />
 </object>
  32. 32. xPDO Generated Model <?php
 class frlMeetup extends xPDOSimpleObject { } <?php class frlMeetup_mysql extends frlMeetup { }
  33. 33. Interacting with that model $modx->addPackage(‘phpfrl’, ‘/path/to/model/‘); $c = $modx->newQuery(‘frlMeetup’);
 $c->sortby(‘starts_on’, ‘DESC’);
 $meetup = $modx->getObject(‘frlMeetup’, $c); echo ‘De volgende meetup is ‘ . $meetup->name . ‘ en vind plaats op ‘ . $meetup- >starts_on . ‘. ’; $speakers = $meetup->getMany(‘Speakers’); // or just $meetup->Speakers
 foreach ($speakers as $spegfytaker) {
 echo $speaker->name . ‘ zal vertellen over ‘ . $speaker->subject;
 }
  34. 34. The Future of MODX • MODX 3 & MODX Next • Backwards incompatible release (semver) • Cleaning up legacy code no longer relevant • Full namespace support for xPDO models • Composer/packagist support • Proper Dependency Injection in the core • Improved, faster routing with Slim
  35. 35. Interesting links: • MODX.com => official website • rtfm.modx.com => official documentation • github.com/modxcms/revolution => source code • MODX.today => daily links/articles about MODX • modmore.com => premium extras for MODX • https://joind.in/talk/view/15031 => please leave feedback Enjoy your Creative Freedom

×