Yii框架CGridView在第3版。党的申请

时间:2012-07-25 12:14:02

标签: php yii

我正在尝试在我的网站中实现CGridView,它只使用Yii框架而不创建Yii应用程序。

所以这是index.php的内容:

require_once(dirname(__FILE__).'/../framework/yii.php');
$dbConf = array(
        'components'=>array(
                'db'=>array(
                        'connectionString' => 'mysql:host=localhost;dbname=yii_tour',
                        'emulatePrepare' => true,
                        'username' => 'root',
                        'password' => 'root',
                        'charset' => 'utf8',
                ),
        )
);
Yii::createWebApplication($dbConf);
Yii::import('zii.widgets.grid.*');

$message = new Message();
$dataProvider = new CActiveDataProvider($message);

$grid = new CGridView();
$grid->dataProvider = $dataProvider;
$grid->run();

此代码可以正常运行。唯一的问题是它只输出“总共10个结果”。就是这样。我看不到网格。

我检查了html,这就是我得到的:

<div>
        <div class="summary">Total 10 result(s).</div>
        <table class="items">
                <thead>
                        <tr>
                        </tr>
                </thead>
                <tbody>
                        <tr class="odd"></tr>
                        <tr class="even"></tr>
                        <tr class="odd"></tr>
                        <tr class="even"></tr>
                        <tr class="odd"></tr>
                        <tr class="even"></tr>
                        <tr class="odd"></tr>
                        <tr class="even"></tr>
                        <tr class="odd"></tr>
                        <tr class="even"></tr>
                </tbody>
        </table>
        <div class="keys" style="display:none" title="/democms/grid.php"><span>1</span><span>2</span><span>3</span><span>4</span><span>5</span><span>6</span><span>7</span><span>8</span><span>9</span><span>10</span></div>
</div>

我想我错过了一些重要的事情。请帮忙!

1 个答案:

答案 0 :(得分:2)

您必须通过

初始化网格列
$grid = new CGridView();
$grid->dataProvider = $dataProvider;
$grid->init();
$grid->run();