本文整理汇总了PHP中app\models\Categories::findByAlias方法的典型用法代码示例。如果您正苦于以下问题:PHP Categories::findByAlias方法的具体用法?PHP Categories::findByAlias怎么用?PHP Categories::findByAlias使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Categories
的用法示例。
在下文中一共展示了Categories::findByAlias方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parseRequest
public function parseRequest($manager, $request)
{
$route = '';
$params = [];
$pathInfo = $request->getPathInfo();
if ($pathInfo == '') {
return false;
}
$parts = explode('/', $pathInfo);
$next = self::CATEGORY_PART;
//вначале всегда идет раздел
$parent_id = 0;
foreach ($parts as $p) {
if ($p != '') {
switch ($next) {
case self::CATEGORY_PART:
$this->_cat = Categories::findByAlias($p, $parent_id);
if ($this->_cat === null) {
throw new NotFoundHttpException('Страница не найдена');
}
if ($this->getHandlerType($this->_cat->handler) == MController::HANDLE_CAT) {
$next = self::CATEGORY_PART;
$parent_id = $this->_cat->id;
} else {
$next = self::RESOURCE_PART;
}
break;
case self::RESOURCE_PART:
$this->_res = Resources::findByAlias($p, $this->_cat->id);
if ($this->_res === null) {
throw new NotFoundHttpException('Страница не найдена');
}
$next = self::PARAM_PART;
break;
case self::PARAM_PART:
$this->_params[] = $p;
break;
}
}
}
$route = $this->_cat->handler;
// Если раздел содержит всего один ресурс/подраздел и $show_single == 1, тогда покажем дочерний элемент
// Если дочерний элемент подраздел и $show_single == 1 идем ниже и т.д.
if ($this->_res == false) {
$action = 'index';
$params = ['id' => $this->_cat->id];
if ($this->_cat->show_single) {
while (count($this->_cat->subcategories) == 1 && $this->_cat->show_single == 1) {
$this->_cat = $this->_cat->subcategories[0];
}
$route = $this->_cat->handler;
$params = ['id' => $this->_cat->id];
if (count($this->_cat->resources) == 1 && $this->_cat->show_single) {
$action = 'view';
$params = ['id' => $this->_cat->resources[0]->id];
}
}
} else {
$action = 'view';
$params = ['id' => $this->_res->id];
}
$route .= '/' . $action;
return [$route, $params];
}
示例2: findModel
protected function findModel($id)
{
if ($id != 0) {
if (($model = Resources::findOne($id)) !== null) {
return $model;
}
} else {
if (($model = Categories::findByAlias('0', 0)->resources[0]) !== null) {
return $model;
}
}
throw new NotFoundHttpException('The requested page does not exist.');
}