0

I just started learning PHP. Passing values into views, specifically.

I have the following in my Home.php controller:

<?php

class Home extends CI_Controller{
    
    public function index()
    {
        $data['title'] = "Passing data to view";        
        $this->load->view('index', $data);
    }
}

?>

And the following in index.php:

<html>
<head>
    <title><?php echo $title;?> </title>
</head>
<body>
    <h1>This is a heading</h1>
</body>
</html>

However, the title is not updating and still shows the simple text title I had in it earlier. enter image description here

All files have been saved and the page has been refreshed numerous times.

Can anyone point me in the right direction please?

Rup7ur3
  • 76
  • 7
  • Maybe try to refresh cache. – TYeung Aug 28 '21 at 09:50
  • @LearningMathematics I am not sure how to do this. I found this [link]( https://stackoverflow.com/questions/1037249/how-to-clear-browser-cache-with-php) that mentioned including a set of headers to constantly force the cash to reload but have not had success with it – 儚き 戦士の翼 Aug 28 '21 at 09:55
  • 1
    Can you provide more information about your code? What kind of framework do you use? And have you tried `echo $data['title']` ? – schmauch Aug 28 '21 at 09:56
  • just open the page in incognito mode, see if is up to date there - if it is, it's because you have an old, stale version of the application in your cache. maybe even try to change `this is a heading` with something else, to check if you are editing the correct file. – Federkun Aug 28 '21 at 09:58
  • @schmauch I'm using CodeIgniter 3 on Xamp 3.3. Not the best and the latest, but I'm just trying to get my feet wet right now and this is the version that came recommended in the module. – 儚き 戦士の翼 Aug 28 '21 at 10:04
  • @Federkun I tried this and it's still there in incognito. I also tried changing the heading but the changes didn't show up. Where do I go from here? – 儚き 戦士の翼 Aug 28 '21 at 10:05
  • how are you running the php server? – Federkun Aug 28 '21 at 10:14
  • There could be a few things wrong. Check the constructor in your Home method -- see https://forum.codeigniter.com/thread-934-page-2.html you might have router issues too. I don't know enough to say confidently. @儚き 戦士の翼 I'd probably use a separate header template/view. https://stackoverflow.com/q/11376745/2943403 , https://stackoverflow.com/q/14051008/2943403 – mickmackusa Aug 28 '21 at 11:32

0 Answers0