【发布时间】:2019-07-15 17:39:54
【问题描述】:
我使用 codeigniter。
当我尝试获取 url 中的参数时出现错误
<?php
class Todo extends CI_Controller{
public function __construct() {
parent::__construct();
}
public function index(){
$this->load->view('index.php');
}
public function blog(){
$this->load->view('arsiv');
}
public function test($param){
$this->load->view('test');
$a = $this->uri->segment(2);
}
}
当我尝试去时:http://localhost/cod/index.php/todo/test/123
遇到 PHP 错误
严重性:通知
消息:未定义的属性:Todo::$uri
文件名:控制器/Todo.php
行号:21
回溯:
文件:/opt/lampp/htdocs/cod/application/controllers/Todo.php
线路:21
函数:_error_handler
文件:/opt/lampp/htdocs/cod/index.php
线路:315
函数:require_once遇到未捕获的异常
类型:错误
消息:在 null
上调用成员函数 segment() 文件名:/opt/lampp/htdocs/cod/application/controllers/Todo.php
行号:21
回溯:
文件:/opt/lampp/htdocs/cod/index.php
线路:315
函数:require_once
【问题讨论】:
-
嗨 @mehmtee10,欢迎来到 Stack Overflow。这个问题需要编辑。为了提高你的问题质量,我邀请你阅读How do I ask a good question。
-
uri 类是自动加载的,所以我不确定你是如何得到这个错误的,因为你已经扩展了 ci_controller。这是您使用的确切代码吗?
标签: php codeigniter