0
votes

I use codeigniter.

I get an error when I try to get the parameter in the 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);


}
}

when i try to go : http://localhost/cod/index.php/todo/test/123

A PHP Error was encountered
Severity: Notice
Message: Undefined property: Todo::$uri
Filename: controllers/Todo.php
Line Number: 21
Backtrace:
File: /opt/lampp/htdocs/cod/application/controllers/Todo.php
Line: 21
Function: _error_handler
File: /opt/lampp/htdocs/cod/index.php
Line: 315
Function: require_once

An uncaught Exception was encountered
Type: Error
Message: Call to a member function segment() on null
Filename: /opt/lampp/htdocs/cod/application/controllers/Todo.php
Line Number: 21
Backtrace:
File: /opt/lampp/htdocs/cod/index.php
Line: 315
Function: require_once

3
Hi @mehmtee10, welcome to Stack Overflow. This question needs to be edited. To improve you question quality, I invite you to read How do I ask a good question. - GaboBrandX
the uri class is loaded automatically, so i'm not sure how you are getting this error given that you've extended ci_controller. this is the exact code you are using? - Alex

3 Answers

0
votes

Please verify the URL helper is enabled in your config function

try to use $this->uri->get_segment(1);

Try to use

$CI =& get_instance(); 
$this->CI->uri->segment('2')
0
votes

you have to load helper in codigniter autoload.php file in config folder

$autoload['helper'] = array('url');
0
votes

Try to use

codigniter autoload.php file in config folder

$autoload['helper'] = array('url');

Url : http://localhost/laravel/users/abc
$product_id = $this->uri->segment(2);
Result : abc

Read https://www.codeigniter.com/user_guide/libraries/uri.html