簡體   English   中英

Codeigniter:從 Controller 視圖中調用 function

[英]Codeigniter: call a function in View From Controller


我是 Codeigniter 的新手。 在我的示例應用程序中,我在 Main.php(查看文件夾)中添加了一個名為“RegForm”的新選項卡。 當我單擊 RegForm 選項卡時,它會加載新窗口(width='800px' height='500px')。 我理解這個概念,但我不知道如何在 Codeigniter 中編寫代碼。 基本上,當我單擊 RegForm 選項卡時,我在 Controller 文件中調用了 function。 我需要在視圖中調用 function ,我在其中加載具有屬性的 window 。 嗯,我是對的。

你可以這樣做(如果我理解正確的話):

查看“someview”包含此鏈接:

$atts = array(
              'width'      => '800',
              'height'     => '500',
              'scrollbars' => 'yes',
              'status'     => 'yes',
              'resizable'  => 'yes',
            );
echo anchor_popup('mycontroller/mymethod','Click this for a popup',$atts);

(anchor_popup 是 URL 助手中的一個函數,只需自動加載它,它真的很有用)

在 Controller 'mycontroller' 中:

class Mycontroller extends CI_Controller {

    //function index()
    // other functions

    function mymethod() 
    {
      $this->load->model('mymodelforthis');
      $data['properties'] = $this->mymodelforthis->get_properties();
      $this->load->view('myview',$data);
    }
}

然后,在“myview”中,您以您想要的方式顯示$properties希望這會有所幫助,lmk

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM