Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
instances for DB like validation?
  • Is there a way to declare a DB::instance() like there is for validation? Example;
    function get_items()
    {
      $query = DB::select('name')->from('items');
      // i would like to do something DB::instance('get_items')->select('name')..... 
      //so i can add to it later from another controller with DB::instance('get_items')->select('id')
    
      return $query->execute()->as_array();
    }
    

    Now, when I do 'return $query->exe....' i want to check modules to see if they want to "extend" the query so it can add a DB::select('id') to grab ID's as well. I was able to do this with the validation class by extending it and running a module check during the run() method. It worked fine because I was able to grab the instance using Validation::instance('name').. but the Database class doesn't seem to have something similar to instance, so I can't modify execute() this same way I did run() . Does the DB class have support for this type of instanceing? If not, any idea on how I could 'extend' a Model's method to modify a query without manually having to add a check in each method? I rather not completely over write the method either. Thanks
  • Currently that is not how the DB system operates. If you use one of the static DB methods, you'll get a Query Builder object returned, which uses a fixed internal data structure to store the elements of your query. Only when you use the execute() method the SQL is compiled, and a DB instance is invoked to execute the query. You could opt to store the QB object in a more global variable, like a public class property, that you can access from elsewhere, instead of using a local variable.
  • I'll give that a shot. Thanks for the explanation, reply and suggestion, much appreciated.
  • Creating a public static property worked nicely. Thanks for the suggestion.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion