myth-auth icon indicating copy to clipboard operation
myth-auth copied to clipboard

AuthController in App folder not responding on auth:publish

Open bedrijfsportaal opened this issue 2 years ago • 11 comments

Hi,

I'm not sure if this should be marked as a bug but i just found out a small issue that could only be resolved by changing the vendor package.

Situation I needed to load a helper inside the controller, this did nothing an didn't even respond clearing the entire file in the App folder. Changing this value in the vendor folder (not recommended) did the trick and actually worked. Is this something that has to work this way or i'm I doing something wrong?

Wat i need Set the BaseController as extends in App\Controller\AuthController.php so it's possible to load helper functions.

<?php 
// Current
class AuthController extends Controller

// I need
class AuthController extends BaseController

bedrijfsportaal avatar Oct 08 '21 08:10 bedrijfsportaal

Hi i think the solution is to extend AuthController in to your App\Controller\ folder

Example: `use Myth\Auth\Controllers\AuthController as MythAuthController;

class AuthController extends MythAuthController {

public function __construct() { parent::__construct(); helper('text'); }

// Other functions here if needed } `

kpeu3u avatar Oct 12 '21 10:10 kpeu3u

@kpeu3u good point! Unfortunately this doesn't work either, still the error as shown below:

Call to undefined function form_open()

bedrijfsportaal avatar Oct 13 '21 17:10 bedrijfsportaal

Hi i think the solution is to extend AuthController in to your App\Controller\ folder

Example: `use Myth\Auth\Controllers\AuthController as MythAuthController;

class AuthController extends MythAuthController {

public function __construct() { parent::__construct(); helper('text'); }

// Other functions here if needed } `

@bedrijfsportaal change the helper('text') to helper('form') it will load the form helper

mjamilasfihani avatar Oct 27 '21 01:10 mjamilasfihani

Hello @mjamilasfihani Thank you for the feedback! You have a good eye i totally missed that on @kpeu3u comment :) but it makes no difference on my side because i've written it myself so no copy/paste answers.

I think the AuthController isn't loaded inside the App folder because it makes no difference what change i've made it's not loading or changing anything.

bedrijfsportaal avatar Oct 27 '21 04:10 bedrijfsportaal

Hello @mjamilasfihani Thank you for the feedback! You have a good eye i totally missed that on @kpeu3u comment :) but it makes no difference on my side because i've written it myself so no copy/paste answers.

I think the AuthController isn't loaded inside the App folder because it makes no difference what change i've made it's not loading or changing anything.

You are welcome, glad to hear that good news :)

mjamilasfihani avatar Oct 30 '21 17:10 mjamilasfihani

No news as it's still not working like i mentioned in my previous comment..

bedrijfsportaal avatar Oct 31 '21 12:10 bedrijfsportaal

Well, since you've already published the AuthController in your App folder, you can try either of the following:

  • Add a protected $helpers variable to store your helpers in an array like so:
protected $helpers = ['form'];
  • Inherit the autoloading feature from the BaseController. So, your file should be updated to:
<?php namespace App\Controllers;

use App\Controllers\BaseController;

class AuthController extends BaseController {
    // code goes here
}

instead of:

<?php namespace App\Controllers;

use CodeIgniter\Controller;

class AuthController extends Controller {
    //
}

sammyskills avatar Nov 19 '21 00:11 sammyskills

Hello Sammyskills,

The first solutions isn't working either, tested this already on my end. The second solution is a published file from the GIT, when running "php spark auth:publish" the files will be copied to the App folder.

It's only a simple funtion so the world wouldn't end, but if I wish to extend this class there would be a mayor issue since i'm unable to extend the class itself.

Forgot to mention it's a Composer installation.

bedrijfsportaal avatar Nov 19 '21 10:11 bedrijfsportaal

Is this still actual?

manageruz avatar Jul 29 '22 10:07 manageruz

Hi,

Situation I needed to load a helper inside the controller, this did nothing an didn't even respond clearing the entire file in the App folder. Changing this value in the vendor folder (not recommended) did the trick and actually worked. Is this something that has to work this way or i'm I doing something wrong?

Wat i need Set the BaseController as extends in App\Controller\AuthController.php so it's possible to load helper functions.

There is no need to extend BaseController to load some helper. just use helper() function. That's all.

manageruz avatar Jul 29 '22 10:07 manageruz

In your case i guess you forgot to change default routes after publishing your controller to App folder. Check it please and let me know about result. I already checked helper in AuthController inside App folder which extends CI's Controller. Everything works fine, helpers loaded.

manageruz avatar Jul 29 '22 10:07 manageruz

Closing as stale. Fell free to reopen it if you need.

manageruz avatar Oct 28 '22 05:10 manageruz