Welcome Guest, Not a member yet? Register   Sign In
Call BaseController custom function in view
#3

(04-20-2020, 06:01 AM)5flex Wrote: BaseController is a common base for expanding your other controllers. However, it is the same Controller as the rest. Everything that you call in your controllers can be called in it in the same way. If not difficult, can you show your code?

Hi, i need to call inside a view a custom function created in BaseController.

BaseController:
PHP Code:
<?php

namespace App\Controllers;

use 
CodeIgniter\Controller;
use 
CodeIgniter\HTTP\RequestInterface;
use 
CodeIgniter\HTTP\ResponseInterface;
use 
Psr\Log\LoggerInterface;

class 
BaseController extends Controller
{

    protected 
$helpers = [];

    public function 
initController(RequestInterface $requestResponseInterface $responseLoggerInterface $logger)
    {
        
parent::initController($request$response$logger);

    }

    private function 
customFunction()
    {
          return 
'Testing';
    }



View:
PHP Code:
<?php
<?= $this->extend('layout'); ?>

<?= $this->section('content'?>

<div>
    <?= Here call function "customFunction" in BaseController ?>
</div>

<?= $this->endSection(); ?>
Reply


Messages In This Thread
RE: Call BaseController custom function in view - by nicojmb - 04-20-2020, 06:10 AM



Theme © iAndrew 2016 - Forum software by © MyBB