我在 Codeigniter 的另一个函数中有问题调用函数。所以我有2个功能:
功能 1 有控制器用于从数据库中获取数据:
public function tampil_halaman_berita()
{
$data['tampil_berita'] = $this->berita->getAllBerita();
$data['tampil_kategori'] = $this->berita->getAllKategori();
$data['tampil_wartawan'] = $this->berita->getAllWartawan();
}
函数 2 从函数 1 调用控制器来索引:
public function index()
{
$data['judul'] = "Halaman Berita";
$this->tampil_halaman_berita();
$this->load->view('ui/Header');
$this->load->view('pages/Berita', $data);
$this->load->view('ui/Footer');
}
但是我收到了这个错误,我的函数tampil_halaman_berita没有调用到index()
Severity: Notice
Message: Undefined variable: tampil_berita
Filename: pages/Berita.php
Line Number: 17
Backtrace:
File: C:\xampp\htdocs\flutter-news\application\views\pages\Berita.php
Line: 17
Function: _error_handler
File: C:\xampp\htdocs\flutter-news\application\controllers\pages\Berita.php
Line: 21
Function: view
File: C:\xampp\htdocs\flutter-news\index.php
Line: 315
Function: require_once
我不想,像这样对我的所有函数重复每个模型,所以我创建了一些函数,我只是调用函数名。
public function add(){
$data['tampil_berita'] = $this->berita->getAllBerita();
$data['tampil_kategori'] = $this->berita->getAllKategori();
$data['tampil_wartawan'] = $this->berita->getAllWartawan();
}
public function update(){
$data['tampil_berita'] = $this->berita->getAllBerita();
$data['tampil_kategori'] = $this->berita->getAllKategori();
$data['tampil_wartawan'] = $this->berita->getAllWartawan();
}
我希望你们都明白我的问题。
神不在的星期二
慕无忌1623718