Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 4th, 2012  |  syntax: None  |  size: 2.32 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. class VideoPage extends Page {
  3.  
  4.         public static $db = array(
  5.                 'VideoURL' => 'Text'
  6.         );
  7.  
  8.         public static $has_one = array(
  9.         );
  10.  
  11. }
  12. class VideoPage_Controller extends Page_Controller {
  13.  
  14.         /**
  15.          * An array of actions that can be accessed via a request. Each array element should be an action name, and the
  16.          * permissions or conditions required to allow the user to access it.
  17.          *
  18.          * <code>
  19.          * array (
  20.          *     'action', // anyone can access this action
  21.          *     'action' => true, // same as above
  22.          *     'action' => 'ADMIN', // you must have ADMIN permissions to access this action
  23.          *     'action' => '->checkAction' // you can only access this action if $this->checkAction() returns true
  24.          * );
  25.          * </code>
  26.          *
  27.          * @var array
  28.          */
  29.         public static $allowed_actions = array (
  30.                 'SearchForm'
  31.         );
  32.  
  33.         public function init() {
  34.                 parent::init();
  35.  
  36.                 // Note: you should use SS template require tags inside your templates
  37.                 // instead of putting Requirements calls here.  However these are
  38.                 // included so that our older themes still work
  39.                 Requirements::themedCSS('layout');
  40.                 Requirements::themedCSS('typography');
  41.                 Requirements::themedCSS('form');
  42.                 Requirements::themedCSS('menu');
  43.         }
  44.  
  45.         /**
  46.          * Site search form
  47.          */
  48.         function SearchForm() {
  49.                 $searchText = isset($_REQUEST['Search']) ? $_REQUEST['Search'] : 'Search';
  50.                 $fields = new FieldSet(
  51.                         new TextField('Search', '', $searchText)
  52.                 );
  53.                 $actions = new FieldSet(
  54.                         new FormAction('results', 'Search')
  55.                 );
  56.                 return new SearchForm($this, 'SearchForm', $fields, $actions);
  57.         }
  58.  
  59.         /**
  60.          * Process and render search results.
  61.          *
  62.          * @param array $data The raw request data submitted by user
  63.          * @param SearchForm $form The form instance that was submitted
  64.          * @param SS_HTTPRequest $request Request generated for this action
  65.          */
  66.         function results($data, $form, $request) {
  67.                 $data = array(
  68.                         'Results' => $form->getResults(),
  69.                         'Query' => $form->getSearchQuery(),
  70.                         'Title' => 'Search Results'
  71.                 );
  72.                 return $this->customise($data)->renderWith(array('Page_results', 'Page'));
  73.         }
  74.        
  75.        
  76.         ///////////////////////////////////////////////////////
  77.  
  78.         public function getCMSFields() {
  79.                 $fields = parent::getCMSFields();
  80.  
  81.                 $fields->addFieldToTab('Root.Content.Main', new TextField('VideoURL'), 'Content');
  82.  
  83.                 return $fields;
  84.         }
  85.  
  86. }
  87.  
  88. ?>