Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用视图中的参数调用控制器中的函数?_Php_Codeigniter - Fatal编程技术网

Php 如何使用视图中的参数调用控制器中的函数?

Php 如何使用视图中的参数调用控制器中的函数?,php,codeigniter,Php,Codeigniter,我有一个控制器视图。我想用控制器中的一个函数绘制视图的内容 例如mycontentview: <h1>$parameter</h2>; public function index(){ $data['parameter'] = "some parameter"; $body = $this->load->view('mycontentview', $data, true); $data = array(); $data['co

我有一个控制器视图。我想用控制器中的一个函数绘制视图的内容

例如mycontentview

<h1>$parameter</h2>;
public function index(){
    $data['parameter'] = "some parameter";
    $body = $this->load->view('mycontentview', $data, true);
    $data = array();
    $data['content'] = $body;

    $this->load->view('templates/header');
    $this->load->view('indexview', $data); 
    $this->load->view('templates/footer');
}

public function new_content($param1){
    $data['parameter'] = $param1;
    $body = $this->load->view('mycontentview', $data, true);
    $data = array();
    $data['content'] = $body;

    $this->load->view('templates/header');
    $this->load->view('indexview', $data); 
    $this->load->view('templates/footer');
}

因此,我第一次在索引视图中加载。在那里,我可以回显$body,其中包含mycontentview中的内容,单击按钮我想调用带有参数的new_content函数。我该怎么做?

您可以将此添加到
mycontentview
视图中

<a href="<?php echo site_url('YourController/new_content/'.$parameter); ?>" title="Button Title">Button Text</a>

您可以将其添加到
mycontentview
视图中

<a href="<?php echo site_url('YourController/new_content/'.$parameter); ?>" title="Button Title">Button Text</a>

在视图文件中使用此代码重定向

<a href="<?php echo site_url('Controller/Method/'.$Parameter); ?>" class="Your Class" id="Your Id">Your Button</a>

在视图文件中使用此代码重定向

<a href="<?php echo site_url('Controller/Method/'.$Parameter); ?>" class="Your Class" id="Your Id">Your Button</a>

您可以在codeigniter中使用get实例方法,如

$ci =& get_instance();
$ci->functionName($something);
您可以调用当前控制器中的函数,或者在HMVC中调用基本控制器中的函数,或者在MVC中调用CI_控制器中的函数


我想这将对您有所帮助,请告诉我任何问题

您可以在codeigniter中使用get-instance方法,如

$ci =& get_instance();
$ci->functionName($something);
您可以调用当前控制器中的函数,或者在HMVC中调用基本控制器中的函数,或者在MVC中调用CI_控制器中的函数


我认为这将对您有所帮助,请告诉我任何问题

您可以在您的
mycontentview
@M.Hemant中使用
锚定标记
。您认为具体是什么?您想要一种从视图到控制器的方法,带有参数。您可以显示您的
mycontentview
视图吗?@M.Hemant您可以看到它,有一个标签。就这些。我想在另一个视图中调用mycontentview。mycontentview只是整个视图的一部分,我想用一个参数生成什么您可以在您的
mycontentview
@M.Hemant中使用
锚定标记。您可以显示您的
mycontentview
视图吗?@M.Hemant您可以看到它,有一个标签。就这些。我想在另一个视图中调用mycontentview。mycontentview只是整个视图的一部分,我想用参数生成的内容不会有帮助,因为我想在视图中调用函数。它不会有帮助,因为我想在视图中调用函数。