1
0

Configured URLManager for use with Program-View-URLs

This commit is contained in:
2014-05-28 11:26:17 +02:00
parent 98fb0f1cec
commit 07c59e0b63
4 changed files with 108 additions and 38 deletions

View File

@@ -67,7 +67,7 @@ class ProgramHelper {
if (is_null($row))
$progDropDown[] = TbHtml::menuDivider();
else
$progDropDown[] = array('label' => $row->attributes['Name'], 'url' => '/programs/' . $row->attributes['Name']);
$progDropDown[] = array('label' => $row->attributes['Name'], 'url' => '/programs/view/' . $row->attributes['Name']);
}
return $progDropDown;
}

View File

@@ -65,8 +65,11 @@ return ArrayX::merge(
'rules' =>
[
'programs/' => 'programs/index',
'downloads/<action:\w+>' => 'programs/<action>', // Compatibility
'programs/view/<id>' => 'programs/view',
'downloads/details.php' => 'programs/index', // Compatibility
'downloads/downloads.php' => 'programs/index', // Compatibility
'downloads/<id>' => 'programs/view', // Compatibility
'' => 'site/index',

View File

@@ -50,8 +50,17 @@ class ProgramsController extends Controller
*/
public function actionView($id)
{
if (is_string($id))
{
$model = $this->loadModelByName($id);
}
else
{
$model = $this->loadModelByID($id);
}
$this->render('view',array(
'model'=>$this->loadModel($id),
'model'=>$model,
));
}
@@ -156,7 +165,7 @@ class ProgramsController extends Controller
* @return Program the loaded model
* @throws CHttpException
*/
public function loadModel($id)
public function loadModelByID($id)
{
$model=Program::model()->findByPk($id);
if ($model===null) {
@@ -165,6 +174,22 @@ class ProgramsController extends Controller
return $model;
}
/**
* Returns the data model based on the name of Program
* If the data model is not found, an HTTP exception will be raised.
* @param string $name the ID of the model to be loaded
* @return Program the loaded model
* @throws CHttpException
*/
public function loadModelByName($name)
{
$model=Program::model()->findByAttributes(['Name' => $name]);
if ($model===null) {
throw new CHttpException(404,'The requested page does not exist.');
}
return $model;
}
/**
* Performs the AJAX validation.
* @param Program $model the model to be validated