Question

I would like to know if it's possible out of the box in CodeIgniter2 to create the urls without modifying routes.php for each controller's function like this:

  1. backend.website.com/ecommerce/products/edit/$id
  2. backend.website.com/ecommerce/currencies/form/$id
  3. backend.website.com/ecommerce/customers/partners/etc/$arg1/$arg2

My controllers/ecommerce.php for function products() is something like this:

public function products($page = 0, $items = NULL, $subview = NULL)
{

    if($subview != NULL){
        // This function is localhost/ecommerce/products/form/$some_id
        _remap($subview); // gives me an error


    }else{
    // Default view with pagination arguments $page and $items

    // Page settings
    $this->config->set_item('page_name',    'Products');
    $this->config->set_item('page_subname', 'Product listing table');

    // Request items
    $this->data['items'] = $this->ecommerce_model->get_products(array('page' => $page, 'items' => $items));

    // Creating a view
    $this->data['view'] = $this->load->view('/ecommerce/products/index', $this->data, TRUE);
    $this->load->view('/_templates/default/index', $this->data);

    }
}

public function _remap($method)
{
    if ($method == 'form')
    {
        $this->$method();
    }
    else
    {
        // SKIP
    }
}

I found that default _remap() function could be useful, but I do not understand how to use it with my function.

Does anyone have any experience with that and could provide some little sample?

==== UPDATED ====

Is it even possible for _remap() to work with another functions such as orders(), customers(), currencies(), etc... at the same time?

Était-ce utile?

La solution

You don't need to complicate things that much for something like this.

Just add another parameter to each of your methods, for example $action:

public function products($action = false, $page = 0, $items = NULL, $subview = NULL) { 

    switch($action) {

        case 'edit':
            // edit stuff here
            break;

        case 'something else':
           // other stuff
           break;
    }
    // etc...
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top