Yii 如何使用下拉菜单重定向?

Yii 如何使用下拉菜单重定向?,yii,Yii,我有一个父页面,有两个子视图_sectionhead.php和_classteacher.php。当用户从dropdwon中选择时,我需要将部分呈现给这些子视图。如何做到这一点 这是我的创作来源 如果有任何其他方式我想知道。我需要快速帮助假设您使用HTML,请在下面的HTML代码中添加 <option onClick="fnCallPage('classteacher')">class teacher</option> <option onClick="fnCal

我有一个父页面,有两个子视图_sectionhead.php和_classteacher.php。当用户从dropdwon中选择时,我需要将部分呈现给这些子视图。如何做到这一点

这是我的创作来源


如果有任何其他方式我想知道。我需要快速帮助

假设您使用HTML,请在下面的HTML代码中添加

<option onClick="fnCallPage('classteacher')">class teacher</option>
<option onClick="fnCallPage('Section')">Section</option> 

假设您使用的是HTML,请在下面的HTML代码中添加

<option onClick="fnCallPage('classteacher')">class teacher</option>
<option onClick="fnCallPage('Section')">Section</option> 

基于@Fraz解决方案:

HTML

    <option onClick="fnCallPage('_classteacher')">class teacher</option>
    <option onClick="fnCallPage('_sectionhead')">Section</option> 

    <div id="divContainerPartial"></div> <!-- View rendered container -->
    function fnCallPage(param){
        $.ajax({
            url: '<?php echo Yii::app()->createUrl('yourModel/renderPageByAjax');?>/' + param,
            type: 'GET',
            success: function(html){
                $('#divContainerPartial').html(html);
            },
            error: function(data){
                alert('Error loading a '+param+' view.');
            }
        });

    }
/**
 * @param $view String : View name to render.
 */
public function actionRenderPageByAjax($view)
{
    $params = array(); // Variables to view.

    $this->renderPartial('//myFolderView/'.$view, array(
        'params' => $params,
    ), false, true);
}

基于@Fraz解决方案:

HTML

    <option onClick="fnCallPage('_classteacher')">class teacher</option>
    <option onClick="fnCallPage('_sectionhead')">Section</option> 

    <div id="divContainerPartial"></div> <!-- View rendered container -->
    function fnCallPage(param){
        $.ajax({
            url: '<?php echo Yii::app()->createUrl('yourModel/renderPageByAjax');?>/' + param,
            type: 'GET',
            success: function(html){
                $('#divContainerPartial').html(html);
            },
            error: function(data){
                alert('Error loading a '+param+' view.');
            }
        });

    }
/**
 * @param $view String : View name to render.
 */
public function actionRenderPageByAjax($view)
{
    $params = array(); // Variables to view.

    $this->renderPartial('//myFolderView/'.$view, array(
        'params' => $params,
    ), false, true);
}

视图中:

<?php Yii::app()->clientScript->registerScript('some-name', "
    $('select').on('change', function (event) {
        var url = $(event.currentTarget).val();
        if (url != 0)
            $.get(url, function (data) {
                $('#result').html(data);
            });
    });", CClientScript::POS_READY) ?>

<?php echo
CHtml::dropDownList("param", "select here", [
    'Select here',
    $this->createUrl('/testing/action1') => "Add class teacher",
    $this->createUrl('/testing/action2') => "Add class techer"
]) ?>
<div id="result"></div>

视图中的

<?php Yii::app()->clientScript->registerScript('some-name', "
    $('select').on('change', function (event) {
        var url = $(event.currentTarget).val();
        if (url != 0)
            $.get(url, function (data) {
                $('#result').html(data);
            });
    });", CClientScript::POS_READY) ?>

<?php echo
CHtml::dropDownList("param", "select here", [
    'Select here',
    $this->createUrl('/testing/action1') => "Add class teacher",
    $this->createUrl('/testing/action2') => "Add class techer"
]) ?>
<div id="result"></div>

我很感激这一点,但我需要从parent create.php中呈现partial _sectionhead.php和_classteacher.php我把dropdwon放在create.phpi中,我很感激这一点,但我需要从parent create.php中呈现partial _sectionhead.php和_classteacher.php,我把dropdwon放在create.php中