* @license LGPL, see license.txt for details * @link http://www.php-tools.net */ /** * Main examples prepend file, needed *only* for the examples framework! */ include_once 'patExampleGen/prepend.php'; $exampleGen->displayHead( 'Example' ); // EXAMPLE START ------------------------------------------------------ // change this according to your setup $pathToBookstore = dirname(__FILE__) . '/propel'; // omit 'bookstore/' here // change these according to your propel settings $pathToCache = './cache'; $propelConfFilename = 'conf/bookstore-conf.php'; $classname = 'Book'; /** * setup include path */ set_include_path(get_include_path() . PATH_SEPARATOR . $pathToBookstore); /** * include needed files */ require_once 'propel/Propel.php'; require_once $neededFiles['patForms']; require_once $neededFiles['patErrorManager']; require_once $neededFiles['patI18n_configure']; require_once $neededFiles['patTemplate']; require_once 'patForms/Definition/Propel.php'; require_once 'bookstore/Book.php'; require_once 'bookstore/Author.php'; require_once 'bookstore/Publisher.php'; Propel::init($propelConfFilename); $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null; switch($action) { default: case 'list': { displayPropelList(array( 'classname' => $classname )); break; } case 'details': { displayPropelDetails(array( 'primary' => (isset($_REQUEST['Id']) ? array('Id' => $_REQUEST['Id']) : array()), 'classname' => $classname )); break; } case 'form': { displayPropelForm(array( 'primary' => (isset($_REQUEST['Id']) ? array('Id' => $_REQUEST['Id']) : array()), 'classname' => $classname, 'path' => $pathToCache, )); break; } } exit; function displayPropelList($args) { extract($args); $callable = array($classname . 'Peer', 'doSelect'); $list = call_user_func_array($callable, array(new Criteria())); echo '
'; echo 'Add'; echo '
'; echo '%s | %s | %s | edit |
'; echo 'List · '; echo 'Edit'; echo '
'; echo '%s | %s |
'; echo 'List'; if ($pk) { echo ' · '; echo 'Details'; } echo '
'; if (!$form->isSubmitted()) { $tpl->displayParsedTemplate(); } elseif (!$form->valid) { displayErrors($form); $tpl->displayParsedTemplate(); } else { echo 'Save successful'; } } // could this probably make its way into patForms? class patForms_Factory_Propel { static public function create($conf) { extract($conf); // create a patTemplate renderer $renderer =& patForms::createRenderer('patTemplate'); $renderer->setPlaceholder('PATFORMS_ELEMENT', null); $renderer->setAttributes(array('display', 'description')); // create a form definition $definition = patForms_Definition_Propel::create(array( 'name' => $classname, 'filename' => $path . '/form.' . $classname . '.xml', )); // create a form $form = &patForms::createCreator('Definition')->create($definition); $form->enableOption('scripts'); $form->setAutoValidate('save'); $form->setRenderer($renderer); // create a storage $storage = patForms::createStorage('Propel'); $storage->setStorageLocation($classname . 'peer'); $form->setStorage($storage); // set data if (isset($primary)) { $form->setValues($primary); } return $form; } } ?>