I am using CGRidVeiw to list my records from database,
In each records I have an edit and delete button.Everthing is working fn9 other than the delete operation,actually its is showing an error after clicking the delete icon,but its still working.Below is the snap of what it actually look like,
After hitting refresh its not showing the record.
I have my view and contoller as below.
//contoller
public function actionDeleteEmployer() {
$model = new AdminDeleteEmployer();
if (isset($_GET['id'])) {
$id = $_GET['id'];
}
$query = "DELETE FROM user,jobs USING user INNER JOIN jobs ON jobs.user_id = user.id WHERE user.id =$id";
Yii::app()->db->createCommand($query)->queryAll();
$this->redirect('admin/site/ManageEmployers');
}
///view
Manage Employers
<div class="form">
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $model->search(),
'ajaxUpdate'=>false,
// 'filter' => $model,
'columns' => array(
array(
'name' => ' Employer ID',
'type' => 'raw',
'value' => 'CHtml::encode($data->id)',
'htmlOptions' => array('style' => 'width:90px;', 'class' => 'zzz'),
// 'filter'=>'false' /* for hiding filter boxes */
),
array(
'name' => 'Created On',
'type' => 'raw',
'value' => 'CHtml::encode( date("m-d-Y",strtotime($data->created)))',
'htmlOptions' => array('style' => 'width:90px;', 'class' => 'zzz'),
// 'filter'=>'false' /* for hiding filter boxes */
),
array(
'name' => 'Account Name',
'type' => 'raw',
'value' => 'CHtml::encode($data->name)',
'htmlOptions' => array('style' => 'width:90px;', 'class' => 'zzz'),
// 'filter'=>'false' /* for hiding filter boxes */
),
array(
'name' => 'Email',
'type' => 'raw',
'value' => 'CHtml::encode($data->email)',
'htmlOptions' => array('style' => 'width:90px;', 'class' => 'zzz'),
// 'filter'=>'false' /* for hiding filter boxes */
),
array(
'name' => 'Last Active On',
'type' => 'raw',
'value' => 'CHtml::encode( date("m-d-Y",strtotime($data->modified)))',
'htmlOptions' => array('style' => 'width:90px;', 'class' => 'zzz'),
// 'filter'=>'false' /* for hiding filter boxes */
),
array(
'class' => 'CButtonColumn',
'deleteConfirmation' => 'Are you sure you want to delte this item?',
'template' => '{view}{delete}',
'buttons' => array(
'view' => array('label' => 'view',
'url' => 'Yii::app()->controller->createUrl("ViewEmployerActivity",array("id"=>$data["id"]))'),
'delete' => array('label' => 'delete',
'url' => 'Yii::app()->controller->createUrl("DeleteEmployer",array("id"=>$data["id"]))'),
)
)
),
));
?>
</tbody>
</table>
redirect to admin action
Yii::app()->db->createCommand($query)->execute();
$this->redirect(array('admin'))
Related
I have created a Magento Admin Grid and am using Mass Action to set the start and stop dates.
Now my Mass Action runs as chosen in dropdown list select start or stop datepicker box will show after select first box.
Can I show two boxes at same time (dropdown list and datepicker) or select date before dropdown list?
My code:
$this->getMassactionBlock()->addItem('setstartdate', array(
'label' => $this->__('Set Start Date'),
'url' => $this->getUrl('*/*/massSetstartdate', array('' => '')),
'confirm' => $this->__('Are you sure?'),
'additional' => array(
'setstartdate' => array(
'name' => 'setstartdate',
'time' => true,
'input' => 'datetime',
'type' => 'datetime',
'class' => 'required-entry',
'label' => Mage::helper('setcustomdate')->__('Set start Date'),
// 'gmtoffset' => true,
'image' => '/skin/adminhtml/default/default/images/grid-cal.gif',
'format' => 'yyyy-MM-dd H:mm:ss'
)
)
));
$this->getMassactionBlock()->addItem('setstopdate', array(
'label' => $this->__('Set Stop Date'),
'url' => $this->getUrl('*/*/massSetstopdate', array('' => '')),
'confirm' => $this->__('Are you sure?'),
'additional' => array(
'setstopdate' => array(
'name' => 'setstopdate',
'time' => true,
'input' => 'datetime',
'type' => 'datetime',
'class' => 'required-entry',
'label' => Mage::helper('setcustomdate')->__('Set Stop Date'),
// 'gmtoffset' => true,
'image' => '/skin/adminhtml/default/default/images/grid-cal.gif',
'format' => 'yyyy-MM-dd H:mm:ss'
)
)
));
Edit 1 update prepareColumns
protected function _prepareColumns() {
$helper = Mage::helper('setupdate');
$this->addColumn('data_id', array(
'header' => $helper->__('Data No.'),
'index' => 'data_id'
));
$this->addColumn('startdate', array(
'header'=> $helper->__('Start'),// store
'index' => 'startdate',
'filter_index' => 't1.start_date',
'format' => 'F',
'type' => 'datetime',
));
$this->addColumn('stopdate', array(
'header'=> $helper->__('Stop'),// store
'index' => 'stopdate',
'filter_index' => 't1.stop_date',
'format' => 'F',
'type' => 'datetime',
));
return parent::_prepareColumns();
}
I'm trying to set up a new grid view in yii booster while passing a variable through at the start of the view to sort the formatting.
I presume I am not passing the variable properly by this line
$gridColumns = $this->widget('booster.widgets.TbGridView', array(
How would I go about using this variable? I can create a new form array okay not using yiibooster but with the widget activated it no longer likes the variable name
The issue is I'm getting the error in the title of the post.
$gridColumns = $this->widget('booster.widgets.TbGridView', array(
'id' => 'delegate-grid',
'dataProvider' => $model->search(),
'filter' => $model,
'columns' => array(
// 'id',
array(
'name' => 'forename',
'type' => 'raw',
'value' => 'CHtml::link($data->forename, array("user/view", "id" => $data->id))',
),
'surname',
// 'facilities',
// 'telephone',
// 'address_id',
/*
'logo_path',
*/
array(
'class' => 'booster.widgets.TbButtonColumn',
),
),
));
$groupGridColumns = $gridColumns;
$groupGridColumns[] = array(
'name' => 'firstLetter',
'value' => 'substr($data->surname, 0, 1)',
'headerHtmlOptions' => array('style' => 'display:none'),
'htmlOptions' => array('style' => 'display:none')
);
$this->widget('booster.widgets.TbGroupGridView', array(
'id' => 'user-grid',
'type' => 'striped bordered condensed highlight',
//'template' => "{items}",
'dataProvider' => $model->search(),
'filter' => $model,
'extraRowColumns' => array('firstLetter'),
'extraRowExpression' => '"<b style=\"font-size: 3em; color: #333;\">".substr($data->surname, 0, 1)."</b>"',
'extraRowHtmlOptions' => array('style' => 'padding:10px;text-align: center;'),
'columns' => $groupGridColumns,
));
It is because you are giving an object of type CGridView to TbGroupGridView as parameter.
$groupGridColumns = $gridColumns;
You are putting an object of type TbGridView($gridColumns) in $groupGridColumns and then give it to your TbGroupGridView, but TbGroupGridView columns property expects its value be an array of arrays(definition of columns) and so throws new exception when in the first cell of $groupGridColumns find an object.
You do not need the first part and with some changes, your code should work fine with filtering enabled.
$this->widget('booster.widgets.TbGroupGridView', array(
'id' => 'user-grid',
'type' => 'striped bordered condensed highlight',
'dataProvider' => $model->search(),
'filter' => $model,
'extraRowColumns' => array('firstLetter'),
'extraRowExpression' => '"<b style=\"font-size: 3em; color: #333;\">".substr($data->surname, 0, 1)."</b>"',
'extraRowHtmlOptions' => array('style' => 'padding:10px;text-align: center;'),
'columns' => array(
array(
'name' => 'forename',
'type' => 'raw',
'value' => 'CHtml::link($data->forename, array("user/view", "id" => $data->id))',
),
'surname',
array(
'name' => 'firstLetter',
'value' => 'substr($data->surname, 0, 1)',
'headerHtmlOptions' => array('style' => 'display:none'),
'htmlOptions' => array('style' => 'display:none')
)
array(
'class' => 'booster.widgets.TbButtonColumn',
),
)
));
I'm building website using yii 1.1 framework and Clevertech YiiBooster extension.
Is there an easy way to render few "editable field" widgets inside the popover widget ?
Please see the code below. Any suggestions are welcome.
Main view:
....
$this->widget(
'booster.widgets.TbButton', array(
'label' => 'Right popover',
'context' => 'warning',
'buttonType' => 'button',
'size' => 'extra_small',
'htmlOptions' => array(
'id' => uniqid(),
'data-html' => true,
'data-title' => 'A Title',
'data-placement' => 'right',
'data-content' => $this->renderPartial('VIEW', array('data'=>$data), true, true),
'data-toggle' => 'popover'
),
)
);
....
partial view:
$this->widget('booster.widgets.TbEditableField', array(
'type' => 'text',
'model' => $survey,
'attribute' => 'text',
'pk' => 'pk',
'name' => 'name',
'text' => '',
'url' => $this->createUrl('controller/method/'), //url for submit data
'title' => 'text',
'placement' => 'right',
'id' => uniqid()),true);
$this->widget('booster.widgets.TbEditableField', array(
'type' => 'text',
'model' => $survey,
'attribute' => 'text',
'pk' => 'pk',
'name' => 'name',
'text' => '',
'url' => $this->createUrl('controller/method/'), //url for submit data
'title' => 'text',
'placement' => 'right',
'id' => uniqid()),true);
$this->widget('booster.widgets.TbEditableField', array(
'type' => 'text',
'model' => $survey,
'attribute' => 'text',
'pk' => 'pk',
'name' => 'name',
'text' => '',
'url' => $this->createUrl('controller/method/'), //url for submit data
'title' => 'text',
'placement' => 'right',
'id' => uniqid()),true);
Here is my code
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'dsfsd',
'dataProvider' => $model->search(),
'filter' => $model,
'cssFile' => false,
'itemsCssClass' => 'table table-striped',
'beforeAjaxUpdate'=>'js:function(id,options){$.blockUI({
message: "Please wait",
//showOverlay: false,
css: {
border: "none",
padding: "15px",
"-webkit-border-radius": "10px",
"-moz-border-radius": "10px",
opacity: 1,
"z-index": "9999"
}
});}',
'columns' => array(
array(
'header' => '#',
'name' => 'id',
'type' => 'raw',
'value' => 'CHtml::link(CHtml::encode($data->id),array("abc/m/".CHtml::encode($data->id)."/info"))',
'htmlOptions' => array('width' => '40px'),
'filter' => CHtml::activeTextField($model, 'id', array('placeholder' => 'search by id')),
), array(
'header' => 'First name',
'name' => '$data.user.f_name',
'type' => 'raw',
'value' => 'CHtml::encode($data->user->f_name)',
), array(
'header' => 'Last name',
'name' => '$data.user.l_name',
'type' => 'raw',
'value' => 'CHtml::encode($data->user->l_name)'
),
array(
'class' => 'CButtonColumn',
'template' => '{update} {delete}',
//'updateButtonUrl' => 'Yii::app()->createUrl("abc/xyz?id=".$data->id."&c_id=".$data->c_id)',
'deleteButtonUrl' => 'Yii::app()->createUrl("xyv/abc",array("uid"=>$data->id))',
),
),
));
Well, what I want is that the operations under beforeAjaxUpdate will work only when delete button is clicked, not for any other ajax actions like on search or update. How is it possible?
You can add callback function to delete button:
http://www.yiiframework.com/doc/api/1.1/CButtonColumn#buttons-detail
You should set click option in buttons config array:
'columns' => array(
...
'buttons'=>array(
'class'=>'CButtonColumn',
'template'=>'{delete}{update}',
'buttons'=>array(
'delete'=>array(
'click'=>'function(){/*your code here*/}'
)
)
)
...
)
You can return false from callback function to prevent deleting.
I can't list data in grid using yii framework. My controller is Sitecontroller.php, My view is list_jobseeker.php.
I got the error:
Parse error: syntax error, unexpected '*', expecting ']' in C:\wamp\www\yii_new\framework\base\CComponent.php(612) : eval()'d code on line 1
Anybody give any suggestion to correct these issue?
My controller:
public function actionlist_jobseeker()
{
$session_id=Yii::app()->session['user_id'];
if ($session_id == "")
{
$this->redirect( array('/employee/site/login'));
}
$user_id =$session_id;
$items = Yii::app()->db->createCommand()
->select('*')
->from('job_seeker_profile s')
->join('job_profile j','s.user_id = j.user_id')
->order('s.id')
->queryAll();
$this->render('list_jobseeker',array('items' =>$items));
}
My view page - list_jobseeker.php
<h1>View Jobseeker</h1>
<div class="flash-success">
</div>
<div class="form">
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'rates-phase-grid',
'htmlOptions' => array('class' => 'table table-striped table-bordered table-hover'),
'dataProvider'=>new CArrayDataProvider($items),
'columns' => array(
array(
'name' => 'Name',
'type' => 'raw',
'value' => 'CHtml::encode($data[*]->name)',
'htmlOptions' => array('style'=>'width:90px;','class'=>'zzz'),
),
array(
'name' => 'Email',
'type' => 'raw',
'value' => 'CHtml::encode($data[*]->email)',
'htmlOptions' => array('style'=>'width:250px;','class'=>'zzz')
),
array(
'name' => 'Password',
'type' => 'raw',
'value' => 'CHtml::encode($data[*]->password)',
'htmlOptions' => array('style'=>'width:90px;','class'=>'zzz')
),
array(
'name' => 'Contact No',
'type' => 'raw',
'value' => 'CHtml::encode($data[*]->contact_no)',
'htmlOptions' => array('style'=>'width:40px;','class'=>'zzz')
),
array(
'name' => 'Gender',
'type' => 'raw',
'value' => 'CHtml::encode($data[*]->gender)',
'htmlOptions' => array('style'=>'width:40px;','class'=>'zzz')
),
array(
'class' =>'CButtonColumn',
'deleteConfirmation'=>'Are you sure you want to delte this item?',
'template'=>'{update}{delete}',
'buttons' =>array('update'=>array(
'label'=>'edit',
'url'=>'Yii::app()->controller->createUrl("UpdateJob",array("id"=>$data["id"]))',
),
'delete'=>array('label'=>'delete',
'url'=>'Yii::app()->controller->createUrl("DeleteJob",array("id"=>$data["id"]))'),
)
)
),
));
?>
</tbody>
change all the [*]
$data[*]->name
to match columns
$data["name"]