Welcome Guest, Not a member yet? Register   Sign In
Protected method in controller
#1

In CI3 I was able to set private o protected method in controller, for example:

Code:
    private function _human_filesize($bytes, $decimals = 2)
    {
        $factor = floor((strlen($bytes) - 1) / 3);
        if ($factor > 0) $sz = 'KMGT';
        return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$sz[$factor - 1] . 'B';
    }
then I could call the private function within the same controller with:

Code:
    $this->_human_filesize($size);

Can we do the same in CI4? ...Sorry I'm a bit lost about this point reading the online guide
Reply
#2

(12-21-2024, 07:36 AM)Vespa Wrote: In CI3 I was able to set private o protected method in controller, for example:

Code:
    private function _human_filesize($bytes, $decimals = 2)
    {
        $factor = floor((strlen($bytes) - 1) / 3);
        if ($factor > 0) $sz = 'KMGT';
        return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$sz[$factor - 1] . 'B';
    }
then I could call the private function within the same controller with:

Code:
    $this->_human_filesize($size);

Can we do the same in CI4? ...Sorry I'm a bit lost about this point reading the online guide

Private functions are part of the PHP language so they would work in CI4 the same way as in CI3.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB