![](/img/trans.png)
[英]In codeigniter how to get a reference to the child controller from a method in parent controller when that method is called from the child controller
[英]How to get parameter from Controller method in codeigniter?
我尝试了以下方法来使用路由和控制器,并尝试从控制器方法中获取参数值,但结果为$ 1。 但实际上,我通过了3。
routes.php
$route['helloword/:any'] = "FirstProgram/helloworld/$1";
controller
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class FirstProgram extends CI_Controller {
public function helloworld($param=''){
$data = array(
'title' => 'Title',
'heading' => 'Heading',
'message' => 'Message',
'param' => $param
);
echo $param;exit;
$this->load->view('FirstProgram', $data);
}
}
?>
更改您的路线代码,只需为:any添加一个括号即可
$route['helloword/(:any)'] = "FirstProgram/helloworld/$1";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.