Jump to content

Recommended Posts

I have a form that when submitted goes to "products/search/"

 

This is the method that it directs too. 

 

    function search($searchCat = NULL, $searchString = NULL)
    {
        if($this->input->post('searchSubmit'))
        {
            $searchCat = $this->input->post('searchCat');
            $searchString = $this->input->post('searchString');
        }
        
         //Get the base URL and assign it to a variable
        $aData['base_url'] = base_url();
        
        //Run the getProductsBySearch function in the product model and pass two parameters
        //This returns the search results
        $aData['query'] = $this->ProductModel->GetProductsBySearch($searchCat, $searchString);
        
        //Run the getBestSellers function in the product model
        //This returns the top 3 best selling products
        $aData['bestsellers'] = $this->ProductModel->getBestSellers();
        
        //Pass the best sellers data to the best sellers view and save it in a variable
        $aData['rightSidebar'] = $this->load->view('products/bestsellers', $aData, true);
       
        //Get breadcrumb trail and assign it to a variables
        $aData['breadcrumbs'] = create_breadcrumb();
        
        //Pass the data to the left sidebar view and save it in a variable
        $aData['leftSidebar'] = $this->load->view('products/leftsidebar', $aData, true);
        
        //Load the cart library
        //$this->load->library('cart');
        
        //Get the contents, total amount and total items of the cart
        $aData['cart'] = $this->cart->contents();
        $aData['cart_total'] = $this->cart->total();
        $aData['total_items'] = $this->cart->total_items();
        
        //Load the layout library
        $this->load->library('layout');  
        
        //Get the header and footer and save them in variables
        $aData['header'] = $this->layout->pageHeader($aData);
        $aData['footer'] = $this->layout->pageFooter();
        
        //If more than one row is returned load multiple product view otherwise load single view
        if ($aData['query']->num_rows() > 1)
        {
            $aData['content'] = $this->load->view('products/products_layout', $aData, true);
        } 
        else
        {
            $aData['content'] = $this->load->view('products/product_layout', $aData, true);
        }
        
        //Load the three column layout view
        $this->load->view('layout/main/three_col', $aData);
        
    }

 

Then in my views file I have the following lines. 

 

$route['products/search/'] = "products/search/";
$route['products/search/(:any)/(:any)'] = "products/search/$1/$2";

 

It works fine when the URL is something like "products/search/all/03241/" but not when it's just "products/search". 

 

Does anyone know what I'm doing wrong?

Link to comment
https://forums.phpfreaks.com/topic/252572-codeigniter-routes-problem/
Share on other sites

Hi c_pattle,

 

 

Then in my views file I have the following lines. 

 

$route['products/search/'] = "products/search/";
$route['products/search/(:any)/(:any)'] = "products/search/$1/$2";

 

It works fine when the URL is something like "products/search/all/03241/" but not when it's just "products/search". 

 

Does anyone know what I'm doing wrong?

 

This should not be in your view file.  If this is in your view file, then it's referring to a local variable, not the config file variable. 

 

I would recommend using _remap.  I will not explain what it is here in this post, but if you give me until tomorow, my post will publish.  It will teach you to use it, and I have a very simple example in which you will be able to modify it for your needs. 

 

I regret not posting it today, as I had no time to finish it.  I will come back once it's published.  (The latest will be by tomorrow)

If you can't wait that long, then go ahead and google _remap.

  • 3 months later...

I was also the same problem and I fixed it by a small change in URI.php page in the system/core

 

In my checking I feel like it was due to a small bug in codeigniter. Anyway I am not an expert.

 

Anyway I fixed it.

 

I was a problem with codeigniter url rewriting.

 

I have to go to www.abc.com/catalog/product/4354

 

when using the url www.abc.com/samsung_galaxy_y

 

I have explained it in my blog myphplibrary.blogspot.in

 

http://myphplibrary.blogspot.in/2012/03/codeigniter-routing-issue-fixation-url.html

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.