I have a domain and id is coming in that domain like this
http://www.test.com/update_record_row/id/6356/
I want id value from the domain without passing ? instead of / in (query string)
Using $this->uri->segment() you get the URL parameter
$this->uri->segment(1)
For more ..https://www.codeigniter.com/userguide3/libraries/uri.html
ID
public function update_record_row($id)
{
echo "Id is :".$id;
}
or
Use URI segment
// if URL -http://www.test.com/update_record_row/id/6356/
$id = $this->uri->segment(3);
// if URL -http://www.test.com/update_record_row/6356/
$id = $this->uri->segment(2);
Use $this->uri->segment() to retreive passed value through url
If URL is http://www.test.com/update_record_row/id/6356/
You should use $this->uri->segment(3);
Codeigniter has awesome userguide.Just check this in in uri part.
https://www.codeigniter.com/userguide3/libraries/uri.html#uri-class
Related
My URL is:
http://localhost/working/myapp/login/index/user_id=&user_email=shashankbhat11%40gmail.com&sig=%C3%86%C3%B1z%C3%BD-o6%C2%B6%01%C2%8A%C3%81%C2%A6%C2%A7z%C2%A1%C3%962%3E:%C3%83F%C2%90M%C2%99%C3%BD%C3%A7%C2%A1O%18%C3%83F%3E
How to retrieve user_email and sig values only from this URl in codeigniter controller, i tried this
$var1 = $this->uri->segment(4);
echo $user_email;
die;
and it is giving me an output as below,
user_id=&user_email=shashankbhat11%40gmail.com&sig=%C3%86%C3%B1z%C3%BD-o6%C2%B6%01%C2%8A%C3%81%C2%A6%C2%A7z%C2%A1%C3%962%3E:%C3%83F%C2%90M%C2%99%C3%BD%C3%A7%C2%A1O%18%C3%83F%3E
but I need only the value of user_email i.e shashankbhat11%40gmail.com in the variables var1 and var2 variable should contain %C3%86%C3%B1z%C3%BD-o6%C2%B6%01%C2%8A%C3%81%C2%A6%C2%A7z%C2%A1%C3%962%3E:%C3%83F%C2%90M%C2%99%C3%BD%C3%A7%C2%A1O%18%C3%83F%3E which is the sig part.
Try this
$var1 = $this->input->get('user_email');
echo $user_email;
die;
The the specified URL is not formatted correctly. You need to put "?" in the URL to access URL values as get. See the question mark in the URL below.
http://localhost/working/myapp/login/index/?user_id=&user_email=shashankbhat11%40gmail.com&sig=%C3%86%C3%B1z%C3%BD-o6%C2%B6%01%C2%8A%C3%81%C2%A6%C2%A7z%C2%A1%C3%962%3E:%C3%83F%C2%90M%C2%99%C3%BD%C3%A7%C2%A1O%18%C3%83F%3E
Once you formatted the URL you can use below code to access it:
$user_id = $this->input->get('user_id');
$user_email = $this->input->get('user_email');
my url is
http://localhost/helpinghand_web/home/userAutologin?tval=Eo7TIhTJqQnfysn8mwu2nXOQ0yJvY36hprJ99GJH9NBZHTh1LU&page=profile
there are two parameter tval and page how can i get it.
following are not working..
$var=$_GET['tval'];$var=$this->input->get('tval');
use this
$tval = $this->input->get('tval');
$page = $this->input->get('page');
You can use this:
$params = $this->input->get(null, true);
to get all the params passed and then use:
$params['tval']
You can use $tval = $this->input->get('tval') for get single data & $tval = $this->input->get() for get all date in singel variable in array format.
I managed the query you can use it.
If you call www.example.com?tval=1100, it will echo 1100, provided the Home
controller is routed correctly.
You can also use the http://ellislab.com/codeigniter%... to get these parameters.
For your query: $this->input->get('tval', TRUE);
I'm working on a CodeIgniter project and trying to get the id of this URI:
http://example.com/myDomain/index.php/public/calendar/gestionEvent?id=c2pnumqnqr0dg9tgmaklho5280#google.com
I want the controller to delete or update the event using this ID.
I tried $this->uri->segment(4)but it doesn't seem to work and doesn't show anything.
try this :
$id = $this->input->get_post('id');
echo $id;
in cotroller
$id = $this->input->get('id');
$data['id'] = $id ;
you can not use uri segment here
ex:-http://example.com/index.php/news/local/metro/crime_is_up
here you can use uri segments
The segment numbers would be this:
1.news
2.local
3.metro
http://codeigniter.com/user_guide/libraries/uri.html
UPDATE
if you want to get only the id with out #google.com you can simply use explode()
$id_string = $this->input->get('id');
$id_string_exp = explode("#", $id_string);
$id = $id_string_exp[0];
Then use
$id = $this->input->get('id');
$this->uri->segment(4) will work only if the url is in the form of segments like
http://example.com/myDomain/index.php/public/calendar/gestionEvent/c2pnumqnqr0dg9tgmaklho5280#google.com
Then you will get id using "URI segments".Thanku.i hope this helps you friend
I want to pass a url like http://example.com/test?a=1&b=2 in url segment of codeigniter.
I'm trying to pass something like this http://myurl.com/abc/http://example.com/test?a=1&b=2 and get the "http://example.com/test?a=1&b=2" url. What should be the best way to do this?
Set your URI protocol to REQUEST_URI in application/config/config.php , like this:
$config['uri_protocol'] = 'REQUEST_URI';
then use GET method:
$this->input->get('a');
EDIT:
Since http://example.com/test?a=1&b=2 is not encoded URL, it isn't possible. So first, I would encode URL with urlencode function like this:
urlencode('http://example.com/test?a=1&b=2');
it returns something like: http%3A%2F%2Fexample.com%2Ftest%3Fa%3D1%26b%3D2
So I would pass the URL like this:
http://myurl.com/?url=http%3A%2F%2Fexample.com%2Ftest%3Fa%3D1%26b%3D2
then get an example URL with GET method.
$this->input->get('url');
Use this technique to get the URL
$url = "http://example.com/test?a=1&b=2";
$segments = array($controller, $action, $url);
echo site_url($segments);
// or create a anchor link
echo anchor($segments, "click me");
Pass urlendode()'d URL in segment and then decode it with own (MY_*) class:
application/core/MY_URI.php:
<?php
class MY_URI extends CI_URI {
function _filter_uri($str)
{
return rawurldecode(parent::_filter_uri($str));
}
}
// EOF
This is my code in routes.php
$route['default_controller'] = "admin";
$route['(:any)'] = $route['default_controller']."/index/";
This is my url:
http://myserver.net/visio/jklmn
But i cant to get the value in index() in admin controller.
I want to get the value jklmn in admin controller.If there is any mistake in my routing code.
This is my index() code;
function index($key = ""){
if(isset($key)){
$newkey = $key;
$data['key'] = $key;
$this->load->view('index',$data);
}else{
redirect('admin/index_login');
}
}
When i taking above link in browser i get the error message below:
Not Found
The requested URL /visio/jklmn was not found on this server.
Use this routing rule:
$route['(:any)/(:any)'] = $route['default_controller']."/index/$2";
which will match a URL with 2 segments (each containing any character) and pass the second match as $2.
You can also pass the first match, just use $1.