Exemplo n.º 1
0
/**
 * The action that displays the entry insert form .
 *
 * @param PDO $pdo The PDO object.
 * @return Opt_View
 */
function action($pdo, $config)
{
    $view = new Opt_View('add.tpl');
    $view->title = 'Add new entry';
    $form = new Form($view);
    $form->setAction('index.php?action=add');
    $form->addField('author', 'required,min_len=3,max_len=30', 'The length must be between 3 and 30 characters.');
    $form->addField('email', 'required,email,min_len=3,max_len=100', 'The value must be a valid mail with maximum 100 characters long.');
    $form->addField('website', 'url,min_len=3,max_len=100', 'The value must be a valid URL with maximum 100 characters long.');
    $form->addField('body', 'required,min_len=3', 'The body must be at least 3 characters long.');
    if ($form->validate()) {
        $values = $form->getValues();
        $stmt = $pdo->prepare('INSERT INTO `entries` (`author`, `email`, `date`, `website`, `body`)
			VALUES(:author, :email, :date, :website, :body)');
        $stmt->bindValue(':author', $values['author'], PDO::PARAM_STR);
        $stmt->bindValue(':email', $values['email'], PDO::PARAM_STR);
        $stmt->bindValue(':date', time(), PDO::PARAM_INT);
        $stmt->bindValue(':website', $values['website'], PDO::PARAM_STR);
        $stmt->bindValue(':body', $values['body'], PDO::PARAM_STR);
        $stmt->execute();
        $view->setTemplate('message.tpl');
        $view->message = 'The entry has been successfully added!';
        $view->redirect = 'index.php?action=list';
    } else {
        // The form is an object, so we need to inform OPT about it.
        $view->form = $form;
        $view->setFormat('form', 'Objective');
    }
    return $view;
}
Exemplo n.º 2
0
 /**
  * The private rendering utility that performs all the basic
  * rendering tasks, such as registering the data formats for
  * the placeholders.
  *
  * @param Opt_View $view The view the form is rendered in.
  * @internal
  */
 protected function _onRender(Opt_View $view)
 {
     $this->setInternal('name', $this->_name);
     foreach ($this->_items as $placeholder => &$void) {
         $view->setFormat($placeholder, 'Form/Form');
     }
     foreach ($this->_collection as $item) {
         $item->_onRender($view);
     }
 }
Exemplo n.º 3
0
Opl_Registry::setState('opl_debug_console', false);
Opl_Registry::setState('opl_extended_errors', true);
try {
    $tpl = new Opt_Class();
    $tpl->sourceDir = './templates/';
    $tpl->compileDir = './templates_c/';
    $tpl->charset = 'utf-8';
    $tpl->compileMode = Opt_Class::CM_REBUILD;
    $tpl->stripWhitespaces = false;
    //$tpl->register(Opt_Class::OPT_FORMAT, 'Paginator', 'Opc_Paginator_DataFormat');
    $tpl->setup();
    $opc = new Opc_Class();
    $pager = Opc_Paginator::create(1000, 13);
    // returns Opc_Paginator_Pager;
    $pager->all = 1000;
    $pager->page = isset($_GET['page']) ? $_GET['page'] : 1;
    $view = new Opt_View('paginator_opt.tpl');
    $view->pager = $pager;
    //$view->setFormat('pager', 'Paginator');
    $view->setFormat('pager', 'Objective/Array');
    $view->setFormat('pager.decorator', 'Objective');
    $out = new Opt_Output_Http();
    $out->setContentType(Opt_Output_Http::HTML);
    $out->render($view);
} catch (Opc_Exception $exception) {
    $handler = new Opc_ErrorHandler();
    $handler->display($exception);
} catch (Opt_Exception $exception) {
    $handler = new Opt_ErrorHandler();
    $handler->display($exception);
}
Exemplo n.º 4
0
 /**
  * Registers the item wrappers in the template as a placeholder.
  *
  * @param Opt_View $view The view the form is rendered in
  * @internal
  */
 protected function _onRender(Opt_View $view)
 {
     $view->setFormat($this->_name, 'FormRepeater/Form');
 }