Welcome Guest, Not a member yet? Register   Sign In
my controller fails to find helper function
#12

(This post was last modified: 5 hours ago by paulbalandan.)

When you declare a function in a file that has a namespace declaration like those you have in youre helpers, the full name of the function includes that namespace. So,
PHP Code:
// awesome_helper.php
namespace App\Helpers;

function 
whatever(): void {} 

In this case, your
Code:
whatever
 function's full name is
Code:
App\Helpers\whatever
. So, if you are invoking that function in your code, you usually add a use statement.

PHP Code:
// home controller
namespace App\Controllers;

use function 
App\Helpers\whatever// < this line

class HomeController extends BaseController
{
    public function foo(): void
    
{
        whatever(); // call your helper as usual
    }


If you don't have the namespace declaration in your helpers, then no need for the use statement line.
Reply


Messages In This Thread
RE: my controller fails to find helper function - by paulbalandan - 5 hours ago



Theme © iAndrew 2016 - Forum software by © MyBB