Hi i am new to yiiframework.
I am trying to create model for my table from mysql
But it has given me the error like this:
Call to a member function getDb() on non object in ModelCommand.php
I also load pdo and pdo_mysql driver.
In main.php the code is:
return array( 'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..', 'name'=>'My Web Application', // autoloading model and component classes 'import'=>array( 'application.models.*', 'application.components.*', 'system.web.*', 'system.db.*', ), // application components 'components'=>array( 'user'=>array( // enable cookie-based authentication 'allowAutoLogin'=>true, ), // uncomment the following to set up database 'db'=>array( 'connectionString'=>'mysql:host=localhost;dbname=sale', 'username'=>'root', 'password'=>'', ), ), );
Then I do the following things
I try to create small application demo like testdrive.
I create folder WebRoot .then I create testdrive application through command webapp.
Then I go from command line
cd WebRoot/testdrive/Protected
and type
yiic shell yiic.bat
and then
Yii Interactive Tool v1.0
Please type 'help' for help. Type 'exit' to quit.
>> model Product product
first Time I try this command :
C:\Program Files\EasyPhp2.0b1\www\YiiRoot\framework\WebRoot\testdrive\Proteced>yiic shell yiic.bat
Then I try this command:
C:\Program Files\EasyPhp2.0b1\www\YiiRoot\framework>yiic shell WebRoot/testdrive/index.php
Then i get following error in command prompt:
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> <title>
PHP Error</title> <style type="text/css">
/*<![CDATA[*/
body {font-family:"Verdana";font-weight:normal;color:black;background-color:white;}
h1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red } h2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
h3 {font-family:"Verdana";font-weight:bold;font-size:11pt}
p {font-family:"Verdana";font-size:9pt;}
pre {font-family:"Lucida Console";font-size:10pt;} .version {color: gray;font-size:8pt;border-top:1px solid #aaaaaa;} .message {color: maroon;}
.source {font-family:"Lucida Console";font-weight:normal;background-color:#ffffee;}
.error {background-color: #ffeeee;} /*]]>*/ </style> </head> <body>
<h1>PHP Error</h1> <h3>Description</h3>
<p class="message">
Illegal offset type in isset or empty</p> <h3>Source File</h3>
<p> C:Program FilesEasyPHP 2.0b1wwwYiiRootframeworkYiiBase.php(175)</p> <div class="source">
<pre>00163: * the class file 'web/CController.php' when needed. 00164: *
00165: * The same alias can be imported multiple times, but only the first time is effective.
00166: * 00167: * @param string path alias to be imported 00168: * @param boolean whether to include the class file immediately. If false, the class file 00169: * will be included only when the class is being used. 00170: * @return string the class name or the directory that this alias refers to 00171: * @throws CException if the alias is invalid 00172: */
00173: public static function import($alias,$forceInclude=false) 00174:
{
<div class="error">00175:
if(isset(self::$_imports[$alias])) // previously imported </div>00176:
return self::$_imports[$alias]; 00177:
00178: if(isset(self::$_coreClasses[$alias]) || ($pos=strrpos($alias,'.'))===false) // a simple class name 00179: {
00180: self::$_imports[$alias]=$alias; 00181: if($forceInclude && !class_exists($alias,false)) 00182: { 00183: if(isset(self::$_coreClasses[$alias])) // a core class 00184: require_once(YII_PATH.self::$_coreClasses[$alias]); 00185: else 00186: require_once($alias.'.php'); 00187: } </pre> </div><!-- end of source --> <h3>Stack Trace</h3>
<div class="callstack"> <pre>
#0 C:Program FilesEasyPHP 2.0b1wwwYiiRootframeworkcollectionsCConfiguration.php(131): import()
#1 C:Program FilesEasyPHP 2.0b1wwwYiiRootframeworkbaseCApplication.php(709): createObject()
#2 C:Program FilesEasyPHP 2.0b1wwwYiiRootframeworkbaseCApplication.php(361): CWebApplication->getComponent()
#3 C:Program FilesEasyPHP 2.0b1wwwYiiRootframeworkclicommandsshellModelCommand.php(92): CWebApplication->getDb()
#4 unknown(0): ModelCommand->generateModel()
#5 C:Program FilesEasyPHP 2.0b1wwwYiiRootframeworkconsoleCConsoleCommand.php(116): call_user_func()
#6 C:Program FilesEasyPHP 2.0b1wwwYiiRootframeworkclicommandsshellModelCommand.php(72): ModelCommand->copyFiles()
#7 C:Program FilesEasyPHP 2.0b1wwwYiiRootframeworkclicommandsShellCommand.php(98): ModelCommand->run()
#8 C:Program FilesEasyPHP 2.0b1wwwYiiRootframeworkclicommandsShellCommand.php(78): ShellCommand->runShell()
#9 C:Program FilesEasyPHP 2.0b1wwwYiiRootframeworkconsoleCConsoleCommandRunner.php(62): ShellCommand->run()
#10 C:Program FilesEasyPHP 2.0b1wwwYiiRootframeworkconsoleCConsoleApplication.php(88): CConsoleCommandRunner->run()
#11 C:Program FilesEasyPHP 2.0b1wwwYiiRootframeworkbaseCApplication.php(146): CConsoleApplication->processRequest()
#12 C:Program FilesEasyPHP 2.0b1wwwYiiRootframeworkyiic.php(30): CConsoleApplication->run()
#13 C:Program FilesEasyPHP 2.0b1wwwYiiRootframeworkyiic(15): require_once() </pre></div>
<!-- end of callstack-->
<div class="version"> 2009-01-05 05:47:35 <a href="http://www.yiiframework.com/">Yii Framework</a>/1.0.0</div> </body> </html>
I trying this in Windows with Mysql.
Please Help me Thanks in advance.