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

(04-20-2020, 06:55 AM)5flex Wrote: How you can try to call the function if it has PRIVATE modificator?  Change private on public or protected!

It's a typographic error writing this post, the function is public:


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);

    }

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



In view:

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

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

<div>
    /* I tried this but do not work */
    <?= $this->customFunction(); ?>
</div>

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


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



Theme © iAndrew 2016 - Forum software by © MyBB