I want to capture javascript/PHP variable in the ajaxoptions' options. e.g;
CHtml::ajaxLink("My link", Yii::app()->createUrl('controller/definition'), array(
'data' => array("id" => $model->id),
'type' => 'POST',
'error' => 'js:function(data){}',
'beforeSend' => 'js:function(request){}',
'success' => 'js:function(data){
alert(jQuery(this).attr("id"));
alert({$model->id});
}',
'complete' => 'js:function(data){}',
//'update'=>'#where_to_put_the_response',
), array(
"confirm" => "Are you sure you want to delete?",
"id" => "linkID",
"href" => "javascript:;",
"title" => "mTitle"
)
);
In the success option I have two alerts to show you guyz how do i want it. Which doesn't display correct data. Is there any way to get the php variables and the jQuery(this) object?
I have extracted the data i wanted from "jQuery(this)". Actually "jQuery(this)" returned me the data in a different format. Below is the code.
CHtml::ajaxLink("My link", Yii::app()->createUrl('controller/definition'), array(
'data' => array("id" => $model->id),
'type' => 'POST',
'error' => 'js:function(data){}',
'beforeSend' => 'js:function(request){
mdata=(jQuery(this)[0]["data"]).replace( /^\D+/g, "");
}',
'success' => 'js:function(data){
alert(mdata);
}',
'complete' => 'js:function(data){alert(mdata);}',
//'update'=>'#where_to_put_the_response',
), array(
"confirm" => "Are you sure you want to delete?",
"id" => "linkID",
"href" => "javascript:;",
"title" => "mTitle"
)
);
if alert the "jQuery(this)" like alert(JSON.stringify(jQuery(this))); - you will get the idea of the data returned.
Related
I am partially updating the document using the following structure
$params = [
'index' => self::$currentIndex[self::INDEX_TYPE_SEARCH],
'type' => self::TYPE_PRODUCT,
'id' => $product_id,
'body' => [
'script' => 'ctx._source.coupons += coupon',
'params' => ['coupon' => array($product_body)],
]
];
However I am getting the following error:
remote_transport_exception:
[Gee][127.0.0.1:9300][indices:data/write/update[s]]
Any idea if the structure is incorrect?
If you wan't to add values to an array than you can do this,
$params['id'] = $product_id;
$params['body'] = array(
'script' => array(
"inline" => "ctx._source.coupons.add(params.coupon)",
"lang" => "painless",
"params" => ['coupon' => array($product_body)]
)
);
This thould work as it worked for me.
$options = array(
'UserData' => base64_encode('test'),
'SecurityGroupIds' => [AWS_REGIONS[$region]['security_group']],
'InstanceType' => AWS_REGIONS[$region]['instance_type'],
'ImageId' => AWS_REGIONS[$region]['ami'],
'MaxCount' => $to_launch,
'MinCount' => 1,
//'EbsOptimized' => true,
'SubnetId' => AWS_REGIONS[$region]['subnet_id'],
'Tags' => [['Key' => 'task', 'Value' => $task],['Key' => 'Name', 'Value' => $task]],
'InstanceInitiatedShutdownBehavior' => 'terminate'
);
$response = $client->runInstances($options);
I am using the "latest" Ec2Client
It launches fine but the Tags are completely ignored.
I suspect an error within the EC2 API but I am not that experienced.
Maybe someone with experience can help me out ?
This is because Ec2Client::runInstances does not have tags option
http://docs.aws.amazon.com/aws-sdk-php/v3/api/api-ec2-2015-10-01.html#runinstances
You would need to make a separate call to tag newly created instance(s) using Ec2Client::createTags:
$result = $client->createTags(array(
'DryRun' => true || false,
// Resources is required
'Resources' => array('string', ... ),
// Tags is required
'Tags' => array(
array(
'Key' => 'string',
'Value' => 'string',
),
// ... repeated
),
));
Read more here:
http://docs.aws.amazon.com/aws-sdk-php/v3/api/api-ec2-2015-10-01.html#createtags
I am trying to display a CGridView in a CJuiDialog but facing some problems.
In my view, I create a menu item as follow :
$this->menu = array(
array('label' => Yii::t('app', 'Afficher les participants ayant fourni cette information'),
'url' => array('Participant/ShowParticipantInfo', 'id' => $model->id_info),
'linkOptions' => array(
//'onclick' => "{viewP(); $('#dialogViewP').dialog('open'); return false}",
'ajax' => array(
'type' => 'POST',
'url' =>"js:$(this).attr('href')", //array('Participant/ShowParticipantInfo', 'id' => $model->id_info),
'update' => '#divForForm2',
),
),
);
Then I've created the dialog :
<?php $this->beginWidget('zii.widgets.jui.CJuiDialog', array(
'id' => 'dialogViewP',
'options' => array(
'title' => 'Liste des participants ayant fourni cette information',
'autoOpen' => false,
'modal' => true,
'width' => 500,
'height' => 300,
),
));
?>
<div id="divForForm2"></div>
<?php $this->endWidget('dialogViewP'); ?>
And my controller looks like this one :
public function actionShowParticipantInfo($id){
$rows = Participant::findParticipantInfo($id);
$result = array();
foreach ($rows AS $key => $val){
$result[] = array('id' => $key +1, 'value' => $val['NomComplet']);
}
$arrayDataProvider = new CArrayDataProvider($result, array(
'id' => 'id',
'pagination' => array(
'pageSize' => 10,
),
));
if(Yii::app()->request->isAjaxRequest){
$this->renderPartial('_showparticipant', array(
'arrayDataProvider' => $arrayDataProvider,
), false, true);
echo CHtml::script('$("#dialogViewP").dialog("open")');
Yii::app()->end();
}
}
But but clicking on the menu item, there is any dialog diplayed. I cannot know why. Can somebody help me ?
I think there should not be both 'url' and 'linkOption' attributes in an menu item. Either one.
Thru web dev tools you need to check if you have ajax XHR upon menu item click.
I'd recommend you this extention if you want to realize an ajax manu.
Even if you initiate ajax request the response cannot activate hidden dialog because on success you ONLY update certain div #divForForm2 but the dialog window is still closed: 'autoOpen' => false. I'd recommend incorporate opening dialog upon ajax success.
'ajax' => array(
'type' => 'POST',
'url' => array('Participant/ShowParticipantInfo', 'id' => $model->id_info),
'success' =>'js:{function(data){$("#divForForm2").html(data); $("#dialogViewP").dialog("open");}'
),
This code actually doesn't draw nothing but the title
It's uses Highcharts like an yii extension
<?php $this->Widget('ext.highcharts.HighchartsWidget', array(
'options'=>array(
'title' => array('text' => 'Grafico a torta'),
'chart' => array('renderTo' =>'charts'),
'credits' => array('enabled' => false),
'series' => array (
'type' => 'pie',
'name' => 'name of serie',
'data' => array (
array('Firefox', 44.2),
array('IE7', 26.6),
array('IE6', 20),
array('Chrome', 3.1),
array('Other', 5.4)
),
),
)
));
?>
It create this javascript
jQuery(window).on('load',function() {
var chart = new Highcharts.Chart(
{'chart':{'renderTo':'charts'},
'exporting':{'enabled':true},
'title':{'text':'Grafico a torta'},
'credits':{'enabled':false},
'series':{
'type':'pie',
'name':'name of serie',
'data':[
['Firefox',44.2000000000000028],
['IE7',26.6000000000000014],
['IE6',20],
['Chrome',3.1000000000000001],
['Other',5.4000000000000004]
]}});
});
I'm not able to understand whats wrong.... no js error was throwed, not console debug info, nothing ....
What I'm missing ?
Check your serie:
series:**[**{
type:'pie',
name:'name of serie',
data:[
['Firefox',44.2000000000000028],
['IE7',26.6000000000000014],
['IE6',20],
['Chrome',3.1000000000000001],
['Other',5.4000000000000004]
]}**]**
});
You are missing [] in series. Check this: http://jsfiddle.net/tqVF8/9/
use array once more for series
section =>
'series' => array (
array (
'type' => 'pie',
'name' => 'Browser share',
'data' => array (
array('Firefox', 44.2),
array('IE7', 26.6),
array('IE6', 20),
array('Chrome', 3.1),
array('Other', 5.4)
),
),
),
it works with me.
in this data is array of count of number of event.
<?php
$this->Widget('application.extensions.highcharts.HighchartsWidget',
array('options'=>array( 'title'=>array('text'=>'User Distribution'),
'tooltip'=>array('formatter'=> 'js:function() {
return "<b>"+this.point.name+"</b>: "+Math.round(this.percentage)+"%"
}'),
'credits' => array('enabled' => true),
'exporting' => array('enabled' => true),
'plotOptions'=>array('pie'=> array('allowPointSelect'=>true,'cursor'=>'pointer',
'dataLabels'=>array('enabled'=>true),
'showInLegend'=>true)
),
'series' => array(array('type'=>'pie', 'name'=>'User Distrubution',
'data' => $data,)
)
)
)
);
?>
I've created a custom node type in Drupal 7, using the hook_node_info method in the install file:
// declare the new node type
function foo_node_info ( ) {
return array(
'foo' => array(
'name' => t('Foo entry'),
'base' => 'node_content',
'description' => t('For use to store foo entries.'),
));
} // END function foo_node_info
and I'm trying to save that type in the module file using the following code:
// INSERT the stuff
node_save(node_submit((object)array(
'type' => 'foo',
'is_new' => true,
'uid' => 1,
'title' => 'Title, blah blah blah',
'url' => 'url here, just pretend',
'body' => '<p>test</p>',
)));
My issue, is that the url, and body fields aren't saving. Any idea what I'm doing wrong?
So, after a ton of digging, it turns out that the way I was entering the custom fields in the node_save was wrong. The node_save needs to look like the following:
node_save(node_submit((object)array(
'type' => 'foo',
'is_new' => true,
'uid' => 1,
'title' => 'the title',
'url' => array(
'und' => array(array(
'summary' => '',
'value' => 'url value',
'format' => 2,
))),
'body' => array(
'und' => array(array(
'summary' => '',
'value' => 'the body goes here',
'format' => 2,
))),
)));
Notice that for the custom fields, the array structure has to match what was previously going on with CCK (pretty much exactly). The first key in the array describing the field value is the language for the content.
I've used 'und' here only because that's what I saw going into the database when entering the data through a form.