Welcome Guest, Not a member yet? Register   Sign In
How to use public variables from controller in views in CI 4
#1

Here is my controller:

PHP Code:
namespace App\Controllers;

use 
CodeIgniter\Controller;

class 
MY_Controller extends Controller {

    public $public_variable;

    public function __construct() {
        $this->public_variable "Some value";
    }

    function index() {
        return view("my_folder/index");
    }




I can't call it from the view file:
in views/my_folder/index.php

PHP Code:
<?php
echo $this->public_variable;
?>


Showing this error:

Code:
ErrorException

Undefined property: CodeIgniter\View\View::$public_variable


But in CI3, I could easily use it. What's wrong here?
I've to call the same thing everywhere mostly. So, I shouldn't pass the variable to view(). Isn't it?

Please provide any solution.
Thanks in advance.
Reply


Messages In This Thread
How to use public variables from controller in views in CI 4 - by ciddict - 12-29-2020, 01:02 PM



Theme © iAndrew 2016 - Forum software by © MyBB