How to add a link on a column.

edited May 2012 in Modules
I am trying to make a pdf file download
$this->data_table->add_action('file', 'assets/pdf/order/{file}', 'url');

but i get url with no file name like this:
http://localhost/ch/invoice/admin/assets/pdf/order/_______ filename mising here

what is the problem?

Or I should try other way to get the file downloaded from the datatable.

Comments

  • edited 6:28PM
    Is the field "file" one of the columns of data being used?
  • edited 6:28PM
    yes the field is file in database.
  • edited 6:28PM
    OK, but is it in the returned data set being rendered by the Data_table class. The reason I ask is because it's required to fill in that {file} value. The rendering of that action is done in the Data_tables "_render_actions" method around line 718.
  • edited May 2012
    Ok. I have now converted my module as advanced module and now I have problem on route.

    I have added a route on my module as so:
    $route[FUEL_ROUTE.'invoice/orders/print_order'] = 'invoice/orders/print_order';

    $route[FUEL_ROUTE.'invoice/orders/print_order/(.*)'] = 'invoice/orders/print_order/$1';
    The first one routes correctly to controller but if I give a parameter id on that controller like so:
    invoice/orders/print_order/4
    it gives 404.

    On my config/invoice_fuel_modules.php I have set the table_actions like so:
    'table_actions' => array('EDIT', 'PRINT' => 'orders/print_order/{id}')
    How to solve this.
  • edited May 2012
    Is the URI path invoice/orders/print_order/4 what you are wanting? What if you use this:
    'table_actions' => array('EDIT', 'PRINT' => fuel_url('invoice/orders/print_order/{id}'))
  • edited May 2012
    I have done same like this and it gives 404 when
    'PRINT' => fuel_url('invoice/orders/print_order/{id}')
    but if I use:
    'PRINT' => fuel_url('invoice/orders/print_order')
    it works fine.

    I am giving the whole structure of my site:
    controller:
    invoice/controllers/orders.php

    require_once(FUEL_PATH.'/libraries/Fuel_base_controller.php');

    class Orders extends Fuel_base_controller {

    function __construct()
    {
    parent::__construct();
    $this->load->library('asset');
    $this->load->helper('ajax');
    }
    function index(){
    //index actions here
    }

    function print_order($id = NULL){
    // if url is: admin/invoice/orders/print_order //this method is executed

    // if url is: admin/invoice/orders/print_order/{id} //this gives 404
    echo "I am inside print_order";
    }

    }
  • edited 6:28PM
    config/invoice_fuel_module.php

    $config['modules']['invoice_orders'] = array(
    'preview_path' => 'invoice/order/{slug}',
    'sanitize_images' => FALSE, // to prevent false positives with xss_clean image sanitation
    'module_name' => 'orders',
    'module_uri' => 'invoice/orders',
    'model_name' => 'orders_model',
    'model_location' => 'invoice',
    'display_field' => 'order_no',
    'instructions' => lang('module_instructions_orders', 'invoice'),
    'archivable' => TRUE,
    'nav_selected' => 'orders',
    'permission' => 'orders',
    'js' => array('invoice' => 'OrdersController.js'),
    'table_actions' => array('EDIT','PRINT' => fuel_url('invoice/orders/print_order/{id}'),'DELETE'),
    );
    config/invoice_routes.php

    $invoice_controllers = array('orders','clients','agencies');

    foreach($invoice_controllers as $c)
    {
    $route[FUEL_ROUTE.'invoice/'.$c] = FUEL_FOLDER.'/module';
    $route[FUEL_ROUTE.'invoice/'.$c.'/(.*)'] = FUEL_FOLDER.'/module/$1';
    }

    $route[FUEL_ROUTE.'invoice/orders/print_order'] = INVOICE_FOLDER.'/orders/print_order';
    $route[FUEL_ROUTE.'invoice/orders/print_order/(.*)'] = INVOICE_FOLDER.'/orders/print_order/$1';

    $route[FUEL_ROUTE.'invoice/dashboard'] = INVOICE_FOLDER.'/dashboard';
  • edited 6:28PM
    Are you able to navigate to the non routed URL?
    invoice/orders/print_order/4
    Instead of:
    fuel/invoice/orders/print_order/4
  • edited May 2012
    No!
    This is main problem. I appreciate your availability.

    I can view if I remove /4
  • edited May 2012
    Have you added "invoice" to the "modules_allowed" config array in MY_fuel.php (easy step to forget)?
  • edited May 2012
    yes. I have added "invoice" on config array

    for temporary solution I added a method on modules/fuel/controllers/module.php

    function print_item($id = NULL){
    // actions here
    }
    still I am waiting for permanent solution on advanced custom modules to add methods and parameters but without 404.
    like:
    module_name/method/param1/param2
  • edited 6:28PM
    I think the first part of your routes statement is causing the problem. What if you remove the first part of your routes just to see if it works:
    foreach($invoice_controllers as $c) { $route[FUEL_ROUTE.'invoice/'.$c] = FUEL_FOLDER.'/module'; $route[FUEL_ROUTE.'invoice/'.$c.'/(.*)'] = FUEL_FOLDER.'/module/$1'; }
  • edited 6:28PM
    I figured it out. The problem was solved using _remap. Here is what I have done incase other come to this difficulties.

    here is the code:

    public function _remap($method, $params = array())
    {
    if (method_exists($this, $method))
    {
    return call_user_func_array(array($this, $method), $params);
    }
    show_404();
    }
    now you are good to do stuff like codeigniter way:
    module_name/method/param1/param2
Sign In or Register to comment.