function index($locator) { $request = $locator->get('Request'); $response = $locator->get('Response'); $page_template = new A_Template_Strreplace('templates/example.html'); $response->setContent($page_template->render()); }
public function logout($locator) { echo "logout()<br/>"; $response = $locator->get('Response'); $usersession = $locator->get('UserSession'); $errmsg = ''; $usernamestr = ''; if ($usersession->isLoggedIn()) { $usersession->logout(); } $page_template = new A_Template_Strreplace('templates/login.html'); $page_template->set('errmsg', $errmsg); $page_template->set('username', $usernamestr); $response->setContent($page_template->render()); }
<?php error_reporting(E_ALL); require 'config.php'; require dirname(__FILE__) . '/../../A/autoload.php'; echo '<h3>Template is PHP file</h3>'; $template = new A_Template_Include('templates/example1.php'); $template->set('one', 'Hello 1'); $template->set('two', 'Happy 2'); $template->set('three', 'Lucky 3'); echo $template->render(); echo '<h3>Template is HTML file</h3>'; $template = new A_Template_Strreplace('templates/example1.html'); $template->set('one', 'Hello 1'); $template->set('two', 'Happy 2'); $template->set('three', 'Lucky 3'); echo $template->render(); echo '<h3>Template is HTML file with blocks</h3>'; $template->makeBlocks(); echo $template->render('one'); echo $template->render('two'); echo $template->render('three'); echo '<h3>Template is HTML file with blocks and array</h3>'; $data = array(0 => array('one' => '0 one', 'two' => '0 two', 'three' => '0 three'), 1 => array('one' => '1 one', 'two' => '1 two', 'three' => '1 three'), 2 => array('one' => '2 one', 'two' => '2 two', 'three' => '2 three')); echo $template->renderArray($data);
$Locator = new A_Locator(); $Locator->autoload(); // initialize autoloading $Request = new A_Http_Request(); $Response = new A_Http_Response(); $Session = new A_Session(); $Locator->set('Config', new A_Collection($ConfigArray)); $Locator->set('Request', $Request); $Locator->set('Response', $Response); $Locator->set('Session', $Session); $Mapper = new A_Http_Pathinfo(array('' => array('controller', 'action', 'id'))); // array('' => array('class', 'method'))); $Mapper->run($Request); // copies clean URL values into the Request based on the map $Action = array('', 'home', 'index'); $Mapper = new A_Controller_Mapper($ConfigArray['APP'], $Action); // action controllers in default 'controller' directory #$Mapper->setDefaultMethod('execute'); // uncomment to make compatable with pre 0.4.x $Controller = new A_Controller_Front($Mapper, $Action); $Controller->run($Locator); if (!$Response->hasRenderer()) { $Template = new A_Template_Strreplace($ConfigArray['APP'] . 'templates/main.html'); $Template->set('title', ''); $Template->set('head', ''); $Template->set('content', ''); $Template->set('sidebar', ''); $Response->setRenderer($Template); } $Response->set('BASE', $ConfigArray['BASE']); // this renders in all templates echo $Response->render();
<?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();
function render($locator) { $request = $locator->get('Request'); $response = $locator->get('Response'); $game = $locator->get('Game'); $template = new A_Template_Strreplace('templates/lose.html'); $template->set('word', $request->get('word')); $response->set('Content', $template->render()); }
function index($locator) { $page_template = new A_Template_Strreplace('templates/error.html'); $this->response->setContent($page_template->render()); }
function index($locator) { $request = $locator->get('Request'); $response = $locator->get('Response'); $page_template = new A_Template_Strreplace('templates/upload_files.html'); $content = ''; $upload = new A_Http_Upload(); // destination directory for uploaded file $upload->setBasePath('./files/'); // destination directory names for select $upload->addPath(1, 'test1/', 'One'); $upload->addPath(2, 'test2/', 'Two'); /* $n = ini_get('file_uploads'); #echo "file_uploads=$n<br>"; $n = ini_get('upload_max_filesize'); #echo "upload_max_filesize=$n<br>"; $n = $upload->getMaxFilesize(); #echo "check_max_filesize=$n<br>"; */ $nfiles = $upload->fileCount(); #echo "nfiles=$nfiles<br>"; #echo '<pre>' . print_r($_FILES, 1) . '</pre>'; if ($nfiles) { $upload->setReplace(false); // if destination file exists delete before moving new file $upload->setMinFilesize(1); // set min size of file with this value $upload->setMaxFilesize(100000); // cap size of file with this value, zero no cap $upload->setAllowedTypes(array()); // set array of allowed file MIME types for ($i = 0; $i < $nfiles; $i++) { if ($upload->isAllowed($i)) { $filename = $upload->getFileName($i); if ($upload->moveUploadedFile($i)) { $content .= "<p>The file <b>{$filename}</b> has been uploaded successfully.</p>"; } else { $errmsg = $upload->getFileErrorMsg($i); $content .= "<p style=\"color:red;\">An error occured uploading {$filename}. {$errmsg}</p>"; } } else { $errmsg = $upload->getFileErrorMsg($i); $content .= "<p style=\"color:red;\">An error occured. {$errmsg}</p>"; } } } else { $uploadform = new A_Http_Uploadform($upload); $uploadform->addHidden('action', 'upload_files'); # $content .= $uploadform->form('index.php'); $content .= $uploadform->formOpen() . "<br/>\n"; if ($request->get('select_path')) { $content .= $uploadform->formSelectPath() . "<br/>\n"; } $content .= $uploadform->formInput() . "<br/>\n"; if ($request->get('multi_file')) { $content .= $uploadform->formInput() . "<br/>\n"; } $content .= $uploadform->formSubmit() . "<br/>\n"; $content .= $uploadform->formClose() . "<br/>\n"; } $page_template->set('uploadform', $content); $response->setContent($page_template->render()); }