Answer the question
In order to leave comments, you need to log in
How to add custom CNCs using Yii framework?
Hello, there is a problem that I solved vlob, if there is a simpler and more elegant solution, I would be happy to help! There is a link field in the table where the name of the link after the domain is set, for example, http://site/data-from-link-variable i.e. this field is unique and the material is pulled from the database by the value of this field. I implemented it this way, I set up the main.php file in the config directory by redirecting requests to one controller that parses them all, because. there are more tables in the database that store data with previously set links, you have to do an additional check.
(Updated, implemented like this, everything is sorted out in one controller, Cyrillic links work through the utf8_encode function, it is possible to set almost any characters)
in the config file:
'urlManager'=>array(
'urlFormat' => 'path',
'showScriptName' => false,
'caseSensitive' => true,
'useStrictParsing'=>true,
'urlSuffix'=>'/',
'rules' => array(
'admin/<_c>/<_a>/*' => 'admin/<_c>/<_a>',
'gii/<_c>/<_a>/*' => 'gii/<_c>/<_a>',
'gii/*' => 'gii/',
'admin/*' => 'admin/',
'site/<_a>/*' => 'site/<_a>',
'<link:[\w\W]+>' => 'content/get',
'/*' => '',
),
),
public function actionGet($link)
{
$url=utf8_encode($_SERVER['REQUEST_URI']);
$model=Categories::model()->findBySql('SELECT * FROM tbl_categories WHERE link=:query',array(':query'=>trim($url)));
if($model!=NULL)
{
$data=Content::model()->findBySql('SELECT * FROM tbl_content WHERE category=:cat',array(':cat'=>$model->id));
$this->render('view',array(
'model'=>$model,
'data'=>$data
));
}
else
{
$model=Content::model()->findBySql('SELECT * FROM tbl_content WHERE link=:query',array(':query'=>trim($url)));
if($model!=NULL)
{
$this->render('view',array(
'model'=>$model,
));
}
else
throw new CHttpException(404,'The requested page does not exist.');
}
}
Answer the question
In order to leave comments, you need to log in
Apparently there is no simpler way, well, it means "and so it will do")))
I think that all old links should be redirected to new places with an adequate structure using htaccess, otherwise you will be tormented later.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question