[eluser]Matalina[/eluser]
I'm curious could I change the database for is_unique?
I'm assuming it uses whatever the default database is. I'm using multiple databases and just curious. I'm more than fine with writing my own call backs, just curious.
[eluser]CroNiX[/eluser]
No, it only allows you to select the table and field. You'd have to create your own.
[eluser]Matalina[/eluser]
even if I did $this->load->database('newdb');?
[eluser]CroNiX[/eluser]
Yes, but then it would use that database for everything until you changed it again. How would you get it to use that database only for that one rule validation?
[eluser]Matalina[/eluser]
change it back after the rule?
*edit* That wouldn't work really...
But really none of my controllers are touching the database directly so it's not sticking with one programming style. I was just curious if it was possible. Most of my database calls in the models I call directly form a database object.
Code:
private $auth; // Auth Database
function __construct() {
parent::__construct();
// Load Databases
$this->auth = $this->load->database('default',TRUE);
}
[eluser]CroNiX[/eluser]
You're right that it wouldn't work because the rules don't get executed until later in the code (form_validation::run()).
If you change the database right before $this->form_validation->run() and then change it back right after (and before you do things like store/retrieve anything in the db), it might work as long as nothing else in the validation rules depend on the main database.
[eluser]CroNiX[/eluser]
I think it would be best for you to create your own validation rule, or callback, for this special case. That won't interfere with anything existing and would remain more "future-proof".
[eluser]Matalina[/eluser]
Thanks for you info.