In my view form,
$encrypted_string = $this->encrypt->encode($list['id']);
where $list['id'] is auto increment. and URL,
Delete
In Controler,
$id1 = $_GET['id'];
$id = $this->encrypt->decode($id1);
In this $id i get decoded value for some value not for all value,please help me..Thank you.
Instead of
$id1 = $_GET['id'];
Try
$id1 = $this->input->get('sid');
Remember that the param you are passing by query string should have the same name in your controller.
Also, in config.php change
$config['uri_protocol'] = 'auto';
Try different values until one of them works for you.
Related
I am working on codeigniter. Controller name is "project" and 4 functions are there.."get_city_data", "get_store_data", "get_currency", "get_description".
Parameters I am passing in above 2 functions are - get_city_data($state, $city), get_place_data($state, $city, $store).
So on browser to render these functions I am using the urls respectively as-
http://localhost/project/get_city_data/state1/city1
I want to change the urls like
http://localhost/state1/city1
In routes.php if I define a route like this
$route['(:any)/(:any)'] = 'project/get_city_data/$1/$2' then it reflects for all other functions as well but I want to change urls for these 2 functions only.
Also I do not want to use _remap function as it doesn't go well with my needs.
Can anybody help me in this?
ThankYou
I suggest you to check in the database at first, then determine the routes required. Here is my answer for your requirement.
In your routes.php, try this code:
require_once( BASEPATH . 'database/DB' . EXT );
$url_source = $_SERVER['REDIRECT_URL'];
$arr_url = explode("/", $url_source);
$state_name = $arr_url[3];
$city_name = $arr_url[4];
$store_name = $arr_url[4];
$db = & DB();
//Let say grab 3 columns to be check
$db->select('state_name, city_name, store_name');
if(!empty($state_name)):
$db->where('state_name', $state_name);
endif;
if(!empty($city_name)):
$db->where('city_name', $city_name);
endif;
if(!empty($store_name)):
$db->where('store_name', $store_name);
endif;
$query = $db->get('table', 1);
$obj = $query->row();
if ($obj):
$route["$obj->state_name/$obj->city_name/$obj->store_name"] = "project/get_city_data/$state_name/$city_name/$store_name";
endif;
You can try by this url to test:
http://localhost/state_name/city_name/store_name
I got it solved using regex.
In routes.php i wrote
$url_source = $_SERVER['REQUEST_URI'];
if(!(preg_match('%^/project/get_description\?state=[a-zA-Z_-]*%', $url_source) || preg_match('%^/project/get_currency\?state=[a-zA-Z_-]*%', $url_source))){
if(!preg_match('%^\/[a-zA-Z_-]+\/[a-zA-Z_-]+\/[a-zA-Z_-]+$%', $url_source)){
$route['(:any)/(:any)'] = 'project/get_city_data/$1/$2';
}else{
$route['(:any)/(:any)/(:any)'] = 'project/get_store_data/$1/$2/$3';
}
}
This way I was able to route for particular functions.
The session value lost after the redirect. I m redirecting from pay_order method to do_payment method. when I print the session value in do_payment method its return false. just simple calling the do_payment method display the session value. Please help what is the problem with redirect..?
function pay_order($order_id)
{
$this->load->helper('url'); //loading url helper
$this->load->library('session');//loading session lib
$this->load->library('cart'); //loading cart lib
$this->load->helper('form');//loading form helper
$output = $this->cart->contents();// getting data from cart.
$output = $this->sort_array($output);// sorting the array
$list['data'] = $output;
$list['order_id'] = $order_id;
$this->session->set_userdata('abc', $list);// setting the session
redirect('checkout/do_payment'); // redirecting to do_payment
}
function do_payment()
{
$this->load->helper('url'); //loading url helper
$this->load->library('session'); //loading session library
$arr = $this->session->userdata('abc');// getting session data in $arr
var_dump( $arr );// return false value.
//$this->load->view('order/pay_through_gateway');
}
when I redirect from pay_order method the session is not available in do_payment method. why?
There is a problem, check the line in the method pay_order() where you are setting the session.
$list['order_id'] = $order_id
$this->session->set_userdata('abc', $list);// setting the session
Before that line you have missed semicolon. And everything looks fine.
Update:
There is no error as I think, check whether you may have null value while you are storing the values in session. And check the values by following code in do_payment() method.
function do_payment(){
$this->load->library('session'); //loading session library
$arr = $this->session->userdata('abc');// getting session data in $arr
print_r( $arr );// print the $arr content
}
Change this:
$list['order_id'] = $order_id
To this:
$list['order_id'] = $order_id;
You have a semicolon missing. You do not see any errors because of the redirection.
How to pass get variable from my view to the controller and to the model also and load to my view again
without the use of form like
$jcid= $row['id']; // this id from other table which is parent.
$s = "SELECT * FROM `jobs` WHERE job_cat=$jcid";
$re = mysql_query($s);
$no = mysql_num_rows($re);
echo $no;
Thanks in advance
Amit
Instead of using get param use like this
This can be your form url
http://example.com/index.php/news/local/metro/crime_is_up
$this->uri->segment(3); // Will give you news
Like wise in place of 3 replace with 4 will give you metro and so on. You can access this in controller.
Uri class in the codeigniter
http://ellislab.com/codeigniter/user-guide/libraries/uri.html
First use
$this->load->helper('url');
And then
$data['$jcid'] = $this->uri->segment(3);
How to go with this url localhost/pitch/action/task/1 ?
1 = pitch id
please answer this. thank you
this is my code controller.
public function insert_task(){
$this->load->model("save");
$data['pitch_id'] = $this->input->post('pitch');
$data['date'] = $this->input->post('date');
$data['name'] = $this->input->post('name');
$data['description'] = $this->input->post('description');
$task = $this->save->insert_task_to_db($data);
if($task){
header('location:'.base_url()."action/task".$this->index());
}
}
You can use
redirect('action/task/'.$this->index(),'refresh');
this code will reload the page and redirect to the desired url.
Please let me know if you face any problem.
codeigniter provides redirect, like:
redirect( base_url() . 'action/task/' . $this->index() );
i already make two changes in config file to enable the $_GET array as
$config['uri_protocol'] = "PATH_INFO";
$config['enable_query_strings'] = true;
but whenever i try tow run my code as http://example.com/controller/function/$demo=demo
it redirected towards the default controller
Enabling query strings in CodeIgniter means that you're using the query string to pass in the controller and function instead of them being parsed from the PATH INFO.
If you want to use the default system for determining what controller and function to use, you do not want to set $config['enable_query_strings'] to true.
This previous SO post covers how to enable teh $_GET array in CodeIgniter: Enabling $_GET in codeigniter
I think that's what you're trying to do.
You also have to set controller and function triggers from config:
$config['enable_query_strings'] = TRUE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';
So once query string is enabled, you can access it like this:
http://example.com/index.php?c=controller&m=function&demo=demo