2014-04-02 60 views
0

在視圖中的一部分,我要檢查,如果$校驗值== true,則打開CJuiDialogYii的查看打開CJuiDialog如果PHP變量爲真

<?php 
if($check==true) 
{ 
    js:function(){$('#dialogDisplay').dialog('open');} 
} 
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(// the dialog 
    'id' => 'dialogDisplay', 
    'options' => array(
     'title' => 'Display Setting', 
     'autoOpen' => false, 
     'modal' => true, 
     'width' => 300, 
     'height' => 200, 
     'buttons' => array(
      array('text' => 'Submit', 'click' => 'js:function(){ document.myform.submit();}'), 
      array('text' => 'Cancel', 'click' => 'js:function(){$(this).dialog("close");}')), 
    ), 
)); 
?> 
<div class="divForForm"> 
    <form name="myform" action="/dataset/resetPageSize" method="post"> 
     Items per page: 
     <select name="filePageSize" class="selectPageSize"> 
      <option value="5">5</option> 
      <option value="10" selected>10</option> 
      <option value="20">20</option> 
      <option value="50">50</option> 
      <option value="100">100</option> 
      <option value="200">200</option>     
     </select> 
     <br> 
     Size: <input type="checkbox" name="size" checked /> 
     <input type="hidden" name="url" value="<? echo Yii::app()->request->requestUri; ?>" /> 

    </form> 

</div>  

<?php $this->endWidget(); ?> 

,但它不工作,我剛開始學習JavaScript,我不知道如何在$檢查==真

回答

1

你需要打印出來的腳本標籤到客戶端運行它:

<?php 
// If PHP variable $check is true 
if($check == true) { 
    // Print out jQuery ready function to the client side, 
    // which will run when the page loads 
    echo "<script>$(function(){ $('#dialogDisplay').dialog('open'); })</script>"; 
}