Exemple #1
0
 /**
  * Bese controller constructor: restores user object by using session data and
  * checks a permission to a requested action
  *
  * @param LiveCart $application Application instance
  * @throws AccessDeniedExeption
  */
 public function __construct(LiveCart $application)
 {
     parent::__construct($application);
     $this->router = $this->application->getRouter();
     if (!$application->isInstalled() && !$this instanceof InstallController) {
         header('Location: ' . $this->router->createUrl(array('controller' => 'install', 'action' => 'index')));
         exit;
     }
     unset($this->locale);
     unset($this->config);
     unset($this->user);
     unset($this->session);
     $this->checkAccess();
     $this->application->setRequestLanguage($this->request->get('requestLanguage'));
     $this->configFiles = $this->getConfigFiles();
     $this->application->setConfigFiles($this->configFiles);
     $localeCode = $this->application->getLocaleCode();
     // add language code to URL for non-default languages
     if ($localeCode != $this->application->getDefaultLanguageCode()) {
         $this->router->setAutoAppendVariables(array('requestLanguage' => $localeCode));
     }
     // verify that the action is accessed via HTTPS if it is required
     if ($this->router->isSSL($this->request->getControllerName(), $this->request->getActionName()) && !$this->router->isHttps()) {
         header('Location: ' . $this->router->createFullUrl($_SERVER['REQUEST_URI'], true));
         exit;
     }
 }
Exemple #2
0
 public static function links($current, $all, $perPage = 50)
 {
     $view = new View('pagination');
     $view->total_pages = ceil($all / $perPage);
     $view->current_page = $current;
     $view->per_page = $perPage;
     $view->previous_page = $current > 0 ? $current - 1 : false;
     $view->next_page = $current + 1 < $all ? $current + 1 : false;
     $view->url = Router::createUrl(array('page' => '{page}'));
     return $view->render();
 }
Exemple #3
0
function smarty_function_createUrl($param, &$smarty)
{
    $project = isset($param['project']) ? $param['project'] : '';
    $controller = isset($param['controller']) ? $param['controller'] : '';
    $action = isset($param['action']) ? $param['action'] : '';
    $baseUrl = isset($param['baseUrl']) ? $param['baseUrl'] : '';
    $params = isset($param['params']) ? $param['params'] : '';
    $delParams = isset($param['delParams']) ? $param['delParams'] : '';
    $addParams = isset($param['addParams']) ? $param['addParams'] : '';
    $baseUrl = isset($param['baseUrl']) ? $param['baseUrl'] : '';
    if (!empty($delParams)) {
        return Router::delUrlParams($controller, $action, $delParams, $project, $baseUrl);
    }
    if (!empty($addParams)) {
        return Router::addUrlParams($controller, $action, $addParams, $project, $baseUrl);
    }
    return Router::createUrl($controller, $action, $params, $project, $baseUrl);
}
Exemple #4
0
 /**
  * 翻页页码初始化
  * @param int $totalNum 总条数
  * @param int $pageSize 每页显示条数 
  * @param int $params 链接参数,默认为空时使用$_GET
  * @param int $pName 翻页页码数参数名称,默认为page
  * @return void
  */
 public function __construct($totalNum, $pageSize, $params = array(), $pName = 'page')
 {
     $pageSize = intval($pageSize);
     if (empty($pageSize)) {
         return false;
     }
     empty($params) && ($params = BaseModelRouter::$get);
     //基本数据计算
     $this->totalNum = max(intval($totalNum), 0);
     //自然数
     $this->pageSize = max($pageSize, -1 * $pageSize);
     //自然数,当$pageSize=0时不分页
     $this->params = $params;
     empty($pName) || ($this->pName = $pName);
     $this->page = isset($this->params[$this->pName]) ? max($this->params[$this->pName], 1) : 1;
     $this->totalPage = ceil($this->totalNum / $this->pageSize);
     // $this->page = min($this->page, $this->totalPage);
     $this->prePage = max($this->page - 1, 1);
     //上一页
     $this->nextPage = min($this->page + 1, $this->totalPage);
     //下一页
     $this->lastPage = $this->totalPage;
     //最后一页
     //limit计算
     $this->page || ($this->page = 1);
     $this->limit = " LIMIT " . ($this->page - 1) * $this->pageSize . ', ' . $this->pageSize;
     //用于 MySQL 分页生成语句
     //url参数计算
     unset($this->params[$this->pName]);
     if (defined('QUEUE') || defined('EXTERN')) {
         $this->paramStr = "?" . http_build_query($this->params);
     } else {
         $this->paramStr = Router::createUrl('', '', $this->params);
     }
     if (strpos($this->paramStr, '?') !== false) {
         $this->paramStr .= '&';
     } else {
         $this->paramStr .= '?';
     }
     return;
 }
Exemple #5
0
<tr class="crud-search-tr">
<td>&nbsp;</td>
<?php 
foreach ($columns as $column => $name) {
    echo '<td>';
    echo '<input type="text" class="crud-search-field" name="search[' . $column . ']" value="' . (isset($_GET['search']['column']) ? htmlspecialchars($_GET['search']['column']) : '') . '">';
    echo '</td>';
}
?>
</tr>
<?php 
foreach ($iterations as $row) {
    echo '<tr>';
    echo '<td><input type="checkbox" name="ids[' . $row->id . ']"' . ((isset($_GET['ids'][$row->id]) and $_GET['ids'][$row->id] == 'on') ? ' checked="checked"' : '') . '/></td>';
    foreach ($columns as $column => $name) {
        echo '<td onclick="document.location = \'' . Router::createUrl(array('id' => $row->id)) . '\'">' . $row->{$column} . '</td>';
    }
    echo '</tr>';
}
?>
</table>
<?php 
if ($countAll > 0) {
    ?>
<a href="javascript:document.getElementById('crud-form').submit()"><?php 
    echo Dict::word('delete marked');
    ?>
</a>
|
<?php 
}
Exemple #6
0
<form method="post" action="<?php 
echo Router::createUrl(array(), false, false);
?>
" class="crud-form">
<fieldset>
<table>
<?php 
foreach ($model->fields() as $column => $name) {
    echo '<tr>';
    echo '<td>' . $name . '</td>';
    echo '<td><input type="text" name="data[' . $column . ']" value="' . htmlspecialchars($model->{$column}) . '"/>';
}
?>
</table>
<input type="hidden" name="id" value="<?php 
echo $model->id;
?>
"/>
<input type="submit" class="submit" value="<?php 
echo Dict::word('Save');
?>
"/>
</fieldset>
</form>
Exemple #7
0
 /**
  * 网址(URL)组装操作
  *
  * 注:组装绝对路径的URL
  *
  * @access public
  *
  * @param string $route controller与action。例:controllerName/actionName
  * @param array $params URL路由其它字段。注:url的参数信息
  *
  * @return string
  */
 public static function createUrl($route, $params = array())
 {
     //参数分析
     if (!$route) {
         return false;
     }
     return Router::createUrl($route, $params);
 }
 public function testRouteNotFound()
 {
     $this->setExpectedException('Http\\RouterException');
     $router = new Router();
     $router->createUrl('404');
 }
Exemple #9
0
 /**
  * 网址(URL)组装操作
  *
  * 注:组装绝对路径的URL
  *
  * @access public
  *
  * @param string $route controller与action。例:controllerName/actionName
  * @param array $params URL路由其它字段。注:url的参数信息
  *
  * @return string
  */
 public static function createUrl($route, $params = array())
 {
     return Router::createUrl($route, $params);
 }