I am using the code below display a grid in Yii.
The grid though displays all rows from the AuthItem table, ignoring the where clause.
Can anyone please help? Thanks.
public function actionGrid_data()
{
$grid = new GridConnector(AuthItem::model(), "PHPYii");
$config = new GridConfiguration();
$config->setHeader("Name,Description");
$config->setInitWidths('150,*');
$config->setColTypes("ro,ro");
$grid->set_config($config);
$grid->render_sql("select id, description from AuthItem where type=2","id","name,description");
}
Sorry there is an error in the code I posted (I was experimenting), this is the code that behaves like I described:
$grid = new GridConnector(Role::model(), “PHPYii”);
$config = new GridConfiguration();
$config->setHeader("Name,Description");
$config->setInitWidths('150,*');
$config->setColTypes("ro,ro");
$grid->set_config($config);
$grid->render_sql("select name, description from AuthItem where type=2","id","name,description");
OK, this actually works, although it does not use Yii database connection and model: so basically when using “PHPYii” as the type of connection, the SQL statement in render_sql is totally ignored; it should be better to have an error message.
Question then, is there a way to specify an SQL statement AND using “PHPYii” ?
$res=mysql_connect("localhost","root","root");
mysql_select_db("448695_foundation");
$grid = new GridConnector($res, "MySQL");
// $grid = new GridConnector(Role::model(), "PHPYii");
$config = new GridConfiguration();
$config->setHeader("Name,Description");
$config->setInitWidths('150,*');
$config->setColTypes("ro,ro");
$grid->set_config($config);
$grid->render_sql("select name, description from AuthItem where type=2","id","name,description");
When you are using PHPYii - grid will fetch data from model, and will ignore any details or render-sql. You can fallback to “MySQL” data driver - in such case connector will work directly with DB and will be able to use all rules of render_sql
Thanks Stanislav, I thought so.
This though is far from ideal and I hope that future releases of PHPYii will allow using specific Yii constructs as createCommand($sql)->queryAll().
Get a guaranteed answer from DHTMLX technical support team
under the most suitable support plan