繁体   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