RedBean 4.3 “A database has already be specified for this key”

146 views
Skip to first unread message

SzkolaWEB

unread,
Sep 24, 2015, 5:29:21 PM9/24/15
to redbeanphp
I making a small site and decided to use Valitron library for the validation part of my site. I noticed there is no kind of "unique" method that returns whether a passed value already exists in the database or not. I quickly added this method, but not like it is recommended to do. I added this:

protected function validateUnique($field, $value, $table)
{
    $model
= new Model();
   
return $model->unique($table[0], $field, $value);
}

to the main Validator class. The thing is, it is working, but only with one field. If I use this on 2 or more fields in my validation proccess, I get this error:

Fatal error: Uncaught exception 'RedBeanPHP\RedException' with message 'A database has already be specified for this key.' in C:\dev\htdocs\Shop\vendor\gabordemooij\redbean\RedBeanPHP\Facade.php:295 Stack trace: #0 C:\dev\htdocs\Shop\vendor\gabordemooij\redbean\RedBeanPHP\Facade.php(216): RedBeanPHP\Facade::addDatabase('default', 'mysql:host=127....', 'root', '', false) #1 C:\dev\htdocs\Shop\app\libs\Model.php(18): RedBeanPHP\Facade::setup('mysql:host=127....', 'root', '') #2 C:\dev\htdocs\Shop\vendor\vlucas\valitron\src\Valitron\Validator.php(429): Shop\libs\Model->__construct() #3 [internal function]: Valitron\Validator->validateUnique('email', 'email.example@g...', Array) #4 C:\dev\htdocs\Shop\vendor\vlucas\valitron\src\Valitron\Validator.php(885): call_user_func(Array, 'email', 'email.example@g...', Array) #5 C:\dev\htdocs\Shop\app\controllers\AuthController.php(68): Valitron\Validator->validate() #6 [internal function]: Shop\controllers\AuthController->postRegister() #7 C:\dev\htdocs\Shop\app\libs\Bootstrap.php(64): in C:\dev\htdocs\Shop\vendor\gabordemooij\redbean\RedBeanPHP\Facade.php on line 295

I work with RedBean as well as Valitron for the first time and I'm not able to say what causes the problem. 





Reply all
Reply to author
Forward
0 new messages