Beispiel #1
0
 function actionsetsrenderer($locator)
 {
     //$view = $this->_load()->view();
     $template = $this->_load()->template('setsrenderertemplate.html');
     $template->set('content', 'This is content set in the the action actionsetsrenderer.');
     $view = new A_Http_View();
     $view->setRenderer($template);
     echo $view->render();
 }
Beispiel #2
0
 public function render($template = '', $scope = '')
 {
     $model = $this->_load()->model();
     $template = $this->_load()->template();
     $template->set('model', $model);
     $this->setRenderer($template);
     return parent::render();
 }
Beispiel #3
0
 public function render($template = '', $scope = '')
 {
     if ($this->headers) {
         foreach ($this->headers as $name => $values) {
             header("{$name}: " . implode(',', $values));
         }
     }
     if ($this->cookies) {
         foreach ($this->cookies as $args) {
             call_user_func_array('setcookie', $args);
         }
     }
     if ($this->redirect) {
         $host = $_SERVER['SERVER_NAME'];
         $script = $host . dirname($_SERVER['SCRIPT_NAME']);
         if (!preg_match('/^https?\\:\\/\\//i', $this->redirect) && strpos($this->redirect, $script) === false) {
             $protocol = 'http://';
             if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']) {
                 $protocol = 'https://';
             }
             if ($this->redirect[0] == '/') {
                 $base = rtrim($host, '/') . '/';
             } else {
                 $base = rtrim($script, '/') . '/';
             }
             $this->redirect = $protocol . $base . $this->redirect;
         }
         # astions Google Chrome caching redirects fix
         # header("Cache-Control: max-age=0, no-cache, no-store, must-revalidate"); // HTTP/1.1
         # header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
         # header("Location: $url", true, 302);
         # or just
         # header("Location: $url", true, 303);
         header("Cache-Control: max-age=0, no-cache, no-store, must-revalidate");
         // HTTP/1.1
         header('Location: ' . $this->redirect, true, 303);
     } else {
         parent::render($template, $scope);
         foreach ($this->headers as $field => $params) {
             if (!is_null($params)) {
                 header($field . ': ' . implode(', ', $params));
             }
         }
         return $this->content;
     }
 }
Beispiel #4
0
 public function __construct($locator)
 {
     parent::__construct($locator);
     $this->setTemplate('example');
     $this->set('menuitems', array(array('menu_link' => '?', 'menu_title' => 'default action using setTemplate()'), array('menu_link' => '?controller=example&action=needsdifferenttemplate', 'menu_title' => 'this action uses setTemplate() with  a different template'), array('menu_link' => '?controller=example&action=actionsetscontent', 'menu_title' => 'this action uses setContent()'), array('menu_link' => '?controller=example&action=actionsetsrenderer', 'menu_title' => 'this action uses setsRenderer() and the A_Template_Strreplace class')));
 }
Beispiel #5
0
 function __construct($locator)
 {
     parent::__construct($locator);
 }
<?php

include 'config.php';
include '../../A/Locator.php';
$Locator = new A_Locator();
$Locator->autoload();
$Response = new A_Http_Response();
$view1 = new A_Http_View();
$view1->set('title', 'Block One');
$view1->set('content', 'This is the content for block one. ');
$view1->setTemplate('block1.php');
// MVC objects assume a templates/ directory
$view2 = new A_Http_View('block2');
$template2 = new A_Template_Strreplace('templates/block2.html');
$template2->set('title', 'Block Two');
$template2->set('content', 'This is the content for block two. ');
$view2->setRenderer($template2);
$layout = new A_Http_View('layout');
$layout->set('block1', $view1);
$layout->set('block2', $view2);
$layout->set('content', 'This is the content for the layout. ');
$layout->setRenderer(new A_Template_Strreplace('templates/layout.html'));
#$doc = new A_Html_Doc(array('doctype'=>'HTML_5'));
$doc = new A_Html_Doc();
$doc->setDoctype(A_Html_Doctype::HTML_5);
$Response->set('layout', $layout);
$Response->set('title', 'Response Example');
$Response->set('BASE', 'http://' . $_SERVER['SERVER_NAME'] . dirname($_SERVER['SCRIPT_NAME']));
$Response->setRenderer($doc);
$Response->set('body', '<h1>This content goes in the body.</h1>');
echo $Response->render();
Beispiel #7
0
 function testHttp_ViewSetEscape()
 {
     $locator = new A_Locator();
     $view = new A_Http_View($locator);
     $str = '<hr style="foo"> &';
     $str_escaped = '&lt;hr style=&quot;foo&quot;&gt; &amp;';
     $file = 'foobar.php';
     $view->setTemplate($file);
     $view->setTemplatePath(dirname(__FILE__) . '/templates');
     $view->setEscape('foo', $str);
     $view->set('bar', '');
     $this->assertEqual($str_escaped, $view->render());
     $view->escapeField('foo');
     $view->set('foo', $str);
     $view->set('bar', '');
     $this->assertEqual($str_escaped, $view->render());
     $view->escapeField(array('foo', 'bar'));
     $view->set('foo', $str);
     $view->set('bar', $str);
     $this->assertEqual($str_escaped . $str_escaped, $view->render());
 }