Php 通过引导模式渲染视图

Php 通过引导模式渲染视图,php,jquery,twitter-bootstrap,yii,Php,Jquery,Twitter Bootstrap,Yii,我需要使用引导模式来加载表单,如何通过链接调用带参数的引导模式 视图: 所以用上面的代码形式也是用验证的,问题是如果我需要添加动态参数链接怎么办? 例如:通过更新功能在CRGidview中使用它,那么$product\u id将针对数据库中与值相关的每一行进行更改。我不知道您是否已经找到了解决方案,但下面是我将如何做的: 在链接中添加一个类似“data productId”的参数(例如:CHtml::link('Addaction','#myModal',array('id'=>'link','

我需要使用引导模式来加载表单,如何通过链接调用带参数的引导模式

视图:

所以用上面的代码形式也是用验证的,问题是如果我需要添加动态参数链接怎么办?
例如:通过更新功能在CRGidview中使用它,那么$product\u id将针对数据库中与值相关的每一行进行更改。

我不知道您是否已经找到了解决方案,但下面是我将如何做的:

在链接中添加一个类似“data productId”的参数(例如:
CHtml::link('Addaction','#myModal',array('id'=>'link','data-toggle'=>'modal','data-productId'=>$id',class'=>'link')

将javascript函数绑定到链接上的单击事件,如下所示:

$("a#link").click(function()
{
   var productId = $(this).data('productId');

   //you can change the value of a form component like this
   //in the below example I have a hidden input field whose val I want to change to be submitted with the form
   $("input#FormId_idHiddenInput").val(productId);

   $('#myModal').modal('show');
}); 
对于本例,您必须将表单从部分文件移动到对话框文件


让我知道这是否有助于您,或者您是否遇到其他问题。

您错过了链接上的“数据目标”属性
public function actionCreate()
    {
    $model=new Actions;
    $productId=intval($_GET['productId']);

    // Uncomment the following line if AJAX validation is needed
    $this->performAjaxValidation($model);

    if(isset($_POST['Actions']))
    {
        $model->attributes=$_POST['Actions'];

        $model->product_id=$productId;
        if($model->validate()){
            $model->save(false);
            $message=Email::setJavaMessage('success',Yii::t('app','sm'),Yii::t('app','actionWasAdded'));
            echo CJSON::encode(array('status' => 'success','message'=>$message));
            Yii::app()->end();
        }else{
            $error = CActiveForm::validate($model);
            if($error!='[]')
                echo $error;
            Yii::app()->end();
        }
    }
    if(Yii::app()->request->getIsAjaxRequest())
        echo $this->renderPartial('_form',array('model'=>$model,'productId'=>$productId),false,true);//This will bring out the view along with its script.

    else
        $this->render('create',array(
                'model'=>$model,'productId'=>$productId));
}
$("a#link").click(function()
{
   var productId = $(this).data('productId');

   //you can change the value of a form component like this
   //in the below example I have a hidden input field whose val I want to change to be submitted with the form
   $("input#FormId_idHiddenInput").val(productId);

   $('#myModal').modal('show');
});