PHP two modules exclude eachother - php

On my site I have panel control and some content. Site is build on Yii framework.
panel menu:
<?php
$this->breadcrumbs=array(
'Muzyka media'=>array('admin'),
'Lista',
);
$this->renderPartial('_submenu',array('model'=>$model));
?>
and content:
<?php
$this->widget('bootstrap.widgets.TbGridView',array(
'id'=>'muzyka-media-grid',
'type'=>'stripped bordered condensed',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'name',
array(
'name'=>'mime_type',
'value'=>array($this,'displayMediaContent'),
'type'=>'raw',
'htmlOptions'=>array('class'=>'span3'),
'filter'=>CHtml::listData(MuzykaMedia::model()->findAll(),'mime_type','mime_type'),
),
'file_extension',
array(
'name'=>'file_size',
'filter'=>false
),
'count_views',
array(
'class'=>'bootstrap.widgets.TbButtonColumn',
),
),
));
?>
Both parts work separately but for some reason I can't see, when put one after another the sub-menu doesn't render.

Your code is definitely Yii1.1. If you're rendering partial views from inside another view, as you seem to be doing here, then you need to echo the result, so your code should look like this;
<?php
$this->breadcrumbs=array(
'Muzyka media'=>array('admin'),
'Lista',
);
echo $this->renderPartial('_submenu',array('model'=>$model));
?>

Related

How to get the checkbox to appear in entire column PHP Yii1.1

I am trying to make the checkbox appear in the entire column of my view. However, I am a little lost as to the 'value' of said column. As of right now, I have no clue what I need to enter to make the checkbox appear in the entire column at all.
Any help or advice is appreciated. Below is the code I have written so far.
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'ServiceDataProvider',
'dataProvider'=>$model->search(),
'cssFile' => false,
'filter'=>$model,
'columns'=>array(
array(
'header'=>'Affected Groups',
'value'=>'displayGroupName($data->groups)',
'name'=>'groups.description',
'filter'=>CHtml::textField('groups.description', Yii::app()->request->getParam('groups.description'))
),
array(
'header'=>'Affected Hosts',
'value'=>'displayHostName($data->hosts)',
'name'=>'hosts.hostname',
'filter'=>CHtml::textField('hosts.hostname', Yii::app()->request->getParam('hosts.hostname'))
),
array(
'name'=>'servicedescription',
),
array(
'class'=>'CButtonColumn',
'template'=>'{delete}',
'deleteButtonUrl'=>'Yii::app()->createUrl("path/to/delete",
array("id"=>$data["idservice"]))',
),
array(
'value'=>'', // AND this is the part where I have no clue what to do.
'id'=>'selectServices',
'header'=>'<input id="services_all" type="checkbox" title="Select multiple services to dele" data-toggle="tooltip"/>',
'headerHtmlOptions'=>array(
'class'=>'checkbox-column'
),
),
),
));
Thanks for your help, fellas. I really appreciate it.
Never mind. It's probably still early or something.
This is how I solved it with version Yii 1.1.21:
array(
'value'=>'$data->idservice',
'class'=>'CCheckBoxColumn',
'id'=>'selectServices',
'headerTemplate'=>'{item}',
'selectableRows'=>'2',
),

Yii CGridView update

