0

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

2
  • 1
    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. Commented Jul 15, 2019 at 18:07
  • 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? Commented Jul 15, 2019 at 22:12

3 Answers 3

0

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')
Sign up to request clarification or add additional context in comments.

Comments

0

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

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

Comments

0

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

1 Comment

Please add some explanation to your code such that others can learn from it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.