KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Why can´t we use a trait from App class? #2783

Closed GHSix opened this topic on on Aug 3 - 4 comments

GHSix commented on Aug 3

Util/Auth.php

<?php
namespace Util;

trait Auth
{
    function getAuth($username)
    {
      return ...
    }
 }
}

App.php

...
class App extends Application {
    use \Util\Auth;
...

Results in:

Fatal error: Trait 'Util\Auth' not found in /www/dev/koolreport/dashboard/App.php on line 13
KoolReport commented on Aug 3

Please post your structure folder (App.php and Auth.php) and also classname of App class.

GHSix commented on Aug 3

At path: /www/dev/koolreport/dashboard/

- App.php
- Util/
| - Auth.php
<?php

use \koolreport\dashboard\Application;
use \koolreport\dashboard\pages\Login;
use \koolreport\dashboard\User;

class App extends Application {
    use \Util\Auth;
...
}

I have no NS on App.php because I didn´t know it was necessary. Is it?

I´m confused because I´m able to use \Util\Auth; in any other class inside other folders, but not in App.php.

KoolReport commented on Aug 4

I consult the dev.team and receive the answer that: The root issue is after the App class is loaded then the autoload mechanism is activated. So at the time App is initated, autoload is not available yet, that why \Util\Auth is not loaded automatically. The solution is that we manually load the the Auth.php file by using require_once on top of App.php

require_once "Util/Auth.php";
GHSix commented on Aug 4

Ok so. Thank you.

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
None yet

None