So I gave up on all of the above and decided to move the colums I wanted to show with ajax in a different grid in the main grid but for some reason i get this error:
Trying to get property of non-object
/var/www/html/framework/base/CComponent.php(607) : eval()'d code(1)
<?php
$this->breadcrumbs=array(
'Fund Admin'=>array('/FundAdmin/index/'),
'Contract Notes'=>array('index'),
'List',
);
$user = Yii::app()->user;
$this->menu=array(
array('label'=>'Fund Prices', 'url'=>array('/FundPrice/index'), 'visible'=>$user->checkAccess('listFPrice')),
array('label'=>'Reports','url'=>array('/FundAdmin/index'), 'visible'=>$user->checkAccess('listReports')),
array('label'=>'Create Contract Note', 'url'=>array('create'), 'visible'=>$user->checkAccess('createCNote')),
array('label'=>'Audit Contract Note', 'url'=>array('auditList'), 'visible'=>$user->checkAccess('auditListClient')),
//array('label'=>'Audit Contract Note Item', 'url'=>array('/ContractNoteItem/auditList'), 'visible'=>$user->checkAccess('auditListClient')),
);
Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
$('.search-form').toggle();
return false;
});
$('.search-form form').submit(function(){
$.fn.yiiGridView.update('contract-note-grid',{
data: $(this).serialize()
});
return false;
});
");
?>
<h1>List Contract Note</h1>
<p>
You may optionally enter a comparison operator (<b><</b>, <b><=</b>, <b>></b>, <b>>=</b>, <b><></b>
or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.
</p>
<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
'model'=>$model,
)); ?>
</div><!-- search-form -->
<?php
//$data=NULL;
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'contract-note-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
array(
'name'=>'cn_fund_house_id',
'type'=>'raw',
'value'=>'$data->cnFundHouse->fh_name',
),
array(
'name'=>'contractNoteItems.cni_fund_id',
'type'=>'raw',
'value'=>'$data->contractNoteItems->f_name',
),
array(
'name'=>'contractNoteItems.cni_isin',
'type'=>'raw',
'value'=>'$data->contractNoteItems->cni_isin',
),
array(
'name'=>'contractNoteItems.cni_client_account_no',
'type'=>'raw',
'value'=>'$data->contractNoteItems->cni_client_account_no',
),
'cn_investment_date',
//'cn_settlement_date',
array(
'class'=>'CButtonColumn',
'deleteConfirmation'=>'Are you sure you want to retire this item?
This item needs to be audited for retirement to take effect.',
'template'=>'{view}{update}{delete}',
'buttons'=>array(
'view' => array
(
'label'=>'view',
'url'=>'Yii::app()->controller->createUrl("contractNoteItem/view",array("id"=>$data->getCNIid($data->id)))',
'visible'=>"Yii::app()->user->checkAccess('editFund')",
),
'update' => array
(
'label'=>'edit',
'url'=>'Yii::app()->controller->createUrl("edit",array("id"=>$data["id"]))',
'visible'=>"Yii::app()->user->checkAccess('editFund')",
),
'delete' => array
(
'label'=>'retire',
'url'=>'Yii::app()->controller->createUrl("retire",array("id"=>$data["id"]))',
'visible'=>'$data->checkIfRetired($data["id"])',
)
)
),
),
));
?>
And the particular error comes to the )); right before the php closing tag so I do not understand. If I comment the 'value' for each of the arrays except the first one and the CButtonColumn arrays I don't get the error because I just don't populate the fields with data. So I don't really get why it does this because everything in the models are defined right.
Also note that when I upload the file to my live server I do not get the error but the colums does not show for these colums:
array(
'name'=>'contractNoteItems.cni_fund_id',
'type'=>'raw',
'value'=>'$data->contractNoteItems->f_name',
),
array(
'name'=>'contractNoteItems.cni_isin',
'type'=>'raw',
'value'=>'$data->contractNoteItems->cni_isin',
),
array(
'name'=>'contractNoteItems.cni_client_account_no',
'type'=>'raw',
'value'=>'$data->contractNoteItems->cni_client_account_no',
),
The live server php is 5.3.27 and on my local server is 5.3.3 so I do not know why I get the error on the local. Anyway my question is about the data there not showing and giving me the error on the local server.
I think you issues is in your button area you have lines like this:
'visible'=>'$data->checkIfRetired($data["id"])',
However $data should be an object not an array. Try changing it to:
'visible'=>'$data->checkIfRetired($data->id)',
In reality though you should need to pass any data to functions like checkIfRetired since it is already an instance. In the function you should just be able to use the value $this->id instead of having to pass it.
The value elements for your columns are the problem. When the value element of a column is not specified, Yii checks whether the object exists before getting the value of the desired attribute. Your value elements do not have this check hence the error.
For simplicity in your code, there is no need to add the value and type elements for some columns. As such your code becomes
'columns'=>array(
...
'contractNoteItems.cni_fund_id',
'contractNoteItems.cni_isin',
'contractNoteItems.cni_client_account_no',
...
)
For more information, see CGridView.columns

To change the value of parameter in CGridView using Yii

