• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can I change the database for is_unique?

#1
[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.

#2
[eluser]CroNiX[/eluser]
No, it only allows you to select the table and field. You'd have to create your own.

#3
[eluser]Matalina[/eluser]
even if I did $this->load->database('newdb');?

#4
[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?

#5
[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);
  }

#6
[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.

#7
[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".


#8
[eluser]Matalina[/eluser]
Thanks for you info.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.