Development

Changeset 4073

You must first sign up to be able to contribute.

Changeset 4073

Show
Ignore:
Timestamp:
05/22/07 10:44:48 (6 years ago)
Author:
mahono
Message:

added basic driver support, now you can write your own page config driver, see README

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfSimplePageControllerPlugin/README

    r4068 r4073  
    5353 
    5454 
     55== Write your own config driver == 
     56 
     57You can write your own config driver to fetch/build pages. Thus you can use one single "page action" 
     58to show many pages, e.g. stored in a database. 
     59 
     60Instead of "children" you have to write the following line into your pageFoo.yml: 
     61 
     62driver: MyDriverClass 
     63 
     64 
     65You have to extend the class sfSimplePageConfigDriver and implement the abstract methods. 
     66Look at sfSimplePageDemoDriver.php to see a very simple example how to setup a page. 
    5567 
    5668 
  • plugins/sfSimplePageControllerPlugin/lib/sfSimplePageConfigHandler.php

    r4068 r4073  
    3535    $pageConfig = $this->parseYaml($configFiles[0]); 
    3636 
    37     // validate config and build code 
    38     if (empty($pageConfig['children'])) 
    39     { 
    40       throw new sfException('You have to set at least one child in your page configuration.'); 
    41     } 
    42  
    4337    $code = array(); 
    4438 
     
    4741    $code[] = "// date: " . date('Y-m-d H:i:s'); 
    4842    $code[] = ''; 
    49  
    5043    $code[] = "\$page = sfSimplePage::getInstance();"; 
    5144 
     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  { 
    5277    if (!empty($pageConfig['layout']['template'])) 
    5378    { 
    5479      $code[] = "\$this->setTemplate('{$pageConfig['layout']['template']}');"; 
    5580    } 
    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         }*/ 
    6381 
    6482    foreach ($pageConfig['children'] as $areaId => $children) 
     
    107125      } 
    108126    } 
    109  
    110     // compile data 
    111     $retval = implode("\n", $code); 
    112     return $retval; 
    113127  } 
    114  
    115128 
    116129    // for debugging only