![](/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.