Love Fuel?
Donate
About
Forums
Discussions
Login
FuelPHP Forums
Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
General
How to Dynamically Set table name in the Model fuelphp
viyancs
January 2014
I have problem when I want to set table name with my prefix from my config file.
class Model_Users extends \Orm\Model
{
protected static $_table_name ;
public function before()
{
parent::before();
self::$_table_name = \Config::get('dbase.db.prefix').'users';
}
}
and when I am run I got the error
42000!
I think that error because table_name is empty or not set.
any suggestion ?
Harro
January 2014
Accepted Answer
You never use self (unless in very specific cases), you use static.
Having said that, a before() method is something controllers only have. That doesn't work for other classes. For static data, you can do:
public static function _init()
{
static::$_table_name = \Config::get('dbase.db.prefix').'users';
}
and having said that: you know you can define a table prefix in your db.php config file?
viyancs
January 2014
Thanks for support,
Hola You Right, I think it's will be nice if I am define in db.php
Add a Comment
Howdy, Stranger!
It looks like you're new here. If you want to get involved, click one of these buttons!
Sign In
Apply for Membership
Categories
All Discussions
5,088
General
↳ General
3,364
↳ Job Board
13
↳ Installation & Setup
214
Packages
↳ Oil
213
↳ Orm
700
↳ Auth
260
Development
↳ Tips and Tutorials
126
↳ Code share
145
↳ Applications
52
In this Discussion
Harro
January 2014
viyancs
January 2014