我是YII框架的新手,我正在尝试创建一个类似于以下的应用程序,当我访问我的索引时,它将我重定向到这个名为management的页面,我必须创建一个包含一些列表选项的新页面必须重定向到那个,但我不太确定如何使用YII。
这是我原来的行动指数:
public function actionIndex()
{
$this->layout = '//layouts/main';
// renders the view file 'protected/views/site/index.php'
// using the default layout 'protected/views/layouts/main.php'
if (Yii::app()->user->isGuest)
{
$this->redirect(Yii::app()->createUrl('site/login'));
}
else
{
$this->redirect(array('management/list'));
//$this->redirect(array('site/HomePage'));
//$this->render('index');
}
}
它将我重定向到管理/列表,我要做的是重定向到新页面而不是管理称为主页,在新页面中有一个管理选项,通过点击它将它带到正确的页面。
这是我的管理文件夹:
这是我的观点:
我做的是: 在网站内我创建了一个名为homepage.php的页面,其中包含以下主体:
<div class="static_page">
<?php
/* @var $this SiteController */
$this->pageTitle=Yii::app()->name;
?>
<h2>Welcome to <?php echo CHtml::encode(Yii::app()->name); ?></h2>
<p>Congratulations! You have successfully created your Yii application.</p>
<p>You may change the content of this page by modifying the following two files:</p>
<ul>
<li>View file: <code><?php echo __FILE__; ?></code></li>
<li>Layout file: <code><?php echo $this->getLayoutFile('main'); ?></code></li>
</ul>
<p>For more details on how to further develop this application, please read
the <a href="http://www.yiiframework.com/doc/">documentation</a>.
Feel free to ask in the <a href="http://www.yiiframework.com/forum/">forum</a>,
should you have any questions.</p>
</div>
然后我更改了我的actionIndex()
,并将以下内容添加到else部分:
$this->redirect(array('site/HomePage'));
但是当我跑步时,我看到了这个错误:
The system is unable to find the requested action "HomePage".
/vagrant/vendor/yiisoft/yii/framework/web/CController.php(483)
471 return $this->createActionFromMap($map,$actionID,$requestActionID,$config);
472 }
473
474 /**
475 * Handles the request whose action is not recognized.
476 * This method is invoked when the controller cannot find the requested action.
477 * The default implementation simply throws an exception.
478 * @param string $actionID the missing action name
479 * @throws CHttpException whenever this method is invoked
480 */
481 public function missingAction($actionID)
482 {
483 throw new CHttpException(404,Yii::t('yii','The system is unable to find the requested action "{action}".',
484 array('{action}'=>$actionID==''?$this->defaultAction:$actionID)));
485 }
486
487 /**
488 * @return CAction the action currently being executed, null if no active action.
489 */
490 public function getAction()
491 {
492 return $this->_action;
493 }
494
495 /**
// specify how many levels of call stack should be shown in each log message
15 defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);
16
17 require_once($yii);
18
19 Yii::createWebApplication($config)->run();
20
21 echo 'temporary add records to the rbac tables';
22
23 //TODO create temporarily the RBAC settings
24 $auth=Yii::app()->authManager;
如何添加新的homepage.php而不是管理页面?
编辑新版本: 所以我就是这样做的: 我创建了一个名为homepage.php的新页面,其中包含我的views \ site。然后我打开主页并添加以下内容:
<div class="static_page">
<?php
/* @var $this SiteController */
$this->pageTitle=Yii::app()->name;
?>
<h2>Welcome to <?php echo CHtml::encode(Yii::app()->name); ?></h2>
<p>You may change the page by clicking on the following pages.</p>
<ul>
<li>For Dossier Management click on: <code><a href="dossiermanagement/list"> dossiers </a></code></li>
<li>For Management Information click on: <code> Management Info</code></li>
<li>For System Management click on: <code> systemBeheer</code></li>
</ul>
<!-- <p>For more details on how to further develop this application, please read
the <a href="http://www.yiiframework.com/doc/">documentation</a>.
Feel free to ask in the <a href="http://www.yiiframework.com/forum/">forum</a>,
should you have any questions.</p> -->
</div>
并将我的actionIndex
更改为$this->render('HomePage');
它可以工作,但现在我的重定向不起作用了:
例如这部分完全不正确
<li>For Dossier Management click on: <code><a href="dossiermanagement/list"> dossiers </a></code></li>
<li>For Management Information click on: <code> Management Info</code></li>
我该如何解决这个问题?
答案 0 :(得分:1)
请不要重定向到其他任何地方,请加载视图
$this->render('yourview/index',array(
'dataProvider'=>$dataProvider,
'list_arr'=>$this->list
));
在视图文件夹中创建名为 yourview 的文件夹。即使您想将其重定向到管理控制器,也请确保您拥有名称中的控制器。
答案 1 :(得分:0)
请写下此代码代替“$ this-&gt; redirect(array('management / list'));”
$list=array('David','Tristup');
$selected_value='';
$this->render('yourview/index',
array('list_arr'=>$list,'selected_value'=>$selected_value
));
现在您在yourview / index.php中编写此代码。这里make_id是字段名称相应的更改。
<?php
//echo $selected_value;
echo CHtml::dropDownList('make_id',$selected_value,$list_arr,array('empty' => 'Select a Make','class'=>'drop_class'));
?>
现在您可以看到我们名字的下拉列表。如果您有任何问题,请与我们联系。