Creating First Yii Application - problem

Hi,

I have just made a new svn checkout and is trying to follow the guide on how to create a Yii application:

Setup: Win Vista 64bit, xampp v1.6.7

virtual host name: http://yiitest

webroot: c:/www/yiitest/public/

framework installed at c:/www/yiitest/framework/

I have created the application using the yiic tool

I have created a sqlite 3 db using Sqlit Administrator (http://sqliteadmin.orbmu2k.de/)

Added the User table

modified the /protected/config/main.php like this:



// This is the main Web application configuration. Any writable


// application properties can be configured here.


return array(


	'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',


	'name'=>'My Web Application',


	'defaultController'=>'site',





	// autoloading model classes


	'import'=>array(


		'application.models.*',


	),





	// application components


	'components'=>array(


		'user' =>array(


			'class'=>'application.components.WebUser',


			'allowAutoLogin'=>true,


			'loginUrl'=>array('user/login'),


		),


		'db'=>array(


			'class'=>'CDbConnection',


			'connectionString'=>'sqlite:c:/www/yiitest/public/protected/data/yiitest.db'


		),





	),


);


When I issue the 'model User' command I get this warning:

Warning: you do not have a 'db' database connection as required by Active Record

.

the crud User command give this error:

Error: Table "User" does not have a primary key.

I assume that the error is due to the fact that the application can't connect to the Db as there is a primary key on the User table.

Any hint ?

Br

Steen

If you changed config, you should re-enter yiic shell. Otherwise, the old config would remain in effect.

Also, you should define a primary key for every table if you want to use AR.

What do you mean by I should define a primary key for every table?

(There is a primary key on the user table)

I'm following the guide step by step.

After re-entering the shell and issue the 'model User' command I get a new error/exception:

exception 'CDbException' with message 'CDbConnection failed to open the DB connection: could not find driver' in C:\www\yiitest\framework\db\CDbConnection.php:228

I know for a fact that the db is working as this is working:



$dbh = new PDO('sqlite:C:/www/yiitest/public/protected/data/yiitest.db'); // success





if($dbh)


{


	foreach ($dbh->query('SELECT * FROM User') as $row)


	{


		var_dump($row);


	}


}


else


{


	var_dump($dbh);


}


If you have PK defined, then ignore that error message because it might be because of your previous db connection error.

It's wierd you got "no driver" error because you verified the driver is available. Could you double check your connectionString? Inside CDbConnection, it is using the similar code as you did in your test snippet.

I have doubled checked it and the connection string is correct.

<?php $model = User::model()->find(); var_dump($model); ?>

in views/layouts/main.php is dumping the records.

Somthing else must be wrong as I can't get the CWebLogRoute working…



			'log'	=> array('class' =>'system.core.log.CLogRouter',


            	'routes' => array(


							array('class' => 'system.core.log.CFileLogRoute', 'level' => 'trace, info', 'category'=>'system.*',),


                			array('class' => 'system.core.log.CWebLogRoute', 'level' => 'trace, info', 'category'=>'info,application',),


            					),


           					),





does not work/give any output in the browser.

for the logging, you should preload the log component by configuring it in the app config with



'preload'=>array('log')


Regarding the DB issue, I just re-tested on my side, but still couldn't reproduce it.

Could you try entering the following statements in yiic shell, and see if there's any error?



> $db=Yii::app()->db;


> $db->active=true;


> echo $db->active;


DAMN!!!

When 'you' run xampp, you have 2 different php.ini files, and the one used when in CLI mode did NOT have the pdo_sqlite.dll enabled.

After modifying the php.ini the shell works as expected - SORRY!!

Now, for the preload/log: As soon as i add the "preload" => array("log"),

I get an exception: Property "CFileLogRoute.level" is not defined.

It should be levels and categories. Sorry the guide has the typo. I will fix it. Thanks.

I just figured it out  :)