Exemple #1
0
 public function indexAction()
 {
     try {
         echo "\r\n <br /> hello, i'm indexAction in controller_index, nice 2 meet u! <br />\r\n ";
         echo "\r\n <br /> now set language to zh-cn! <br />\r\n ";
         i18n::setLanguage('en-us');
         echo "\r\n <br /> in english, my name is: " . i18n::get('author') . " <br />\r\n ";
         echo "\r\n <br /> now set language to zh-cn! <br />\r\n ";
         i18n::setLanguage('zh-cn');
         echo "\r\n <br /> in chinese, my name is: " . i18n::get('author') . " <br />\r\n ";
         $mDemo = new model_demo();
         $uin = 10000;
         $uinfo = $mDemo->getUserInfo($uin);
         $uinfo2 = $mDemo->getUserInfo2($uin);
         $update = $mDemo->updateInfo(6, 1);
         var_dump($uinfo, $uinfo2, $update);
         $confs = array('title' => 'page title', 'time' => date('Ymd H:i:s'), 'name' => 'ricolau');
         log::add('error', 'im test~!');
     } catch (exception_i18n $e) {
         //i18n 的异常,一般是由于语言包不存在
         $code = $e->getCode();
         if ($code == exception_i18n::type_language_not_exist) {
             echo "\r\n <br /> exception: language of " . i18n::getLanguage() . ' not exist!\\r\\n <br />';
         }
         echo $e->getMessage();
     } catch (Exception $e) {
         //如果实在还是有exception,那就捕捉到这里吧,ignore 忽略处理的话。代码继续执行 $this->render(),不会白页。
         //throw $e;  //如果把这个异常抛上去,当前页面就木有了,上层接收到的话自己处理就好了,比如报个异常啥的
         $code = $e->getCode();
         echo $e->getMessage();
     }
     //一般来说 render 这块儿可以不用 try 和 cache,只有 template 或 slot 不存在才会有异常而已。
     //但是建议和上面部分业务代码的try cache 结构分离,从而可以更好的决定,如果业务数据有问题,页面是否还继续render()
     try {
         //按变量单独 assign
         $this->assign('uinfo', $uinfo);
         $this->assign('updateresult', $update);
         //批量assign 一个数组可以!
         $this->massign($confs);
         $this->render();
     } catch (exception_render $e) {
         //一般来说这个exception  不会有,模板放好了就行了么
         $code = $e->getCode();
         if ($code == exception_render::type_tpl_not_exist) {
             echo '\\r\\n <br /> exception: template not exist!\\r\\n <br />';
         } elseif ($code == exception_render::type_slot_not_exist) {
             echo '\\r\\n <br /> exception: template not exist!\\r\\n <br />';
         }
         echo $e->getMessage();
     }
     // equals to $this->render('index', 'index');
     return;
     //绝对不要用 exit!!!!!
 }
Exemple #2
0
 /**
  * Display ZeroBin frontend.
  *
  * @access private
  * @return void
  */
 private function _view()
 {
     // set headers to disable caching
     $time = gmdate('D, d M Y H:i:s \\G\\M\\T');
     header('Cache-Control: no-store, no-cache, must-revalidate');
     header('Pragma: no-cache');
     header('Expires: ' . $time);
     header('Last-Modified: ' . $time);
     header('Vary: Accept');
     // label all the expiration options
     $expire = array();
     foreach ($this->_conf->getSection('expire_options') as $time => $seconds) {
         $expire[$time] = $seconds == 0 ? i18n::_(ucfirst($time)) : filter::time_humanreadable($time);
     }
     // translate all the formatter options
     $formatters = array_map(array('i18n', 'translate'), $this->_conf->getSection('formatter_options'));
     // set language cookie if that functionality was enabled
     $languageselection = '';
     if ($this->_conf->getKey('languageselection')) {
         $languageselection = i18n::getLanguage();
         setcookie('lang', $languageselection);
     }
     $page = new RainTPL();
     $page::$path_replace = false;
     // we escape it here because ENT_NOQUOTES can't be used in RainTPL templates
     $page->assign('CIPHERDATA', htmlspecialchars($this->_data, ENT_NOQUOTES));
     $page->assign('ERROR', i18n::_($this->_error));
     $page->assign('STATUS', i18n::_($this->_status));
     $page->assign('VERSION', self::VERSION);
     $page->assign('DISCUSSION', $this->_conf->getKey('discussion'));
     $page->assign('OPENDISCUSSION', $this->_conf->getKey('opendiscussion'));
     $page->assign('MARKDOWN', array_key_exists('markdown', $formatters));
     $page->assign('SYNTAXHIGHLIGHTING', array_key_exists('syntaxhighlighting', $formatters));
     $page->assign('SYNTAXHIGHLIGHTINGTHEME', $this->_conf->getKey('syntaxhighlightingtheme'));
     $page->assign('FORMATTER', $formatters);
     $page->assign('FORMATTERDEFAULT', $this->_conf->getKey('defaultformatter'));
     $page->assign('NOTICE', i18n::_($this->_conf->getKey('notice')));
     $page->assign('BURNAFTERREADINGSELECTED', $this->_conf->getKey('burnafterreadingselected'));
     $page->assign('PASSWORD', $this->_conf->getKey('password'));
     $page->assign('FILEUPLOAD', $this->_conf->getKey('fileupload'));
     $page->assign('BASE64JSVERSION', $this->_conf->getKey('base64version'));
     $page->assign('LANGUAGESELECTION', $languageselection);
     $page->assign('LANGUAGES', i18n::getLanguageLabels(i18n::getAvailableLanguages()));
     $page->assign('EXPIRE', $expire);
     $page->assign('EXPIREDEFAULT', $this->_conf->getKey('default', 'expire'));
     $page->assign('EXPIRECLONE', !$this->_doesExpire || $this->_doesExpire && $this->_conf->getKey('clone', 'expire'));
     $page->assign('URLSHORTENER', $this->_conf->getKey('urlshortener'));
     $page->draw($this->_conf->getKey('template'));
 }
Exemple #3
0
?>
<br /><br />

######## hi, i'm /index/index template ################
<br /><br />

<?php 
$this->slot('index/section');
?>
<br /><br />


######## show i18n use here ################

current language is: <?php 
echo i18n::getLanguage();
?>
<br /><br />

the author's gender is:<?php 
echo i18n::get('gender');
?>
<br /><br />

and the vget of i18n is: <?php 
echo i18n::vget('telltime', array($title, $time));
?>
<br /><br />