Seiten-URL:
http://site.local/ru/topic/view?title=anons
Controller:
Code: Select all
class TopicController extends Controller {
public $layout = 'main';
public $defaultAction = 'index';
public function behaviors() {
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
['allow' => true, 'actions' => ["create", "update", 'admin'], 'roles' => ['@']],
['allow' => true, 'actions' => ["index", "view"], 'roles' => ['?', '@']]
]
]];
}
/**
* Displays a particular model.
* @param string $title the title of the model to be displayed
*/
public function actionView($title) {
$model = Topic::findOne(["code"=>$title]);
if (empty($model))
return $this->redirect(['/404']);
if (!$model->published && (Yii::$app->user->isGuest))
return $this->redirect(['/404']);
if ($model->paid > 0)
Yii::$app->params["nofollow"] = 1;
return $this->render('view', array(
'model'=>$model
));
}
Code: Select all
[i][/i]
Code: Select all
id?>" data-bid="">
[url=" title="" target='_blank' rel="nofollow">
[img]" alt="" loading="lazy">
[/url]
Code: Select all
$banner = Banner::getRandom($type);
Bannersuche:
Code: Select all
public static function getRandom($type = "main_banner") {
$lang = Yii::$app->language;
$country = self::getCountry();
$now = date("Y-m-d");
$tbl = self::tableName();
$tbs = Service::tableName();
$sql = "select $tbl.* from $tbl
inner join $tbs on $tbl.serviceid = $tbs.id
where published = 1
and $tbs.code like :position
and $tbs.lang = :lang
and (finaldate is null or
(initialdate = :now))
and (options is null or length(options) = 0 or options like :country)
order by rand()
limit 1";
$postfix = ("ru" == $lang) ? "" : "_".$lang;
$query = self::findBySql($sql, [
":position"=>$type.$postfix,
":lang"=>$lang,
":now"=>$now,
":country"=>"%".$country."%"
]);
return $query->one();
}
Mobile version