douyi3632 2014-07-29 10:22
浏览 23
已采纳

Yii渲染CJuiDialog内部的模型视图

I want to render a Model view completely in the CJuiDialog box.

what i did is i have a model JOB for this i have view files that are generated by Gii.

what i want- when clicking on id for each record on index.php i should open CJuiDialog box instead of rendering view file.

But, something going wrong-- when index page is accessed it displays all records for the job model and a pop up CJuiDialog box displaying first record( id=1 record)

and it displaying view for remaining records on the index page.

index.php

<?php
  $this->breadcrumbs=array(
 'Jobs',
);

$this->menu=array(
array('label'=>'Create Jobs','url'=>array('create')),
array('label'=>'Manage Jobs','url'=>array('admin')),
);
?>

<h1>Jobs</h1>

<?php $this->widget('bootstrap.widgets.TbListView',array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
)); ?>

_view.php

<?php 
   $target = 'window.location='."'".$this->createUrl('jobs/index')."'";
 $this->beginWidget('zii.widgets.jui.CJuiDialog', array(
  'id'=>'mydialog',
 // additional javascript options for the dialog plugin
  'options'=>array(
    'title'=>'View Job..',
    'autoOpen'=>true,
  'buttons' => array(
array('text'=>'Route','click'=> 'js:function(){'.$target.'}'),
array('text'=>'Cancel','click'=> 'js:function(){$(this).dialog("close");}'),
),
  'height'=>400,
 'width'=>450,
 'show'=>'fade',
 'hide'=>'fade',
   ),
 ));

    //define the model
  // $model=new Jobs;
 echo 'dialog content here';
 $this->renderPartial('/jobs/view',array('model'=>$data));

 $this->endWidget('zii.widgets.jui.CJuiDialog');

// the link that may open the dialog
 echo CHtml::link('open dialog', '#', array(
'onclick'=>'$("#mydialog").dialog("open"); return false;',
 ));
 ?>

<div class="view">

<b><?php echo CHtml::encode($data->getAttributeLabel('job_id')); ?>:</b>
<?php echo CHtml::link(CHtml::encode($data->job_id),array('view','id'=>$data->job_id)); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('job_code')); ?>:</b>
<?php echo CHtml::encode($data->job_code); ?>
<br />

<b><?php echo CHtml::encode($data->getAttributeLabel('job_title')); ?>:</b>
<?php echo CHtml::encode($data->job_title); ?>
<br />

<b><?php echo CHtml::encode($data->getAttributeLabel('job_desc')); ?>:</b>
<?php echo CHtml::encode($data->job_desc); ?>
<br />

<b><?php echo CHtml::encode($data->getAttributeLabel('job_lastdate')); ?>:</b>
<?php echo CHtml::encode($data->job_lastdate); ?>
<br />

<b><?php echo CHtml::encode($data->getAttributeLabel('job_photo')); ?>:</b>
<?php echo CHtml::encode($data->job_photo); ?>
<br />

<b><?php echo CHtml::encode($data->getAttributeLabel('job_file')); ?>:</b>
<?php echo CHtml::encode($data->job_file); ?>
<br />

<?php /*
<b><?php echo CHtml::encode($data->getAttributeLabel('job_createtime')); ?>:</b>
<?php echo CHtml::encode($data->job_createtime); ?>
<br />

*/ ?>

</div>

view.php

 <h1>View Jobs #<?php echo $model->job_id; ?></h1>

 <?php $this->widget('bootstrap.widgets.TbDetailView',array(
'data'=>$model,
'attributes'=>array(
    'job_id',
    'job_code',
    'job_title',
    'job_desc',
    'job_lastdate',
    'job_photo',
    'job_file',
    'job_createtime',
),
)); ?>

controller actionView()

 public function actionView($id)
 {

    $this->render('view',array(
        'model'=>$this->loadModel($id),
    ));
 }

I didn't getting whats wrong in my code. help me to solve this problem.. Thank You..

  • 写回答

1条回答 默认 最新

  • duanke1984 2014-07-30 17:43
    关注

    Assuming I understood your problem there are a couple problems with your widget declaration.

    1.Your id is not unique for every ui widget on the screen. Change 'id' => 'mydialog' to something like "dialog_{$data->id}". Make sure to change the onclick jQuery id to match that id.

    2.You have autoOpen set to true. Set it to false.

    Also. You're echoing the 'dialog content here' in every dialog :) .

    Cheers

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi