2011-02-16 5 views
-3

관리자 관리 페이지에는 링크가 있습니다. 이 링크를 클릭하면 같은 페이지에서 대화 상자가 열립니다. 대화 상자에는 사용자가 양식을 작성하고 데이터를 저장할 수있는 양식이 있습니다.Yii 프레임 워크 대화 상자

Yii를 사용하면 어떻게 할 수 있습니까?

+0

회신 .plz 경우 당신은 당신의 질문에 훨씬, 훨씬 더 상황 및 세부 실제 오류 메시지를 추가하기 시작해야합니다. –

답변

1

우선이 유형의 질문은 본질적으로 매우 주관적입니다. 그러나 여전히, 나는 대답하려고 노력할 것이다.

"관리 관리"페이지에서 사용자가 (하나의) 링크를 클릭하면 연락처 양식이있는 대화 상자가 열립니다. 이것은 많은 유효한 것의 아무 것나 하나를 사용하여 행해질 수있다 jQuery Modal Box plugins. 모든 양식에 필요한 HTMLINPUT 마크 업 태그를 지원하는 특정 종류의 플러그인을 검색하십시오.

다음은 연락처 양식 데이터를 저장하는 & 양식을 제출하는 것입니다. 따라서 "method"(값은 "post"&이 아닌 "get"이되어야 함) 특성을 가진 FORM 태그가 필요하므로 양식을 제출하는 것은 매우 쉽습니다. "get"을 사용하면 모든 데이터가 쿼리 문자열 형식으로 서버에 전달되어 데이터를 모두 열어 볼 수있게 만듭니다. 대신 "post"을 사용하면 누구도 볼 수 없게 데이터가 제출됩니다. 또한이 양식은 "jQuery"s ""submit() "방법 또는 다른 적절한 방법 (INPUT 태그 사용과 같은)을 사용하여 제출해야합니다.

데이터를 데이터베이스에 저장하는 것에 대해서는 Larry Ullman으로 작성된 Yii 기사 시리즈를 읽는 것이 가장 좋습니다. 특히 당신이 사용할 수있는 일련의 사이에 다음과 같은 기사가 필요합니다 : - Creating Models, Views, and Controllers in Yii

0

완벽한 솔루션은 우리가 모델 우리가 admin.hp 페이지에 링크 버튼을 사용하여 새 클라이언트를 추가 할 '클라이언트'가 예를 들어 여기

입니다 1 단계 : client.php에서 변경 actioncreate 모델을 만들고이 코드로 대체하십시오. 2 단계

public function actionCreate() 
{ 
    $model=new client; 




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

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


     if($model->save()) 
     { 
      if (Yii::app()->request->isAjaxRequest) 
      { 
       echo CJSON::encode(array(
        'status'=>'success', 
        'div'=>"Client successfully added" 
        )); 
       exit;    
      } 
      else 
       $this->redirect(array('view','id'=>$model->id)); 
     } 
    } 

    if (Yii::app()->request->isAjaxRequest) 
    { 
     echo CJSON::encode(array(
      'status'=>'failure', 
      'div'=>$this->renderPartial('_form', array('model'=>$model), true))); 

     exit;    
    } 
    else 
     $this->render('create',array('model'=>$model,)); 
} 

:

는 다음과 admin.php의 모든 코드를 대체,하지만 난 client..you 자신의 모델을 사용한다 모델을 사용하고 있습니다주의하십시오. / /@var $ 모델 클라이언트 */

/* 
$this->breadcrumbs=array(
'Clients'=>array('index'), 
'Manage', 
); 
*/ 
$this->menu=array(
array('label'=>'List client', 'url'=>array('index')), 
//array('label'=>'Create client', 'url'=>array('create')), 
); 
?> 
<h1>Manage Clients</h1> 
<div> 

<?php echo CHtml::link('Add Client ', "", // the link for open dialog 
array(
    'style'=>'cursor: pointer; font-size:20px; text-decoration: underline;', 
    'onclick'=>"{addclient(); $('#dialogclient').dialog('open');}")); 
    ?> 
    </div><!-- add-form --> 
    <?php 
    $this->beginWidget('zii.widgets.jui.CJuiDialog', array(// the dialog 
    'id'=>'dialogclient', 
    'options'=>array(
    'title'=>'Create Client ', 
    'autoOpen'=>false, 
    'modal'=>true, 
    'width'=>550, 
    'height'=>470, 
    ), 
    )); 
    ?> 
    <div class="divForForm"></div> 
    <?php $this->endWidget();?> 
    <?php $this->widget('zii.widgets.grid.CGridView', array(
     'id'=>'client-grid', 
     'dataProvider'=>$model->search(), 
     //'filter'=>$model, 
     'columns'=>array(
    'id', 
    'Client Name', 
    'first_name', 
    'last_name', 
    'email_address', 
    'created_date', 
    array(
     'class'=>'CButtonColumn', 
    ), 
    ), 
    )); 
    ?> 



    <script type="text/javascript"> 
    // here is the magic 
    function addclient() 
    { 
    <?php echo CHtml::ajax(array(
     'url'=>array('client/create'), 
     'data'=> "js:$(this).serialize()", 
     'type'=>'post', 
     'dataType'=>'json', 
     'success'=>"function(data) 
     { 
      if (data.status == 'failure') 
      { 
       $('#dialogclient div.divForForm').html(data.div); 
         // Here is the trick: on submit-> once again this function! 
       $('#dialogclient div.divForForm form').submit(addclient); 
      } 
      else 
      { 
       $('#dialogclient div.divForForm').html(data.div); 
       setTimeout(\"$('#dialogclient').dialog('close') \",3000); 
      } 

     } ", 
     )) 
    ?>; 
     return false; 

    } 

     </script> 

면 어떤 문제가

관련 문제