Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getSharedInstance doesn't work on costum services #294

Closed
mithazhe opened this issue Oct 17, 2016 · 2 comments
Closed

getSharedInstance doesn't work on costum services #294

mithazhe opened this issue Oct 17, 2016 · 2 comments

Comments

@mithazhe
Copy link
Contributor

mithazhe commented Oct 17, 2016

I have custom service:

public static function loggedinuser($getShared = true)
{
if ($getShared)
{
return self::getSharedInstance('loggedinuser');
}
return (new UsersModel())->getUserById(session('user_id'));
}

if I call it with $getShared = true, It doesn't work, show NULL with var_dump, if $getShared = false, It works, show the data.

However. I make sure that getSharedInstance doesn't work on custom services, by moving that function into \system\Config\Services.php. The result, that function works well with $getShared = true.

@ridho1991
Copy link
Contributor

Hmm. I think the problem is parent class can't call child class method. getSharedInstance() can't call loggedinuser()

@lonnieezell
Copy link
Member

A couple of things;

First - these boards are not intended to be used to advice or problem solving. They are for feature planning and bugs.

Second - don't use a service for that. Just create a User class and instantiate that when you need it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants