Saturday, December 14, 2013

php develop log–yii yiic mirgate

1.error

Error: The migration directory does not exist: user.migrations

 




or

Yii Migration Tool v1.0 (based on Yii v1.1.14)

Creating migration history table "tbl_migration"...done.
Total 2 new migrations to be applied:
m110805_153437_installYiiUser
m110810_162301_userTimestampFix

Apply the above migrations? (yes|no) [no]:y
*** applying m110805_153437_installYiiUser
Exception: Alias "user.UserModule" is invalid. Make sure it points to an existin
g PHP file and the file is readable. (D:\doc\webserver\wwwroot\third\yii\YiiBase
.php:322)
#0 D:\doc\webserver\wwwroot\third\yii\YiiBase.php(196): YiiBase::import('user.Us
erModule'
, true)
#1 D:\doc\webserver\wwwroot\third\yii\base\CModule.php(282): YiiBase::createComp
onent('user.UserModule', 'user', NULL, Array)
#2 D:\doc\webserver\wwwroot\mw2\protected\migrations\m110805_153437_installYiiUs
er.php(10): CModule->getModule('user')
#3 D:\doc\webserver\wwwroot\third\yii\db\CDbMigration.php(53): m110805_153437_in
stallYiiUser->safeUp()
#4 D:\doc\webserver\wwwroot\third\yii\cli\commands\MigrateCommand.php(386): CDbM
igration->up()
#5 D:\doc\webserver\wwwroot\third\yii\cli\commands\MigrateCommand.php(110): Migr
ateCommand->migrateUp('m110805_153437_...')
#6 [internal function]: MigrateCommand->actionUp(Array)
#7 D:\doc\webserver\wwwroot\third\yii\console\CConsoleCommand.php(172): Reflecti
onMethod->invokeArgs(Object(MigrateCommand), Array)
#8 D:\doc\webserver\wwwroot\third\yii\console\CConsoleCommandRunner.php(71): CCo
nsoleCommand->run(Array)
#9 D:\doc\webserver\wwwroot\third\yii\console\CConsoleApplication.php(92): CCons
oleCommandRunner->run(Array)
#10 D:\doc\webserver\wwwroot\third\yii\base\CApplication.php(180): CConsoleAppli
cation->processRequest()
#11 D:\doc\webserver\wwwroot\third\yii\yiic.php(33): CApplication->run()
#12 D:\doc\webserver\wwwroot\mw2\protected\yiic.php(7): require_once('D:\doc\web
serve...'
)
#13 {main}
*** failed to apply m110805_153437_installYiiUser (time: 0.008s)


Migration failed. All later migrations are canceled.
or
Add to console.php :
'modules'=>array(
...
'user'=>array(
... # copy settings from main config
),
...
),

*** failed to apply m110805_153437_installYiiUser (time: 0.005s)

 




2.why


i want to add this plugin: http://www.yiiframework.com/extension/yii-user/ ,


my yii worked path is D:\doc\webserver\wwwroot\mw2\


and mw2 is not generated by cmd: yii webapp D:\doc\webserver\wwwroot\mw2\,it created by manual.


3.fixed


3.1 regenerate it


now i rename mw2,and cmd:

yii webapp D:\doc\webserver\wwwroot\mw2\

 




it generate some files,and override old mw2 files in it.


3.2 unpack


unpack yii-user-0.3-61-gfc69518.zip,and extract all files to D:\doc\webserver\wwwroot\mw2\protected\modules\user\


like it:


image


3.3 modify config file


D:\doc\webserver\wwwroot\mw2\protected\config\ main.php and config.php


main.php:

<?php

include dirname(__FILE__).'/../../config.inc.php';

// This is the main Web application configuration. Any writable
// application properties can be configured here.
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'pkrss v2',

'theme'=>'bootstrap',

// autoloading model and component classes
'import'=>array(
'application.models.*',
'application.components.*',

'application.modules.user.models.*',
'application.modules.user.models.user.*',
'application.modules.user.components.*',

'ext.bootstrap-theme.widgets.*',
'ext.bootstrap-theme.helpers.*',
'ext.bootstrap-theme.behaviors.*',
),

'modules'=>array(
'user'=>array(
# encrypting method (php hash function)
'hash' => 'md5',

# send activation email
'sendActivationMail' => true,

# allow access for non-activated users
'loginNotActiv' => false,

# activate user on registration (only sendActivationMail = false)
'activeAfterRegister' => false,

# automatically login from registration
'autoLogin' => true,

# registration path
'registrationUrl' => array('/user/registration'),

# recovery password path
'recoveryUrl' => array('/user/recovery'),

# login form path
'loginUrl' => array('/user/login'),

# page after login
'returnUrl' => array('/user/profile'),

# page after logout
'returnLogoutUrl' => array('/user/login'),
),

'gii' => array(
'generatorPaths'=>array(
'ext.bootstrap-theme.gii',
),
),
),

