bcit-ci / CodeIgniter

Open Source PHP Framework (originally from EllisLab)
https://codeigniter.com/
MIT License
18.27k stars 7.61k forks source link

Codeigniter sending data from controller to view #5976

Closed Keshangit closed 4 years ago

Keshangit commented 4 years ago

I'm trying to pass data from controller to view in Codeigniter.

Report.php (Controller)

<?php defined('BASEPATH') OR exit('No direct script access allowed');
header('Access-Control-Allow-Origin: *');
class Report extends Public_Controller
{
 function __construct()
 {
     parent::__construct();
 }
 function index()
 {$data = array(
            'title' => 'My Title',
            'heading' => 'My Heading',
            'message' => 'My Message'
       );
     $this->load->view("templates/dashboard", $data);
 } 
}

dashboard.php(View file located in view/templates)

<div class="row">
  <?php
  echo $title;
  ?>
</div>

Those codes have executed an error

A PHP Error was encountered
Severity: Notice
Message: Undefined variable: title
Filename: templates/dashboard.php
Line Number: 4

I need to load title in the dashboard.php

narfbg commented 4 years ago

Please post on our forums instead, this is a bug tracker.