1
0

Configured URLManager for use with Program-View-URLs

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

View File

@ -63,10 +63,49 @@
</component>
<component name="FileEditorManager">
<leaf>
<file leaf-file-name="about.php" pinned="false" current="true" current-in-tab="true">
<file leaf-file-name="main.php" pinned="false" current="true" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/www/protected/config/main.php">
<provider selected="true" editor-type-id="text-editor">
<state line="69" column="74" selection-start="1485" selection-end="1485" vertical-scroll-proportion="0.4086207" vertical-offset="936" max-vertical-offset="1802">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="ProgramsController.php" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/www/protected/controllers/ProgramsController.php">
<provider selected="true" editor-type-id="text-editor">
<state line="64" column="5" selection-start="1429" selection-end="1429" vertical-scroll-proportion="-16.423077" vertical-offset="661" max-vertical-offset="3434">
<folding>
<element signature="e#1432#1547#0" expanded="false" />
<element signature="e#1941#2118#0" expanded="false" />
</folding>
</state>
</provider>
</entry>
</file>
<file leaf-file-name="main.php" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/www/protected/views/layouts/main.php">
<provider selected="true" editor-type-id="text-editor">
<state line="47" column="96" selection-start="1704" selection-end="1704" vertical-scroll-proportion="-7.6538463" vertical-offset="600" max-vertical-offset="1785">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="ProgramHelper.php" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/www/protected/components/ProgramHelper.php">
<provider selected="true" editor-type-id="text-editor">
<state line="69" column="102" selection-start="1626" selection-end="1626" vertical-scroll-proportion="-16.115385" vertical-offset="754" max-vertical-offset="1360">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="about.php" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/www/protected/views/site/about.php">
<provider selected="true" editor-type-id="text-editor">
<state line="26" column="78" selection-start="790" selection-end="790" vertical-scroll-proportion="0.762069" vertical-offset="0" max-vertical-offset="1530">
<state line="26" column="78" selection-start="790" selection-end="790" vertical-scroll-proportion="-17.0" vertical-offset="0" max-vertical-offset="1530">
<folding />
</state>
</provider>
@ -113,17 +152,17 @@
<option value="$PROJECT_DIR$/www/protected/controllers/SiteController.php" />
<option value="$PROJECT_DIR$/framework/logging/CLogger.php" />
<option value="$PROJECT_DIR$/www/protected/models/Program.php" />
<option value="$PROJECT_DIR$/www/protected/controllers/ProgramsController.php" />
<option value="$PROJECT_DIR$/www/protected/config/main.php" />
<option value="$PROJECT_DIR$/www/protected/views/site/index.php" />
<option value="$PROJECT_DIR$/www/protected/views/layouts/main.php" />
<option value="$PROJECT_DIR$/www/protected/components/ProgramHelper.php" />
<option value="$PROJECT_DIR$/www/protected/views/programs/admin.php" />
<option value="$PROJECT_DIR$/www/protected/views/programs/create.php" />
<option value="$PROJECT_DIR$/www/protected/views/programs/index.php" />
<option value="$PROJECT_DIR$/www/protected/views/programs/update.php" />
<option value="$PROJECT_DIR$/www/protected/views/programs/view.php" />
<option value="$PROJECT_DIR$/www/protected/views/site/about.php" />
<option value="$PROJECT_DIR$/www/protected/components/ProgramHelper.php" />
<option value="$PROJECT_DIR$/www/protected/controllers/ProgramsController.php" />
<option value="$PROJECT_DIR$/www/protected/config/main.php" />
</list>
</option>
</component>
@ -1074,20 +1113,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/www/protected/controllers/ProgramsController.php">
<provider selected="true" editor-type-id="text-editor">
<state line="2" column="14" selection-start="21" selection-end="21" vertical-scroll-proportion="-1.3076923" vertical-offset="0" max-vertical-offset="3128">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/www/protected/config/main.php">
<provider selected="true" editor-type-id="text-editor">
<state line="68" column="70" selection-start="1506" selection-end="1506" vertical-scroll-proportion="-8.461538" vertical-offset="936" max-vertical-offset="1751">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/www/protected/views/site/index.php">
<provider selected="true" editor-type-id="text-editor">
<state line="42" column="76" selection-start="847" selection-end="847" vertical-scroll-proportion="-9.807693" vertical-offset="459" max-vertical-offset="1564">
@ -1097,20 +1122,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/www/protected/views/layouts/main.php">
<provider selected="true" editor-type-id="text-editor">
<state line="46" column="79" selection-start="1591" selection-end="1591" vertical-scroll-proportion="-7.0" vertical-offset="600" max-vertical-offset="1785">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/www/protected/components/ProgramHelper.php">
<provider selected="true" editor-type-id="text-editor">
<state line="69" column="96" selection-start="1620" selection-end="1620" vertical-scroll-proportion="-14.307693" vertical-offset="801" max-vertical-offset="1360">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/www/protected/views/programs/_form.php">
<provider selected="true" editor-type-id="text-editor">
<state line="1" column="21" selection-start="27" selection-end="27" vertical-scroll-proportion="-0.65384614" vertical-offset="0" max-vertical-offset="1190">
@ -1153,9 +1164,40 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/www/protected/views/layouts/main.php">
<provider selected="true" editor-type-id="text-editor">
<state line="47" column="96" selection-start="1704" selection-end="1704" vertical-scroll-proportion="-7.6538463" vertical-offset="600" max-vertical-offset="1785">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/www/protected/components/ProgramHelper.php">
<provider selected="true" editor-type-id="text-editor">
<state line="69" column="102" selection-start="1626" selection-end="1626" vertical-scroll-proportion="-16.115385" vertical-offset="754" max-vertical-offset="1360">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/www/protected/views/site/about.php">
<provider selected="true" editor-type-id="text-editor">
<state line="26" column="78" selection-start="790" selection-end="790" vertical-scroll-proportion="0.762069" vertical-offset="0" max-vertical-offset="1530">
<state line="26" column="78" selection-start="790" selection-end="790" vertical-scroll-proportion="-17.0" vertical-offset="0" max-vertical-offset="1530">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/www/protected/controllers/ProgramsController.php">
<provider selected="true" editor-type-id="text-editor">
<state line="64" column="5" selection-start="1429" selection-end="1429" vertical-scroll-proportion="-16.423077" vertical-offset="661" max-vertical-offset="3434">
<folding>
<element signature="e#1432#1547#0" expanded="false" />
<element signature="e#1941#2118#0" expanded="false" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/www/protected/config/main.php">
<provider selected="true" editor-type-id="text-editor">
<state line="69" column="74" selection-start="1485" selection-end="1485" vertical-scroll-proportion="0.4086207" vertical-offset="936" max-vertical-offset="1802">
<folding />
</state>
</provider>

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