Yii Framework Forum: Issues with console command. - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Issues with console command. Issues with console command Rate Topic: -----

#1 User is offline   YIINewBy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 41
  • Joined: 11-September 09
  • Location:Pretoria, South Africa

Posted 15 April 2010 - 08:55 AM

I'm struggling with creating a simple console command. I created a new command class under protected/commands called sendEmail.php

sendEmail.php looks as follows

class sendEmailCommand extends CConsoleCommand{
    public function run($args){
        $arg1 = $args[0];
        $arg2 = $args[1];
        echo "Thanks for $arg1 and $arg2";
    }
    
    public function getHelp(){ 
        return 'Usage: <toNumber> <Message>'; 
    }
}


Now in /protected/config/console.php I have the following

return array(
	'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
	'name'=>'Email Application',
        
        // preloading 'log' component
	'preload'=>array('log'),

	// autoloading model and component classes
	'import'=>array(
		'application.models.*',
		'application.components.*',
	),
        
    
	// application components
	'components'=>array(
		'user'=>array(
			// enable cookie-based authentication
			'allowAutoLogin'=>true,
		),
		'db'=>array(
			'connectionString'=>'mysql:host=localhost;dbname=test',
                        'username'=>'asd',
                        'password'=>'sadasdas',
			'emulatePrepare'=>true,
		),
                'authManager'=>array(
                        'class'=>'CPhpAuthManager',
                ),
		'errorHandler'=>array(
			// use 'site/error' action to display errors
                    'errorAction'=>'site/error',
                ),
	        
               
	),
        'commandMap'=>array(
            'sendemail'=>array(
                'class'=>'sendEmail',
            ),
        
        ),

);



If I run the following command from the CLI within the protected folder
./yiic sendemail


I get the following error
./yiic sendemail e we
exception 'CException' with message 'sendEmail does not have a method named "run".' in .../base/CComponent.php:237
Stack trace:


I really do not know what could be wrong any advise will be appreciated.
0

#2 User is offline   Y!! 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 978
  • Joined: 18-June 09

Posted 15 April 2010 - 10:17 AM

I guess you have to rename the class to sendEmail (instead of sendEmailCommand).
0

#3 User is offline   YIINewBy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 41
  • Joined: 11-September 09
  • Location:Pretoria, South Africa

Posted 15 April 2010 - 03:02 PM

View PostY!!, on 15 April 2010 - 10:17 AM, said:

I guess you have to rename the class to sendEmail (instead of sendEmailCommand).



What I though but in the documentation the Command needs to be included for any console commands?
0

#4 User is offline   Y!! 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 978
  • Joined: 18-June 09

Posted 15 April 2010 - 03:09 PM

View PostYIINewBy, on 15 April 2010 - 03:02 PM, said:

What I though but in the documentation the Command needs to be included for any console commands?


Ok I thought this may not be the case if you use commandMap. Well rename the file to sendMailCommand.php and modify config accordingly. That's the correct convention anyway.
2

#5 User is offline   YIINewBy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 41
  • Joined: 11-September 09
  • Location:Pretoria, South Africa

Posted 16 April 2010 - 02:15 AM

View PostY!!, on 15 April 2010 - 03:09 PM, said:

Ok I thought this may not be the case if you use commandMap. Well rename the file to sendMailCommand.php and modify config accordingly. That's the correct convention anyway.


Thanks, this worked :-) After changing it to sendMailCommand.php it worked, thanx for the tip. SOLVED

www.techportal.co.za
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

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