1
是否可以將<style>
標記放入echo
?我的情況是,我有報銷的一張桌子和有這種「類型」一欄,其中,如果類型是「特設報銷」,整個表<tr>
的文本顏色和字體樣式將被改變:在php中放置樣式標籤echo
我使用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開發人員工具,並創建該樣式值以查看它是否實際影響任何內容。玩耍,直到你能得到那種效果,複製這種風格,然後迴應你的代碼中的作品。也可以嘗試將它放在返回字符串的末尾。 – DataHerder