agungsugiarto / boilerplate

CodeIgniter4 Boilerplate based on AdminLTE 3 with user management, roles, permissions, ...
MIT License
156 stars 49 forks source link

Call to undefined function menu() VENDORPATH\agungsugiarto\boilerplate\src\Views\layout\mainsidebar.php at line 21 #99

Open rafaelsanchezrd opened 2 years ago

rafaelsanchezrd commented 2 years ago

Hello Friend, first thanks for your great CI4 boilerplate, I have some time working with CI and every day learning more, I have a question about your boilerplate.

I was able to configure it and its working with no error, but I'm a bit lost on how I would add more controllers, View, and Models in the App Folder, when I try to return the view I receive some error

Describe the bug I copied the dashboard View to App/View Folder also the DashboardController to the App/Controllers In the Home Controller, I try to call the dashboard view and I get this error:

Call to undefined function menu() VENDORPATH\agungsugiarto\boilerplate\src\Views\layout\mainsidebar.php at line 21

<?php namespace App\Controllers; class Home extends BaseController { public function index() { //return view('welcome_message'); $data = [ 'title' => 'Dashboard', ]; return view('dashboard', $data); } }

May I ask you please how to more Views, Models, and Controllers in the App Folder so it could be displayed inside the container?

eveltic commented 2 years ago

Hello Friend, first thanks for your great CI4 boilerplate, I have some time working with CI and every day learning more, I have a question about your boilerplate.

I was able to configure it and its working with no error, but I'm a bit lost on how I would add more controllers, View, and Models in the App Folder, when I try to return the view I receive some error

Describe the bug I copied the dashboard View to App/View Folder also the DashboardController to the App/Controllers In the Home Controller, I try to call the dashboard view and I get this error:

Call to undefined function menu() VENDORPATH\agungsugiarto\boilerplate\src\Views\layout\mainsidebar.php at line 21 'Dashboard', ]; return view('dashboard', $data); } } May I ask you please how to more Views, Models, and Controllers in the App Folder so it could be displayed inside the container?

I don't know if this is the correct answer but is working for me.

You should extend the controller from "agungsugiarto\boilerplate\Controllers\BaseController" and then add a protected variable called $helpers that is an array of the desired helpers. The helper you want is called "menu_helper". Another option is to call the helper function with the "menu_helper" as one of the array keys.

An example:

<?php

namespace App\Controllers;

use agungsugiarto\boilerplate\Controllers;

class TestController extends BaseController
{
    protected $helpers = ['menu_helper'];
    public function index()
    {
        $data = ['title' => 'Dashboard',];
        return view('agungsugiarto\boilerplate\Views\dashboard', $data);
    }
}

Greets!

aayush-rajpara commented 1 year ago

Thanks for your help though this is not mentioned anywhere in documentation.