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 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)