Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php CGridView设置特定列的样式,插入<;部门>;内部<;td>;元素_Php_Css_Yii_Zii Widgets - Fatal编程技术网

Php CGridView设置特定列的样式,插入<;部门>;内部<;td>;元素

Php CGridView设置特定列的样式,插入<;部门>;内部<;td>;元素,php,css,yii,zii-widgets,Php,Css,Yii,Zii Widgets,我正在尝试将自定义样式应用于由CGridView生成的特定列。我需要在元素内部插入,但我不知道怎么做 以下是查看文件: <div id="shortcodes" class="page"> <div class="container"> <!-- Title Page --> <div class="row"> <div class="span12">

我正在尝试将自定义样式应用于由CGridView生成的特定列。我需要在元素内部插入,但我不知道怎么做

以下是查看文件:

<div id="shortcodes" class="page">
    <div class="container">
        <!-- Title Page -->
        <div class="row">
            <div class="span12">
                <div class="title-page">
                    <h2 class="title">Available Products</h2>

                </div>
            </div>
        </div>
        <!-- End Title Page -->
        <!-- Start Product Section -->
        <div class="row">
            <?php
            $this->widget('bootstrap.widgets.TbGridView', array(
                'id' => 'products-grid',
                'dataProvider' => $dataProvider,
                'ajaxUpdate' => TRUE,
                'pager' => array(
                    'header' => '',
                    'cssFile' => false,
                    'maxButtonCount' => 25,
                    'selectedPageCssClass' => 'active',
                    'hiddenPageCssClass' => 'disabled',
                    'firstPageCssClass' => 'previous',
                    'lastPageCssClass' => 'next',
                    'firstPageLabel' => '<<',
                    'lastPageLabel' => '>>',
                    'prevPageLabel' => '<',
                    'nextPageLabel' => '>',
                ),
                'columns' => array(
                    'id',
                    'name',
                    'category',
                    'brand',
                    'weight_unit',
                    'price_unit',
                    'flavors',
                    array(
                        'name' => 'providers',
                        'htmlOptions' => array('class' => 'label label-info'),
                    ),
                ),
            ));
            ?>
        </div>
        <!-- End Product Section -->
    </div>
</div>

可用产品
因此,我想为名为“providers”的列设置样式。使用htmlOptions确实会将类添加到td列中,但列的对齐方式不合适。这就是为什么我想将其包装在
中,以应用正确的对齐和样式

现在看起来是这样的:

<tr class="even">
    <td>414</td>
    <td>Owl Book</td>
    <td>Night Owl Trance</td>
    <td>Binaural Beats</td>
    <td> 400 Grams</td>
    <td>$569.66</td>
    <td>Ether</td>
    <td class="label label-info">Shrooms.com</td>
</tr>

414
猫头鹰书
夜猫子出神
双耳节拍
400克
$569.66
乙醚
Shrooms.com
我想做的是:

<tr class="even">
    <td>414</td>
    <td>Owl Book</td>
    <td>Night Owl Trance</td>
    <td>Binaural Beats</td>
    <td> 400 Grams</td>
    <td>$569.66</td>
    <td>Ether</td>
    <td><div class="label label-info">Shrooms.com</div></td>
</tr>

414
猫头鹰书
夜猫子出神
双耳节拍
400克
$569.66
乙醚
Shrooms.com

那么,我该怎么做呢?有选择吗?据我所知,htmlOptions只会向元素添加属性。

未经测试,但我认为您可以使用类似的方法

'flavors',
    array(
        'name' => 'providers',
        'value' => "<div class=label label-info>$data->providers</div>"
        ),
“口味”,
排列(
“名称”=>“提供程序”,
'value'=>“$data->providers”
),

好的,我首先尝试了redGREENblue的答案,但我给出了一个未定义的变量:data 'value'=>''.$data->providers'

在Yii论坛上提出一些建议后,我找到了解决方案。基本上,我所做的是从函数闭包中返回值,它起作用了

工作代码::

<div id="shortcodes" class="page">
<div class="container">

    <!-- Title Page -->
    <div class="row">
        <div class="span12">
            <div class="title-page">
                <h2 class="title">Available Products</h2>

            </div>
        </div>
    </div>
    <!-- End Title Page -->



    <!-- Start Product Section -->
    <div class="row">


        <?php


        $this->widget('bootstrap.widgets.TbGridView', array(
            'id' => 'products-grid',
            'dataProvider' => $dataProvider,
            'filter' => $dataProvider->model,
            'ajaxUpdate' => TRUE,
            'pager' => array(
                'header' => '',
                'cssFile' => false,
                'maxButtonCount' => 25,
                'selectedPageCssClass' => 'active',
                'hiddenPageCssClass' => 'disabled',
                'firstPageCssClass' => 'previous',
                'lastPageCssClass' => 'next',
                'firstPageLabel' => '<<',
                'lastPageLabel' => '>>',
                'prevPageLabel' => '<',
                'nextPageLabel' => '>',
            ),
            'columns' => array(
                'id',
                'name',
                'category',
                'brand',
                'weight_unit',
                'price_unit',
                'flavors',
                array(
                    'name' => 'providers',
                    'value' => function($data) {         //*the closure that works*
                        return '<div class="label label-info">'.$data->providers.'</div>';
                    },
                    'type' => 'raw',
                ),
            ),
        ));
        ?>

    </div>
    <!-- End Product Section -->


</div>

可用产品

嗨,谢谢你的回答。我试过了,但是我给了我一个未定义的变量:data'value'=>'.$data->providers'.'。所以后来我把这个值放在函数闭包中,它现在就可以工作了。