thanks for ur response,this program, get input datacode from user, and when user click check button, it will return/result single json data, only like {"datacode":"123", "message":"hello","status":"good"}
this my model,
<?php
class Mydata extends CFormModel {
public $data_code;
public $errorcode, $message, $name, $status;
public function rules()
{
return array(
array('data_code','required'),
array('data_code, 'numerical'),
);
}
public function attributeLabels()
{
return array(
);
}
}
?>
my controller,
public function actionData()
{
$model=new Mydata();
// collect user input data
if(isset($_POST['Mydata']))
{
$model->attributes=$_POST['Mydata'];
$data["username"] = "dummy";
$data["password"] = "dummy";
$data["data_code"] = $_POST['Mydata']['data_code'];
$post =CJSON::encode($data);
$url = "http://www.mydata.com";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$output = curl_exec($ch);
curl_close($ch);
if($output!="null")
$obj=CJSON::decode($output, true); //result = Array ( [datacode] => 123 [message]=>hello [name] => tata [status] => good )
$rawData = $obj;
$dataProvider=new CArrayDataProvider($rawData, array(
'sort'=>array(
'attributes'=>array(
'errorcode','message','name','status',
),
),
));
//i tried to show array in indexMydata view
$this->render('indexMydata',array('model'=>$model));
}
// display the mydata form
$this->render('mydataForm',array('model'=>$model));
}
my View (mydataForm)
<div class="form">
<?php $form=$this->beginWidget(‘CActiveForm’, array(
'id'=>'Mydata-form',
'enableClientValidation'=>false,
)); ?>
<div class="row">
<?php echo $form->labelEx($model,'datacode'); ?>
<?php echo $form->textField($model,'datacode'); ?>
<?php echo $form->error($model,'datacode'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton('Check'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
my View (indexMydata)
<?php
$this->widget(‘zii.widgets.grid.CGridView’, array(
'dataProvider'=>$dataProvider,
'columns'=>array(
array(
'name'=>'errorcode',
'value'=>'$data["errorcode"]',
),
array(
'name'=>'message',
'value'=>'$data["message"]',
),
),
));
?>
its now give me an error
PHP notice
Undefined variable: dataProvider
i hope u can help me to solve my problem, must i learn ajax or what??
actually, i still confusing, how to show other view when i click check/submit button…hehe…
thanks a lot…