// application components
'components'=>array(
'cache'=>array(
'class'=>'system.caching.CDbCache',
'autoCreateCacheTable'=>false,
'cacheTableName'=>PKRSS_DB_TABLEPREFIX . 'yiicache',
'connectionID'=>'db',
),
'db'=>array(
'class'=>'CDbConnection',
'connectionString'=>PKRSS_DB_CONNECTIONSTRING,
'username'=>PKRSS_DB_USERNAME,
'password'=>PKRSS_DB_PASSWORD,
'tablePrefix' => PKRSS_DB_TABLEPREFIX,
'charset' => 'utf8',
'emulatePrepare'=>true, // needed by some MySQL installations
),
'errorHandler'=>array(
// use 'site/error' action to display errors
'errorAction'=>'site/error',
),
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'user/<controller:\w+>/'=>'user/<controller>',
'<subdir:\w+>/<controller:\w+>/<action:\w+>'=>'<subdir>/<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),
'user'=>array(
// enable cookie-based authentication
'class' => 'WebUser',
'allowAutoLogin'=>true,
'loginUrl' => array('/user/login'),
),
'bootstrap'=>array(
'class'=>'bootstrap.components.Bootstrap',
),
),

// application-level parameters that can be accessed
// using Yii::app()->params['paramName']
'params'=>array(
// this is used in contact page
'adminEmail'=> PKRSS_ADMINEMAIL,
),
);

 




console.php:

<?php

include dirname(__FILE__).'/../../config.inc.php';

// This is the configuration for yiic console application.
// Any writable CConsoleApplication properties can be configured here.
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'My Console Application',

// preloading 'log' component
'preload'=>array('log'),


// autoloading model and component classes
'import'=>array(
'application.models.*',
'application.components.*',

'application.modules.user.models.*',
'application.modules.user.components.*',

'ext.bootstrap-theme.widgets.*',
'ext.bootstrap-theme.helpers.*',
'ext.bootstrap-theme.behaviors.*',
),

'modules'=>array(
'user'=>array(
# encrypting method (php hash function)
'hash' => 'md5',

# send activation email
'sendActivationMail' => true,

# allow access for non-activated users
'loginNotActiv' => false,

# activate user on registration (only sendActivationMail = false)
'activeAfterRegister' => false,

# automatically login from registration
'autoLogin' => true,

# registration path
'registrationUrl' => array('/user/registration'),

# recovery password path
'recoveryUrl' => array('/user/recovery'),

# login form path
'loginUrl' => array('/user/login'),

# page after login
'returnUrl' => array('/user/profile'),

# page after logout
'returnLogoutUrl' => array('/user/login'),
),

'gii' => array(
'generatorPaths'=>array(
'ext.bootstrap-theme.gii',
),
),
),
// application components
'components'=>array(
'db'=>array(
'class'=>'CDbConnection',
'connectionString'=>PKRSS_DB_CONNECTIONSTRING,
'username'=>PKRSS_DB_USERNAME,
'password'=>PKRSS_DB_PASSWORD,
'tablePrefix' => PKRSS_DB_TABLEPREFIX,
'charset' => 'utf8',
'emulatePrepare'=>true, // needed by some MySQL installations
),
'user'=>array(
// enable cookie-based authentication
'class' => 'WebUser',
'allowAutoLogin'=>true,
'loginUrl' => array('/user/login'),
),
// uncomment the following to use a MySQL database
/*
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=testdrive',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
),
*/
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
'levels'=>'error, warning',
),
),
),
),
);
config.inc.php
<?php

defined('YII_DEBUG') or define('YII_DEBUG',true);
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);

define('PKRSS_DB_CONNECTIONSTRING','mysql:host=localhost;dbname=sp500ccbd11028f');
define('PKRSS_DB_USERNAME','root');
define('PKRSS_DB_PASSWORD','');

define('PKRSS_DB_TABLEPREFIX','pkrss_');
define('PKRSS_ADMINEMAIL','liandeliang@gmail.com');


define('PKRSS_DB_LOCALE_CACHE_SECONDS',30);

define('PKRSS_CACHE_ENABLED',true);

 






3.3 migrate


then cmd:

D:\doc\webserver\wwwroot\mw2\protected>yiic migrate --migrationPath=application.modules.user.migrations

 




 


4.result


success.


then i called:http://localhost/mw2/user/ , if i logined it, may called index.php is 404,but the error not relative above. tks.


screen shots:


image

No comments: