It appears that the links aren't in correct order and I can't figure out why. I have it in other grids, they seem to be fine.
This is what the link shows:
index.php?ajax=gridID&id=180&r=controller/action
when it's suppose to show:
index.php?r=controller/action&id=180
this is my value in gridview:
'value'=>function($data,$row){
if (intval($data->sid) ==$someID){
if($data->accept == "ACCEPTED")
return CHtml::Link("[X]", array("controller/action","id"=>$data->id),
array('confirm' => 'Are you sure?',
'class'=>'stat')
);
}
where grid is suppose to refresh on confirm:
<?php
Yii::app()->clientScript->registerScript('stat', "
$('#gridId a.stat').live('click', function() {
$.fn.yiiGridView.update('gridId', {
type: 'POST',
url: $(this).attr('href'),
success: function() {
$.fn.yiiGridView.update('gridId');
}
});
return false;
});"
);
?>
if you need generate url on "path" format (controller/action/id/180) and without script name you can set urlFormat property in UrlManager to "path" and set showScriptName property to false. Look this and this
in aplication config file:
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false,
)
Related
Helloo....
I have a problem uploading the image in the code igniter.
I use codeigniter as backend.
the code is like this:
public function upload_image_post()
{
if ($_FILES['image']) {
$name = $_FILES['image']['name'];
$this->load->library('upload', array(
'overwrite' => FALSE,
'upload_path' => FCPATH . 'assets/public/image/news',
'max_size' => '2097152',
'allowed_types' => 'png|jpg|gif|jpeg',
));
if (!$this->upload->do_upload('image')) {
return $this->response([
'status' => false,
'message' => 'fail 1'
], 500);
} else {
$upload = $this->upload->data();
return $this->response([
'status' => true,
'message' => 'success',
'data' => $upload,
], 200);
}
} else {
return $this->response([
'status' => false,
'message' => 'fail 2'
], 500);
}
}
When i using it in localhost, it is success to upload image. But when i deploy it, its failed, and show message 'fail 1'
how do I set up upload_path so it can point to any url I want??
If it's uploading on your localhost your logic is probably right.Please try the following see if this helps you.
First of all can you try adding a trailing slash to the path you provided like this assets/public/image/news/
Please check if your upload folder has write permissions set.
Note:
You can check if your directory is writable using this piece of code from this link.
https://forum.codeigniter.com/thread-74330.html
<?php if(is_writable(base_url('assets/public/image/news/'))){
echo 'writable';
}
else { echo (base_url('assets/public/image/news/'). ' ' ."is not writable");} ?>
Check if your htaccess is configured properly. May be any htaccess from the following git repository might work for you if the above points does not work.
https://github.com/tasmanwebsolutions/htaccess_for_codeigniter
I am rendering an ActiveForm dynamically via ajax, however because the form isn't there on page load, the necessary JS files yiiActiveForm.js, yii.validation.js) and the associated validation triggers aren't there when the form is echoed out.
Here is some sample code:
JS:
$('.btn-edit').on('click', function() {
var id = $(this).attr('data-id');
var url = base_url + '/account/editreview/' + id;
$.ajax({
type: 'post',
url: url,
dataType: 'json',
success: function(result) {
$('.popup').html(result.html);
}
});
});
Controller:
public function actionEditReview($id)
{
$return_array = [
'html' => null,
];
$review = $this->findReview($id);
$return_array['html'] = $this->renderPartial('review-popup', [
'review' => $review,
]);
echo json_encode($return_array);
}
View (review-popup.php):
<?php
use yii\widgets\ActiveForm;
?>
<?php $form = ActiveForm::begin([
'id' => 'review-form',
'enableAjaxValidation' => false,
'enableClientValidation' => true,
]); ?>
<?php echo $form->field($review, 'title')->textInput(); ?>
<button type="submit" class="btn-edit" data-id="<?php echo $review->id; ?>">Submit</button>
<?php ActiveForm::end(); ?>
I have read the notes on this page https://yii2-cookbook.readthedocs.io/forms-activeform-js/ but this talks about adding validation to single attributes, and not to an entire form.
Does anyone know how to do this?
I found the solution: use renderAjax() instead of renderPartial() when echoing out the view.
http://www.yiiframework.com/doc-2.0/yii-web-view.html#renderAjax()-detail
Is it possible to update a highcharts chart using the chart.series[i].setData method if the chart has been created by the Yii extension? I have used highcharts before without Yii extension and able to reference my variables once I set the chart up via declared variable var chart = .... I would just like to to able to call the setData methods for a Yii-created highcharts...this is current code for creating chart:
$this->Widget('ext.highcharts.HighchartsWidget', array(
'id' => 'shop_pie',
'options' => array(
'chart' => array(
'backgroundColor' => '#efefef'
),
'colors' => $colors,
'title' => array('text' => 'Shop'),
'plotOptions' => array(
'pie' => array(
'showInLegend' => 'true',
'dataLabels' => array(
'formatter' => 'js:function(){return this.point.y}',
'distance' => -10,
'color' => '#000'
),
),
'series' => $results['series'],
)
));
My ajax call to update the chart:
"$('#city_filter').on('change',function(e) {
$.ajax({
url: ". $quotedUrl . ",
data: { 'cities': e.val },
success: function(data) {
$('#name_span').text(data[0]);
//chart.series[0].setData(data[1]); // THIS IS WHERE I NEED TO BE ABLE TO REFERENCE THE CHART
}
});
});",
Many thanks in advance.
Andy
"$('#city_filter').on('change',function(e) {
$.ajax({
url: ". $quotedUrl . ",
data: { 'cities': e.val },
success: function(data) {
$('#name_span').text(data[0]);
var chart = $('#shop_pie').highcharts();
chart.series[0].setData(data[1]); // THIS IS WHERE I NEED TO BE ABLE TO REFERENCE THE CHART
}
});
});",
referring to
http://api.highcharts.com/highcharts#Series.setData
and example from that article
http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/highcharts/members/series-setdata/
In my view I have this code:
echo $form->select2Row($model, 'Zustelladresse', array(
'asDropDownList' => false,
'options' => array(
'placeholder' => "Zustelladresse",
'width' => '100%',
'closeOnSelect' => true,
'minimumInputLength'=>1,
'initSelection' => "js:function (element, callback) {
var selected_data = new Object;
selected_data.id = '123';
selected_data.text = 'Test';
callback(selected_data);
}",
'ajax' => array(
'url' => Yii::app()->createUrl('address/zustelladresse'),
'dataType' => 'json',
'data' => 'js:function(term,page) { if(term && term.length){ return { zustelladresse: term };} }',
'results' => 'js:function(data,page) { return {results: data}; }',
),
)));
Created html:
Why is created only label and hidden input?
YiiBooster widgets are quite tricky to debug, if anything is wrong they just don't show. If you still need the answer, I successfully displayed a select2 widget with this code:
$form->select2Row($model, 'attribute_name', array(
'data' => array('1'=>'value1,'2'=>'value2'),
'htmlOptions'=>array(
'style' => 'width:600px',
'multiple' => true,
),
'options'=>array('placeholder'=>'Please make a selection'),
));
I'd suggest you to start from this code and add up your options one by one, and see if anything breaks.
I have been looking into select2 and yii and have managed to load data via json request/response.
The issue I'm faced with is when I try to select an entry of the returned data, I can not.
Where am I going wrong ? The data returnd by the action is json formatted as CustomerCode and Name
Widget code in form
$this->widget('bootstrap.widgets.TbSelect2', array(
'asDropDownList' => false,
'name' => 'CustomerCode',
'options' => array(
'placeholder' => 'Type a Customer Code',
'minimumInputLength' => '2',
'width' => '40%',
'ajax' => array(
//'url'=> 'http://api.rottentomatoes.com/api/public/v1.0/movies.json',
'url'=> Yii::app()->getBaseUrl(true).'/customer/SearchCustomer',
'dataType' => 'jsonp',
'data' => 'js: function (term,page) {
return {
term: term, // Add all the query string elements here seperated by ,
page_limit: 10,
};
}',
'results' => 'js: function (data,page) {return {results: data};}',
),
'formatResult' => 'js:function(data){
var markup = data.CustomerCode + " - ";
markup += data.Name;
return markup;
}',
'formatSelection' => 'js: function(data) {
return data.CustomerCode;
}',
)));
code snipped from controller action SearchCustomer
Yii::app()->clientScript->scriptMap['jquery.js'] = false;
$this->renderJSON(Customer::model()->searchByCustomer($term));
renderJSON function from base controller class
protected function renderJSON($data)
{
header('Content-type: application/json');
echo $_GET['callback'] . "(";
echo CJSON::encode($data);
echo ")";
foreach (Yii::app()->log->routes as $route) {
if($route instanceof CWebLogRoute) {
$route->enabled = false; // disable any weblogroutes
}
}
Yii::app()->end();
}
Appreciate any help on this
i try.
change
'dataType' => 'jsonp' to 'dataType' => 'json'
and check json format
https://github.com/ivaynberg/select2/issues/920