CGridView in 3rd. party application.

Hello to everyone! I’m trying to implement CGridView in my website which only uses Yii framework without creating Yii application.

So here is the content of 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();



This code works without any errors. The only problem is that it only outputs “Total 10 result(s).” and that’s it. I can’t see the grid.

I checked in html and this is what I got:




<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>



I guess I’m missing something important here. Please help!

CGridView requires that you define the ‘columns’ array.

I have tryed that. It does not helped.

This is what worked for me:




$grid = new CGridView();

$grid->dataProvider = $dataProvider;

$grid->init();

$grid->run();



I have to init columns for the grid before executing run()