I a have a basic question about CGridViews. I have the table employees stored in my DB and I am showing some of his atributs using this CGridView. The problem is that I stored all the passwords using the md5 codification, and when I want to show them I don't know how to show them without the md5 codification.
I tried it with the sentence: "'password'=>$dataProvider->employee->md5(password)," But as you can imagine it is wrong and it doesn't work. This is my CGridView with parameter password changed to this sentence.
<?php $this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'id'=>'employee_list',
'columns'=>array(
'id',
'name',
//'password',
'password'=>$dataProvider->employee->md5(password),
array(
'class'=>'CButtonColumn',
),
),
)); ?>
Somebody could help me? Thank you very much.
you just need to pass php code as string, Cgridview will run that string with eval function,
Please refer following code for more clarification:
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$model->search(),
'columns'=>array(
array(
'name'=>'password',
'value'=>'md5($data->password)',
),
),
));
Let say you encoded your password with base64_encode($password) then what you have to do is base64_decode($encoded_password)
from your question, is it $dataProvider->md5(password)?
maybe you can refer the code below.
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'leaveapplication-grid1',
'dataProvider'=>$model->searchpersonalleave($myid),
//'filter'=>$model,
'columns'=>array(
'leave_dateapplied',
'leave_id',
array('name'=>'leave_category','value'=>'$data->getcategoryname($data->leave_category)' ), //0-annual, 1-medical, 2-emergency
'leave_startdate',
//'leave_enddate',
'leave_duration',
'leave_reason',
array(
'class'=>'CButtonColumn',
'template'=>'{view}{update}',
'buttons'=>array
(
'update' => array
(
'visible'=>'($data->getupdatefunction(17) =="Yes")',
),
),
),
),
));

How to get controller name inside CGridView?

In views controller name can be achieved by $this->id, but in CGridView $this->id evaluation results in another name (may be gridview widget name). (1) How can I get controller name in cgridview?
Also I tried to define a variable ($thisCtl = $this->id) before calling CGridview. Although $thisCtl has the controller name, in CGridview evaluation process it is not defined. (2) Is there any way to pass a parameter to CGridView?
<?php
$thisCtl = $this->id;
$data = $model->search();
$this->widget('bootstrap.widgets.TbExtendedGridView', array(
'id'=>'insurance-grid',
'dataProvider'=>$model->search(),
//'filter'=>$model,
'columns'=>array(
'id',
'registeration_date',
'modification_date',
array(
'htmlOptions' => array('nowrap'=>'nowrap'),
'class'=>'bootstrap.widgets.TbButtonColumn',
'viewButtonUrl'=>'Yii::app()->createUrl("$thisCtl/view", array("id"=>$data["id"]))',
'updateButtonUrl'=>'Yii::app()->createUrl("$this->id/update", array("id"=>$data["id"]))',
),
),
));
?>
Since it appears you wish to use the controller value within the column values, you can do the following to get the controller name:
$this->grid->controller->id
As you are within a TbButtonColumn, you can access the grid property (since TbButtonColumn extends from CButtonColumn which in turn extends from CGridColumn) to access the TbExtendsGridView (which ultimately extends from CGridView) where you in turn access the controller property of the grid (which is defined by the widget parent), and finally the get id of the controller.
Then, assuming all your other code is correct, you would specify your gridview like so:
<?php
$data = $model->search();
$this->widget('bootstrap.widgets.TbExtendedGridView', array(
'id'=>'insurance-grid',
'dataProvider'=>$model->search(),
//'filter'=>$model,
'columns'=>array(
'id',
'registeration_date',
'modification_date',
array(
'htmlOptions' => array('nowrap'=>'nowrap'),
'class'=>'bootstrap.widgets.TbButtonColumn',
'viewButtonUrl'=>'Yii::app()->createUrl($this->grid->controller->id."/view", array("id"=>$data["id"]))',
'updateButtonUrl'=>'Yii::app()->createUrl($this->grid->controller->id."/update", array("id"=>$data["id"]))',
),
),
));
I haven't used any of the Tb extensions myself, by so long as they did not alter the built in behavior of the objects they extended, the above should work as desired.
the problem is that $this in CGridView refers to it's widget. So we should use a global function to get current controller name:
Yii::app()->getController()->getId();
the code should look like:
<?php
$thisCtl = $this->id;
$data = $model->search();
$this->widget('bootstrap.widgets.TbExtendedGridView', array(
'id'=>'insurance-grid',
'dataProvider'=>$model->search(),
//'filter'=>$model,
'columns'=>array(
'id',
'registeration_date',
'modification_date',
array(
'htmlOptions' => array('nowrap'=>'nowrap'),
'class'=>'bootstrap.widgets.TbButtonColumn',
'viewButtonUrl'=>'Yii::app()->createUrl("'.Yii::app()->getController()->getId().'/view", array("id"=>$data["id"]))',
'updateButtonUrl'=>'Yii::app()->createUrl("'.Yii::app()->getController()->getId().'/update", array("id"=>$data["id"]))',
),
),
));
?>
Thanks to this post Getting Current Controller ID in Yii

Submit CGridView Checked values using a form

I have a CGridView wigdet with CCheckBoxColumn like this:
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'columns'=>array(
array(
'class'=>'CCheckBoxColumn',
),
'title',
....
),
));
Question: how to submit to controller action the checked values? I understand that I need a form, submit button, but I need a clear explanation where to put things, so that search boxes on the top appear.
Thanks in advance.
You do not absolutely need another form. You can just use a link with additional javascript attached to it.
To get the checked values, you can call the javascript function $.fn.yiiGridView.getChecked(containerID,columnID), see here, it returns an array containing the ids.
Full example (with ajax):
In your view:
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'example-grid-view-id', // the containerID for getChecked
'dataProvider'=>$dataProvider,
'columns'=>array(
array(
'class'=>'CCheckBoxColumn',
'id'=>'example-check-boxes' // the columnID for getChecked
),
'title',
....
),
));
?>
<div id="for-link">
<?php
echo CHtml::ajaxLink('SomeLink',Yii::app->createUrl('somecontroller/someaction'),
array(
'type'=>'POST',
'data'=>'js:{theIds : $.fn.yiiGridView.getChecked("example-grid-view-id","example-check-boxes").toString()}'
// pay special attention to how the data is passed here
)
);
?>
<div>
In your controller:
...
public function actionSomeaction(){
if(isset($_POST['theIds'])){
$arra=explode(',', $_POST['theIds']);
// now do something with the ids in $arra
...
}
...
}
...
You could also use json string, instead of simple string, in the data we pass by ajax (from the view), but then instead of explode(), you would use json_decode() (in the controller). Also it would be better to validate/sanitize the ids before use.
Check out the documentation for CHtml::ajaxLink to know more about ajax links.
Note that the example is a little crude, since i haven't put in checks for empty array of checked ids.
This one works with CSRF protection and updates the GridView.
<?php
echo CHtml::ajaxLink('ClickMe',Yii::app()->createUrl('controller/action'),
array(
'type'=>'POST',
'data'=>'js:{"ids" : $.fn.yiiGridView.getChecked("grid_view_id","check_box_id").toString(),"YII_CSRF_TOKEN" : "'.Yii::app()->request->csrfToken.'"}',
'success'=>"$('#grid_view_id').yiiGridView.update('grid_view_id')"
));
?>
If you wrap your Gridview into a simple form you can send the checkboxs selected to the value,
An example:
View
<form id="frmSubmit">
<?php
echo CHtml::dropDownList('user_id'
, null
, CHtml::listData(User::model()->findAll(), 'USER_ID', 'FULLNAME')
);
echo CHtml::ajaxSubmitButton('Save'
, Yii::app()->createUrl('query/ajaxUpdate')
, array('success' => 'js:reloadGrid', )
, array('class' => 'btn btn-success'));
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'query-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
array(
'id' => 'query',
'class'=>'CCheckBoxColumn',
'selectableRows' => '2',
),
'Contact',
'Email',
'Company',
),
)); ?>
</form>
<script type="text/javascript">
function reloadGrid(data) {
$.fn.yiiGridView.update('query-grid');
}
</script>
Controller
public function actionAjaxUpdate()
{
var_dump($_POST);
}

Categories