第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Codeigniter :Controller 內(nèi)部調(diào)用函數(shù)

Codeigniter :Controller 內(nèi)部調(diào)用函數(shù)

PHP
阿波羅的戰(zhàn)車 2022-01-08 14:42:13
我在 Codeigniter 的另一個函數(shù)中有問題調(diào)用函數(shù)。所以我有2個功能:功能 1 有控制器用于從數(shù)據(jù)庫中獲取數(shù)據(jù):public function tampil_halaman_berita()    {        $data['tampil_berita'] = $this->berita->getAllBerita();        $data['tampil_kategori'] = $this->berita->getAllKategori();        $data['tampil_wartawan'] = $this->berita->getAllWartawan();    }函數(shù) 2 從函數(shù) 1 調(diào)用控制器來索引: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');    }但是我收到了這個錯誤,我的函數(shù)tampil_halaman_berita沒有調(diào)用到index()Severity: NoticeMessage: Undefined variable: tampil_beritaFilename: pages/Berita.phpLine Number: 17Backtrace:File: C:\xampp\htdocs\flutter-news\application\views\pages\Berita.phpLine: 17Function: _error_handlerFile: C:\xampp\htdocs\flutter-news\application\controllers\pages\Berita.phpLine: 21Function: viewFile: C:\xampp\htdocs\flutter-news\index.phpLine: 315Function: require_once我不想,像這樣對我的所有函數(shù)重復每個模型,所以我創(chuàng)建了一些函數(shù),我只是調(diào)用函數(shù)名。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();}我希望你們都明白我的問題。
查看完整描述

2 回答

?
神不在的星期二

TA貢獻1963條經(jīng)驗 獲得超6個贊

在這里,您需要使用PASS BY REFERENCEwith &concept 來解決您的問題


public function tampil_halaman_berita(&$data)//changes

    {

        $data['tampil_berita'] = $this->berita->getAllBerita();

        $data['tampil_kategori'] = $this->berita->getAllKategori();

        $data['tampil_wartawan'] = $this->berita->getAllWartawan();

    }

    public function index()

    {

        $data = array();

        $data['judul'] = "Halaman Berita";

        $this->tampil_halaman_berita($data);//changes

        echo '<pre>';print_r($data);die;

        $this->load->view('ui/Header');

        $this->load->view('pages/Berita', $data);

        $this->load->view('ui/Footer');

    }

試試我的代碼來測試,讓我知道你看到了什么?


查看完整回答
反對 回復 2022-01-08
?
慕無忌1623718

TA貢獻1744條經(jīng)驗 獲得超4個贊

-First load model in your tampil_halaman_berita() method

-get data using Model and return data

-then call first method to another method


查看完整回答
反對 回復 2022-01-08
  • 2 回答
  • 0 關注
  • 168 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號