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.
Orm
I can not dynamically change table name(dev-1.9)
soseki
January 27
Hello there,
I have following method in the model.
public static function set_table(int $user_id)
{
static::$_table_name = "tests_".substr(str_pad((string)$user_id,2,0,STR_PAD_LEFT),-2);
}
public static function add($user_id)
{
$prop = array('user_id'=>$user_id);
self::set_table($user_id);
return self::forge($prop)->save();
}
But, it dose not change the table name.
Do you have any suggetion for this?
Regards,
Harro Verton
January 28
Accepted Answer
Do not use self:, use static:. Late static binding is important if you change static properties.
atabak
January 31
in your model:
public static function table()
{
// some magic code
return 'new_table_name';
}
Harro Verton
January 31
Accepted Answer
The model already has a static method for retrieving the table name.
The problem is that
self:: will call the original base model, not the current derived class. You need late static binding for that.
soseki
February 2
Hello there,
Sorry for late reply.
Thank you very much for your help.
I did not know that I have to use static:: all the time when I change static properties.
I still have to more about PHP.
Thank you, Harro
:)
Harro Verton
February 3
Accepted Answer
No worries, we've all been there.
See
https://www.php.net/manual/en/language.oop5.late-static-bindings.php
soseki
February 5
Thank you, Harror
:)
I always appreciate it .
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,058
General
↳ General
3,340
↳ Job Board
13
↳ Installation & Setup
213
Packages
↳ Oil
212
↳ Orm
700
↳ Auth
258
Development
↳ Tips and Tutorials
125
↳ Code share
145
↳ Applications
51
In this Discussion
atabak
January 31
Harro Verton
February 3
soseki
February 5