Accessing a custom object with instanceof |
I have instantiated a new object from a class in my app/libraries folder as such:
PHP Code: // in controller PHP Code: // in controller method But when I pass $account to my model and check if it is an instance of LN_Account the conditional fails. PHP Code: // in controller method PHP Code: // in model How do I make LN_Account visible to my model?
In model:
Code: use App\Libraries\LN_Account; You can also do the following in getAuthenticationCredentials() to show details about the variable: Code: d($account);
I tried adding that to the Model with no luck. Same error.
I have been using CI3 for like 8 years so not a n00b here, and PHP for 15 years. This one has me stumped.
The specific error is: Class 'LN_Account' not found
The model is like this: PHP Code: namespace App\Models; LN_Account is in app\Libraries PHP Code: namespace App\Libraries; if I print_r $credentials inside the model/method I get this, so the controller knows what it is and created it. PHP Code: App\Libraries\LN_Account Object Okay so the outer if ($account instanceof LN_Account) seems to work now, it's this that doesn't: $credentials = $query->getCustomRowObject(0, 'LN_Account') Do I have to instantiate a new LN_Account() for it to use? I figured it would do it automatically.
(01-26-2021, 06:34 PM)iRedds Wrote:(01-26-2021, 06:18 PM)baxterheinen Wrote: The specific error is: Class 'LN_Account' not found Ah, because it's not already an object, got it. (01-26-2021, 06:37 PM)baxterheinen Wrote:(01-26-2021, 06:34 PM)iRedds Wrote:(01-26-2021, 06:18 PM)baxterheinen Wrote: The specific error is: Class 'LN_Account' not found (01-26-2021, 06:37 PM)baxterheinen Wrote: Ah, because it's not already an object, got it. Incorrect example in the documentation. The documentation uses the User class without a namespace, so just 'User' is passed as a parameter. If the class uses a namespace, then it must also be specified.
This is from PHP.net.
Code: If you want to test if a classname is an instance of a class, the instanceof operator won't work. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |