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() );
Related
How can set auto route 404 page of frontend and backend different ? I have searched a long time but i have not found perfect answer.
Btw, can we make the same for error 500 ?
You can easily do it by using conditional statement.
go to application/config/routes.php and remove:
$route['404_override'] = '';
After that add the following code.
$req_uri = $_SERVER['REQUEST_URI']; // $req_uri = /myproject/backend
$req_uri = explode('/', $req_uri);
$req_uri = $req_uri[2]; // $req_uri[2] = backend
if($req_uri == 'backend'){
$route['404_override'] = 'Backend_error'; // Not found controller for backend
}else {
$route['404_override'] = 'Frontend_error'; // Not found controller for frontend
}
You can use echo statement to analyze further. and then do more stuff accordingly.
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.
I'm implementing redirect to previous page after login and logout.
So in each methods of controller I've saved session like as follow.
$this->session->set_userdata('previous_page', current_url());
And after successful login and logout, I'm calling a library method as follows.
function redirect_to_previous_url() {
$url = base_url();
if($this->_CI->session->userdata('previous_page')) {
// Get previous_url
$url = $this->_CI->session->userdata('previous_page');
$this->_CI->session->unset_userdata('previous_page');
}
return $url;
}
But Its redirecting to base_url of the site. After checking the session value Its showing not found image path but not what I've saved it before.
I'm not able to find out what is the problem behind this.
Please help me to rectify and the work would be appreciated
Try this..
function redirect_to_previous_url() {
$url = base_url();
if($this->_CI->session->userdata('previous_page')) {
// Get previous_url
$url = $this->_CI->session->userdata('previous_page');
$this->_CI->session->unset_userdata('previous_page');
return $url;
}
return $url;
}
I would ensure the session was set. Like this;
if($this->_CI->session->userdata('previous_page')) {
show_error('The session is set');
}
If you don't see the error, the session isn't set. Then you know this isn't where the problem lies.
No need to store Previous URL in session.
In core php you can get previously visited URL in following server variable
$_SERVER['HTTP_REFERER'];
Same can be achieved in CodeIgniter as
$this->load->library('user_agent');
echo $this->agent->referrer();
I want to remove empty query vars from a url in my controller. my url is /search?qi=yoga&q= notice that q is empty. Sometimes qi will be empty. How can I remove these? Seems like a simple issue, but I can't seem to find a elegant solution.
function search() {
$qi = Request::get('qi');
$q = Request::get('q'));
$results = getResults($qi, $q);
return View::make('search.results', compact('results'));
}
You could do that in the next request, but you would have to Redirect::refresh() or Redirect::to($url) with a clean url, like
$items = Redirect::query();
$items = $this->removeEmptyItems($items); /// you'll have to create this method!
return Redirect::route('your.current.route', $items);
As you can see, this will clean up your url, but it requires a new request.
But this looks like something you have in your current request and I'm afraid Laravel cannot change a URL in the browser for you. If this is a form submission query, Javascript can help you prevent from sending those empty queries:
$('form').submit(function(){$('input[value=]',this).remove();return true;})
I suggest this:
function search()
{
$search = array_filter(Request::all()); // or only(..) / except(..)
$results = getResults($search);
}
I'm just trying to set up terms and conditions page after a successful login. All seems to to working well. I am getting the post data through the form which I have placed in CMS Page with identifier 'general-conditions'. The problem is only in the
header('Location: '.Mage::getUrl('general-conditions'));
If I comment out this line.. page loads properly but if I don't it gets caught in infinite loop.
Could anyone please help me, that's the only thing left and I've spent a lot of time on it.
Thanks in advance.
<?php
Class Rik_Terms_Model_Observer{
public function checkGeneralTerms(){
if (Mage::helper('customer')->isLoggedIn()) {
$id = Mage::getModel('customer/session')->getId();
$customer = Mage::getModel('customer/customer')->load($id);
$customerData = $customer->getData();
$groupId = Mage::helper('customer')->getCustomer()->getGroupId();
$groupName = Mage::getModel('customer/group')->load($groupId)->getCode();
$storeId = Mage::app()->getStore()->getId();
if($customer->getGeneralTerms()=='0'){
$pageIdentifier = Mage::getModel('cms/page')->checkIdentifier("general-conditions", $storeId);
if ($pageIdentifier){
header('Location: '.Mage::getUrl('general-conditions')); // problem
die();
}
}
}
}
}
Found later, it was actually conflicting with extended version of my CMS Module.