Yii Framework Forum: Creating First Yii Application - problem - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Creating First Yii Application - problem Rate Topic: -----

#1 User is offline   rabol 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 50
  • Joined: 08-October 08

Posted 08 October 2008 - 01:23 PM

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


0

#2 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,857
  • Joined: 04-October 08
  • Location:DC, USA

Posted 08 October 2008 - 01:59 PM

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

#3 User is offline   rabol 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 50
  • Joined: 08-October 08

Posted 08 October 2008 - 02:18 PM

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);
}


0

#4 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,857
  • Joined: 04-October 08
  • Location:DC, USA

Posted 08 October 2008 - 02:43 PM

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

#5 User is offline   rabol 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 50
  • Joined: 08-October 08

Posted 08 October 2008 - 03:03 PM

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

#6 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,857
  • Joined: 04-October 08
  • Location:DC, USA

Posted 08 October 2008 - 03:16 PM

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;

0

#7 User is offline   rabol 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 50
  • Joined: 08-October 08

Posted 08 October 2008 - 03:56 PM

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.

0

#8 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,857
  • Joined: 04-October 08
  • Location:DC, USA

Posted 08 October 2008 - 04:02 PM

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

#9 User is offline   rabol 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 50
  • Joined: 08-October 08

Posted 08 October 2008 - 04:06 PM

I just figured it out  :)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users