I've been struggle with this for hours. I would like to use helpers and the user_agent library on a model.
User_agent: every-time I'm trying to load the user agent library using the next code:
$agent = $this->request->getUserAgent();
I getting the next error:
Error Call to a member function getUserAgent() on null
- When trying to load helper and use it from model for example cookie helper:
helper(cookie);
I think it's loading the helper but when trying to use it I printing next error:
Error Call to a member function is_mobile() on null
CodePudding user response:
There isn't any need to load helpers.
The User Agent Class provides functions that help identify information about the browser, mobile device, or robot visiting your site.
$agent = \Config\Services::request()->getUserAgent();
$isMobile = $agent->isMobile();