Welcome Guest, Not a member yet? Register   Sign In
Getting Value in index file
#1

[eluser]anishpsla[/eluser]
Hi, I am new to Codeigniter. I need a help to get value from GET. I have code to get value from www.mysite.com/index.php/home/index/value in home controller. I want to Display 'Value' in www.mysite.com/index.php/home/value or www.mysite.com/index.php/value or www.mysite.com/value (URL Rewrite enabled). Where home is the default_controller. My working code is added below.

Code:
<?php  

class home extends CI_Controller {    
var $value1;    
var $value2;          

public function index($testname='')     {        
echo $testname;    
}          

public function test($testname1='')     {        
echo $testname1;     }
}  

?>
#2

[eluser]InsiteFX[/eluser]
Read the CodeIgniter Users Guide!
CodeIgniter Users Guide - Input Class
#3

[eluser]anishpsla[/eluser]
Hi, I didn't understand anything. I am new to codeigniter. I have some experiance in php. But I can't get anything usefull ftom the link. Please help me by posting sample code.

Also how Codeigniter know value after / is a function in controller or GET data ? That's the real problem for me. It always think www.mysite.com/index.php/value is another function in home controller.

But www.mysite.com/index.php/home/index/value will work. Because it's clear that in home controller after index function, value is a GET item.
#4

[eluser]InsiteFX[/eluser]
Code:
// controller/function/segment
// n is the position in the url like 2 or 3 for n.
$result = $this->uri->segment(n);
#5

[eluser]anishpsla[/eluser]
Good one. But Still I need to add default_controller in address. Without that I am getting 404 error. I need something like this.

www.mysite.com/test

I want to get value of test. Now this one is working www.mysite.com/default_controller/test.
#6

[eluser]InsiteFX[/eluser]
./application/config/routes.php
Code:
$route['test/(:any)'] = 'test/$1';

See:

CodeIgniter Users Guide - URI Routing
#7

[eluser]anishpsla[/eluser]
Sorry to say, I am still getting

404 Page Not Found
The page you requested was not found.


Code:
Class test extends CI_Controller
{
    public function index()
    {
        //$this->load->view('test_view');
        $data = $this->uri->segment(2);
        echo $data;
    }
}

:::: EDIT ::::
==========

Finally I got the answer just add

Code:
$route['(:any)'] = 'test/index/$1';
in routes.php




Theme © iAndrew 2016 - Forum software by © MyBB