Welcome Guest, Not a member yet? Register   Sign In
Autoload Librari and Helper in codeigniter4
#1

please help me how to make autoload in codeigniter4 for example loading url, form_validation, session, database, and others in the Autoload.php / Codeigniter4 file
Reply
Reply
#3

The url helper is already loaded by default in CodeIgniter 4 no reason to load it again.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

thank you for helping me
Reply
#5

I have this function in Common.php. So, it wraps the view in the main viwe, also checks if is any present in the helpers array and load depending on the helpers that I send in $data. Like this:

function renderView(string $view, array $data = [], array $options = []): mixed
{
$ionAuth = new \IonAuth\Libraries\IonAuth();
$Images = new \App\Models\Images();

extract($data);

$avatar = $Images->where('type','user')->where('external_id',$ionAuth->user()->row()->id)->orderBy('main','desc')->find();

$avatar = ($avatar!==[]) ? imageUrl('user',$avatar[0]['name']) : null;

if(!empty($helpers))
{
foreach($helpers as $helper)
{
helper($helper);
}
}

return view('dashboard',[
'title' => esc($title),
'subtitle' => isset($subtitle) ? esc($subtitle) : null,
'bodycontent' => view($view,$data),
'user' => esc($ionAuth->user()->row()),
'isadmin' => esc($ionAuth->isAdmin()),
'active' => isset($active) ? esc($active) : null,
'activecontroller' => isset($activecontroller) ? esc($activecontroller) : null,
'breadcrumbs' => esc($breadcrumbs),
'avatar' => $avatar,
]);
}

And I call it like:

return renderView('purchases/purchaseedit', [
'title' => lang('purchase.core.title'),
'bodycontent' => lang('purchase.core.contacts'),
'boxtitle' => lang('purchase.core.create'),
'boxfooter' => sprintf(lang('providers.core.lines'), $this->pageLen),
'active' => 'purchase',
'activecontroller' => 'purchase',

'details' => $details,
'purchase' => $purchase,
'provider' => $provider,
'products' => $this->Providers->getArticlesOfProvider($provider['id']),

'paginate' => $this->Purchases->paginate($this->pageLen),
'count' => $this->Purchases->countFindAll(),
'pagelen' => $this->pageLen,
'pager' => $this->Providers->pager,
'Time' => new Time(),
'locale' => $this->request->getLocale(),
'provArts' => $this->Providers,
'errors' => $errors ?? null,
'helpers' => ['form'],

'breadcrumbs' => [
[
'url' => base_url(),
'text' => lang('app.dashboard'),
'icon' => lang('app.icons.dashboard'),
'active' => false,
],
[
'url' => base_url('purchases'),
'text' => lang('purchase.core.title'),
'icon' => lang('purchase.core.icon'),
'active' => false,
],
[
'url' => '',
'text' => lang('purchase.core.create'),
'icon' => lang('purchase.core.icon-plus'),
'active' => true,
]
]
]);
Reply




Theme © iAndrew 2016 - Forum software by © MyBB