简体   繁体   English

Codeigniter:从 Controller 视图中调用 function

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


I am New to Codeigniter.我是 Codeigniter 的新手。 In my Sample Application I add a new Tab called "RegForm" in my Main.php(View Folder).在我的示例应用程序中,我在 Main.php(查看文件夹)中添加了一个名为“RegForm”的新选项卡。 When i Click the RegForm Tab it load the New Window(width='800px' height='500px').当我单击 RegForm 选项卡时,它会加载新窗口(width='800px' height='500px')。 i understand the concept but i dont know how to write coding in Codeigniter.我理解这个概念,但我不知道如何在 Codeigniter 中编写代码。 Basicall i call a function in Controller file when i Clicked the RegForm tab.基本上,当我单击 RegForm 选项卡时,我在 Controller 文件中调用了 function。 and i need to call a function in View where i load a window with properties.我需要在视图中调用 function ,我在其中加载具有属性的 window 。 amm i correct.嗯,我是对的。

YOu could do this (if I understood correctly):你可以这样做(如果我理解正确的话):

View 'someview' contains this link:查看“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 is a funcion in the URL helper, just autoload it, it's really useful) (anchor_popup 是 URL 助手中的一个函数,只需自动加载它,它真的很有用)

in Controller 'mycontroller':在 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);
    }
}

THen, in 'myview', you display $properties the way you want Hope this helps, lmk然后,在“myview”中,您以您想要的方式显示$properties希望这会有所帮助,lmk

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM