Esempio n. 1
0
 /**
  * 
  * @param \Hitar\Table $table
  * @param string $name
  */
 function __construct($table, $name = 'page')
 {
     $this->table = $table;
     $this->_name = $name;
     $this->_page = intval(\Hiano\App\App::getRequest()->getParameter($name));
     if ($this->_page < 1) {
         $this->_page = 1;
     }
     $this->buttons = array('first' => array('href' => '', 'caption' => '首页'), 'prev' => array('href' => '', 'caption' => '上页'), 'next' => array('href' => '', 'caption' => '下页'), 'last' => array('href' => '', 'caption' => '末页'));
 }
Esempio n. 2
0
 function listAction()
 {
     if ($this->request->isPost()) {
         \Hiano\App\App::redirectPostAsParameter();
     }
     $tb = $this->getTableForList();
     /* @var $tb \Hitar\Table */
     $list = $tb->select();
     $this->view->set('list', $list);
     $this->afterSelectOfList($list);
 }
Esempio n. 3
0
 /**
  * 
  * @param type $params
  * @param type $content
  * @param \Smarty_Internal_Template $template
  * @param type $repeat
  * @return string
  */
 static function block_form($params, $content, $template, &$repeat)
 {
     if (!$repeat) {
         $ret = '<form';
         if ($params) {
             foreach ($params as $key => $value) {
                 $ret .= ' ' . $key . '="' . $value . '"';
             }
         }
         $ret .= ">\n" . $content . '<input type="hidden" name="_csrftoken" value="' . \Hiano\App\App::getRequest()->getCookie('_csrftoken') . '" /></form>';
         return $ret;
     }
 }
Esempio n. 4
0
 static function init()
 {
     $dbs = \Hiano\App\App::getConfig()->get('hitar:database');
     $first = NULL;
     foreach ($dbs as $dk => $dv) {
         if ($first === NULL) {
             $first = $dk;
         }
         \Hitar\DatabaseManager::addDatabase($dk, $dv);
     }
     if ($first) {
         \Hitar\DatabaseManager::selectDatabase($first);
     }
 }
Esempio n. 5
0
 /**
  * 
  * @param array $params
  * @return boolean
  * @throws UrlFormatException
  */
 function format($params)
 {
     $param_arr = [];
     foreach ($params as $pk => $pv) {
         if ($pv !== '') {
             $param_arr[$pk] = $pv;
         }
     }
     if ($this->route) {
         foreach ($this->route as $route) {
             if ($url = $route->format($param_arr)) {
                 return \Hiano\App\App::getBaseUrl() . $url . $this->getSuffix();
             }
         }
     }
     throw new UrlFormatException('无法格式化URL:' . print_r($arr, TRUE));
 }
Esempio n. 6
0
 /**
  * 渲染视图
  * @param string $version 模板版本
  * @return string
  * @throws Exception
  */
 function render($version = NULL)
 {
     $view_driver = \Hiano\App\App::newViewDriver();
     $name = get_class($this);
     if (substr($name, -6) !== 'Widget') {
         throw new \Exception('错误的Widget类名:' . $name);
     }
     $short_name = substr($name, 0, -6);
     $suffix = '.tpl';
     if ($version) {
         $suffix = '.' . $version . $suffix;
     }
     $file_name = str_replace('\\', '/', $short_name);
     $tpl_file = HIANO_APP_PATH . '/Widget/' . $file_name . $suffix;
     $tpl_dir = dirname($tpl_file);
     $tpl_basename = basename($tpl_file);
     $view_driver->setTemplateDirs((array) $tpl_dir);
     return $view_driver->render($tpl_basename, $this->vars);
 }
Esempio n. 7
0
 static function init()
 {
     if (!defined('HIANO_APP_PATH')) {
         die('ERROR:HIANO_APP_PATH undefined!');
     }
     spl_autoload_register(array('Hiano\\ClassLoader', 'load'));
     if (App\App::getConfig()->get('debug.enable', false)) {
         $debug_config = App\App::getConfig()->get('debug');
         error_reporting($debug_config['error_reporting']);
         unset($debug_config);
     } else {
         error_reporting(0);
     }
     if (App\App::getConfig()->get('timezone')) {
         date_default_timezone_set(App\App::getConfig()->get('timezone'));
     }
     if ($session_path = App\App::getConfig()->get('session_path')) {
         //todo load and register SessionDriver
         //$session_driver = Hiano::loadDriver('\\Hiano\\')
         //\Hiano\Session\SessionManager::register();
     }
     //\Hiano\App\App::registerModelPath(HIANO_APP_PATH . '/widgets/models');
     $app_path = realpath(HIANO_APP_PATH);
     \Hiano\App\App::registerModelPath($app_path . '/Model');
     \Hiano\App\App::registerImportPath($app_path . '/Include');
     App\App::setErrorHandler(function ($ex) {
         /* @var $ex \Hiano\ErrorException */
         throw new \Exception("Error[{$ex->getCode()}]:" . $ex->getMessage());
     });
     App\App::setRedirectHandler(function ($ex) {
         /* @var $ex \Hiano\RedirectException */
         header('Location:' . $ex->getRedirectUrl());
     });
 }
Esempio n. 8
0
<?php

/**
 * 
 * @author kasonyang <*****@*****.**>
 */
define('HIANO_APP_PATH', __DIR__ . '/../AppDemo');
include __DIR__ . '/../../vendor/autoload.php';
\Hiano\App\App::run();
Esempio n. 9
0
 function afterUpdate($model)
 {
     \Hiano\App\App::redirectRequest('list');
 }