Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YumUser.php::tableName() don't recognize the userTable passed argument from config #3

Closed
christiansalazar opened this issue Jun 14, 2012 · 1 comment

Comments

@christiansalazar
Copy link

This is the case in PHP 5.2.6, (please reproduce on other versions)

My user table is named "users" (with extra S at end), when you setup config and specify in users module the "userTable" argument specifying value: "users" then and exception occurs because table "user" (without the "s") is not present in database. It looks like YumUser model dont recognize the passed argument: "users", instead using "user" by default.

you can observe in YumUser, the "user" argument is specifyed by default, assuming no other value is present, but, the value "IS PRESENT" in config, why it dont recognize ?, please continue reading.

Looking deeply in YumUser.php, i set some debug lines in YumUser that demostrate what's happening in that method. As you can observe, the problem is "if (isset(Yum::module()->userTable))" who is always returning false, no matter if the config value is present or not.

Then a simple solution is not using "isset", but it can derive in an exception (try/catch ?) if user dont specify the userTable argument in it own config file.

in file : \code\ecommerce\protected\modules\user\models\YumUser.php, method:
public function tableName()
{
if (isset(Yum::module()->userTable)) {
$this->_tableName = Yum::module()->userTable;
Yii::log("tableName MARK #1,","info");
}
else {
$this->_tableName = 'user'; // fallback if nothing is set
Yii::log("tableName MARK #2,","info");
}

    Yii::log("tableName is: ".$this->_tableName,"info");
    throw new Exception("STOP HERE - EXCEPTION",500);   

    return Yum::resolveTableName($this->_tableName, $this->getDbConnection());
}
@thyseus
Copy link
Owner

thyseus commented Jun 14, 2012

I have completely rewritten the tableName function. Its now KISS:

    $this->_tableName = Yum::module()->userTable;
    return $this->_tableName;

the old ResolveTableName() method is a relict from the old age, when yii-user-management was one BIG module
rather than many small, like it is now. I will keep it simply for all other submodules and tables, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants