【发布时间】:2016-03-11 14:17:15
【问题描述】:
是否可以在里面放<style>标签和echo?我的场景是我有一个报销表,并且有这个“类型”列,如果类型是“临时报销”,整个表<tr>的文本颜色和字体样式将被更改:
我正在使用 Yii 2.0 php 框架。这是我的代码:
echo GridView::widget([
'dataProvider' => $dataProvider,
//'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'header' => 'Employee ID',
'value' => 'employeeId'
],
[
'header' => 'Identification <br> Number',
'value' => 'IDnumber'
],
[
'header' => 'Employee <br> Name',
'format' => 'html',
'value' => 'fullName'
],
[
'header' => 'Attachment',
'format' => 'html',
'value' => function ($model) {
return !empty($model->attachment) ? Html::img($model->getImageUrl(), ['class' => 'reim-attach']): 'No Attachment';
},
],
[
'attribute' => 'receipt_company',
'header' => 'Merchant',
],
'description',
[
'attribute' => 'date',
'header' => 'Date <br><span style= "color:gray;font-size:8pt;"> (dd-mm-yyyy)</span>',
],
'currency',
[
'attribute' => 'amount',
'format'=>['decimal',2],
'value' => function ($model){
return !empty($model['amount']) ? $model['amount'] : 0.00;
}
],
[
'attribute' => 'exchange_rate',
'header' => 'Exchange <br> Rate',
'format'=>['decimal',2],
'value' => function ($model){
return !empty($model['exchange_rate']) ? $model['exchange_rate'] : 0.00;
}
],
[
'attribute' => 'converted_amount',
'header' => 'Converted <br> Amount',
'format'=>['decimal',2],
'value' => function ($model){
return !empty($model['converted_amount']) ? $model['converted_amount'] : 0.00;
}
],
[
'attribute' => 'chargeable',
'header' => 'Chargeable to <br> Client',
'value' => function ($model) {
return $model['chargeable'] ? 'Chargeable' : 'Non-chargeable';
},
],
[
'attribute' => 'date_noted',
'header' => 'Date Modified <br><span style= "color:gray;font-size:8pt;"> (dd-mm-yyyy)</span>',
],
[
'attribute' => 'status',
'label' => 'Status',
'content' => function ($model, $key, $index, $column) {
if ($model['status'] == "Pending") {
return Html::button('Pending', ['class' => 'status-pending']);
} elseif ($model['status'] == "Draft") {
return Html::button('Draft', ['class' => 'status-draft']);
} elseif ($model['status'] == "Approved") {
return Html::button('Approved', ['class' => 'status-approved']);
} elseif ($model['status'] == "Rejected") {
return Html::button('Rejected', ['class' => 'status-rejected']);
} elseif ($model['status'] == "Reimbursed") {
return Html::button('Reimbursed', ['class' => 'status-reimbursed']);
}
}
],
'type',
[
'label' => 'Action',
'content' => function ($model, $key, $index, $column) {
if($model['status'] == "Pending") {
return Html::button('<span class="glyphicon glyphicon-eye-open"></span>', ['value' => Url::to(['view']).'&id=' . (string)$model['_id'], 'class' => 'btn btn-warning btn-view btn-responsive','id' => 'modalButton2', 'data-toggle'=>'tooltip', 'title'=>'View'])
.' '
.Html::button('<i class="fa fa-check-circle-o"></i> Approve', ['value' => $model['_id'], 'class' => 'btn btn-info btn-responsive', 'onclick'=>'approve(value)', 'data-toggle'=>'tooltip','title'=>'Approve'])
.' '
.Html::button('<i class="fa fa-ban"></i> Reject', ['value' => $model['_id'], 'class' => 'btn btn-danger btn-responsive', 'onclick'=>'reject(value)', 'data-toggle'=>'tooltip','title'=>'Reject']);
} elseif ($model['status'] == "Draft") {
return Html::button('<span class="glyphicon glyphicon-eye-open"></span>', ['value' => Url::to(['view']).'&id=' . (string)$model->_id, 'class' => 'btn btn-warning btn-view btn-responsive','id' => 'modalButton2', 'data-toggle'=>'tooltip', 'title'=>'View'])
.' '
. Html::button('<span class="glyphicon glyphicon-pencil"></span>', ['value' => Url::to(['update']).'&id=' . (string)$model->_id, 'class' => 'btn btn-success btn-view btn-responsive','id' => 'modalButton3', 'data-toggle'=>'tooltip', 'title'=>'Update'])
.' '
. Html::a('<span class="glyphicon glyphicon-remove"></span>', ['delete', 'id' => (string)$model->_id], ['class' => 'btn btn-danger btn-responsive','data-toggle'=>'tooltip', 'title'=>'Delete', 'data' => ['confirm' => 'Are you sure you want to delete this reimbursement?', 'method' => 'post']]);
} elseif ($model['status'] == "Approved") {
if ($model->type == 'Ad Hoc Reimbursement') {
return Html::button('<span class="glyphicon glyphicon-eye-open"></span>', ['value' => Url::to(['view']).'&id=' . (string)$model['_id'], 'class' => 'btn btn-warning btn-view btn-responsive','id' => 'modalButton2', 'data-toggle'=>'tooltip', 'title'=>'View'])
.' '
.Html::button('<i class="fa fa-check-square-o"></i> Reimburse', ['value' => $model['_id'], 'class' => 'btn btn-info btn-responsive', 'onclick'=>'reimburse(value)', 'data-toggle'=>'tooltip','title'=>'Reimburse']);
} else {
return Html::button('<span class="glyphicon glyphicon-eye-open"></span>', ['value' => Url::to(['view']).'&id=' . (string)$model['_id'], 'class' => 'btn btn-warning btn-view btn-responsive','id' => 'modalButton2', 'data-toggle'=>'tooltip', 'title'=>'View'])
.' '
.Html::button('<i class="fa fa-check-circle-o"></i> Approve', ['value' => $model['_id'], 'class' => 'btn btn-default btn-responsive disable', 'onclick'=>'approve(value)', 'data-toggle'=>'tooltip', 'disabled' => true, 'title'=>'Approve'])
.' '
.Html::button('<i class="fa fa-ban"></i> Reject', ['value' => $model['_id'], 'class' => 'btn btn-default btn-responsive disable', 'onclick'=>'reject(value)', 'data-toggle'=>'tooltip', 'disabled' => true, 'title'=>'Reject']);
}
} else {
if ($model->type == 'Ad Hoc Reimbursement') {
echo "<style>.table-striped > tbody > tr { font-style: italic !important;color: #259A5A !important; }</style>";
return Html::button('<span class="glyphicon glyphicon-eye-open"></span>', ['value' => Url::to(['view']).'&id=' . (string)$model['_id'], 'class' => 'btn btn-warning btn-view btn-responsive','id' => 'modalButton2', 'data-toggle'=>'tooltip', 'title'=>'View'])
.' '
.Html::button('<i class="fa fa-check-square-o"></i> Reimburse', ['value' => $model['_id'], 'class' => 'btn btn-default btn-responsive disable', 'onclick'=>'reimburse(value)', 'disabled' => true, 'data-toggle'=>'tooltip','title'=>'Reimburse']);
} else {
return Html::button('<span class="glyphicon glyphicon-eye-open"></span>', ['value' => Url::to(['view']).'&id=' . (string)$model['_id'], 'class' => 'btn btn-warning btn-view btn-responsive','id' => 'modalButton2', 'data-toggle'=>'tooltip', 'title'=>'View'])
.' '
.Html::button('<i class="fa fa-check-circle-o"></i> Approve', ['value' => $model['_id'], 'class' => 'btn btn-default btn-responsive disable', 'onclick'=>'approve(value)', 'data-toggle'=>'tooltip', 'disabled' => true, 'title'=>'Approve'])
.' '
.Html::button('<i class="fa fa-ban"></i> Reject', ['value' => $model['_id'], 'class' => 'btn btn-default btn-responsive disable', 'onclick'=>'reject(value)', 'data-toggle'=>'tooltip', 'disabled' => true, 'title'=>'Reject']);
}
}
}
]
],
]);
在最后一部分,你可以看到if ($model->type == 'Ad Hoc Reimbursement'),在里面我放了echo "<style>.table-striped > tbody > tr { font-style: italic !important;color: #259A5A !important; }</style>";,我认为这是不对的,因为它不起作用。
您对此有什么想法吗?
【问题讨论】:
-
我认为您的风格不正确或被覆盖。尝试使用该页面打开 chrome 开发人员工具并创建该样式值以查看它是否真的影响任何内容。玩弄直到你能得到那种效果,复制那种风格,然后在你的代码中回显有效的东西。也尝试将它放在返回的字符串的末尾。