Changeset 4073
- Timestamp:
- 05/22/07 10:44:48 (6 years ago)
- Files:
-
- plugins/sfSimplePageControllerPlugin/README (modified) (1 diff)
- plugins/sfSimplePageControllerPlugin/lib/sfSimplePageConfigDriver.php (added)
- plugins/sfSimplePageControllerPlugin/lib/sfSimplePageConfigHandler.php (modified) (3 diffs)
- plugins/sfSimplePageControllerPlugin/lib/sfSimplePageDemoDriver.php (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfSimplePageControllerPlugin/README
r4068 r4073 53 53 54 54 55 == Write your own config driver == 56 57 You can write your own config driver to fetch/build pages. Thus you can use one single "page action" 58 to show many pages, e.g. stored in a database. 59 60 Instead of "children" you have to write the following line into your pageFoo.yml: 61 62 driver: MyDriverClass 63 64 65 You have to extend the class sfSimplePageConfigDriver and implement the abstract methods. 66 Look at sfSimplePageDemoDriver.php to see a very simple example how to setup a page. 55 67 56 68 plugins/sfSimplePageControllerPlugin/lib/sfSimplePageConfigHandler.php
r4068 r4073 35 35 $pageConfig = $this->parseYaml($configFiles[0]); 36 36 37 // validate config and build code38 if (empty($pageConfig['children']))39 {40 throw new sfException('You have to set at least one child in your page configuration.');41 }42 43 37 $code = array(); 44 38 … … 47 41 $code[] = "// date: " . date('Y-m-d H:i:s'); 48 42 $code[] = ''; 49 50 43 $code[] = "\$page = sfSimplePage::getInstance();"; 51 44 45 if (!empty($pageConfig['driver'])) 46 { 47 $this->compileForDriver($pageConfig, $code); 48 } 49 elseif (!empty($pageConfig['children'])) 50 { 51 $this->compileForYml($pageConfig, $code); 52 } 53 else 54 { 55 throw new sfConfigurationException('You have to either set driver or children in your page configuration.'); 56 } 57 58 // compile data 59 $retval = implode("\n", $code); 60 return $retval; 61 } 62 63 /** 64 * Compiles the config for use with a custom driver. 65 */ 66 protected function compileForDriver($pageConfig, &$code) 67 { 68 $code[] = "\$context = sfContext::getInstance();"; 69 $code[] = "\$driverInstance = new {$pageConfig['driver']}(\$context, \$page);"; 70 } 71 72 /** 73 * Compiles the page config from yml settings. 74 */ 75 protected function compileForYml($pageConfig, &$code) 76 { 52 77 if (!empty($pageConfig['layout']['template'])) 53 78 { 54 79 $code[] = "\$this->setTemplate('{$pageConfig['layout']['template']}');"; 55 80 } 56 /*57 if (!empty($pageConfig['layout']['theme'])) {58 $code[] = "\$this->setTheme('{$pageConfig['layout']['theme']}');";59 }60 if (!empty($pageConfig['layout']['style'])) {61 $code[] = "\$this->setStyle('{$pageConfig['layout']['style']}');";62 }*/63 81 64 82 foreach ($pageConfig['children'] as $areaId => $children) … … 107 125 } 108 126 } 109 110 // compile data111 $retval = implode("\n", $code);112 return $retval;113 127 } 114 115 128 116 129 // for debugging only