示例#1
0
 public static function test()
 {
     $tests = array("/this/is/a/path", "/second/level", "/somethingelse", "/foo");
     $rules = array(array("rule" => "/foo", "template" => "fooonly"), array("rule" => "/%/%", "template" => "secondlevel"), array("rule" => "*", "template" => "simple"));
     foreach ($tests as $test) {
         $rule = aRules::select($rules, $test);
         if ($rule) {
             echo $test . ": " . $rule['template'] . " " . $rule['rule'] . "\n";
         } else {
             echo "No match\n";
         }
     }
 }
 public function executeCreate()
 {
     $this->flunkUnless($this->getRequest()->getMethod() == sfRequest::POST);
     $parent = $this->retrievePageForEditingBySlugParameter('parent', 'manage');
     $title = trim($this->getRequestParameter('title'));
     $this->flunkUnless(strlen($title));
     $pathComponent = aTools::slugify($title, false);
     $base = $parent->getSlug();
     if ($base === '/') {
         $base = '';
     }
     $slug = "{$base}/{$pathComponent}";
     $page = new aPage();
     $page->setArchived(!sfConfig::get('app_a_default_on', true));
     $page->setSlug($slug);
     $existingPage = aPageTable::retrieveBySlug($slug);
     if ($existingPage) {
         // TODO: an error in addition to displaying the existing page?
         return $this->redirect($existingPage->getUrl());
     } else {
         $page->getNode()->insertAsFirstChildOf($parent);
         // Figure out what template this new page should use based on
         // the template rules.
         //
         // The default rule assigns default to everything.
         $rule = aRules::select(sfConfig::get('app_a_template_rules', array(array('rule' => '*', 'template' => 'default'))), $slug);
         if (!$rule) {
             $template = 'default';
         } else {
             $template = $rule['template'];
         }
         $page->template = $template;
         // Must save the page BEFORE we call setTitle, which has the side effect of
         // refreshing the page object
         $page->save();
         $page->setTitle(htmlspecialchars($title));
         return $this->redirect($page->getUrl());
     }
 }