Searching

Why does the search work only on some of the tables?
I need it to work on a table where its main field is named "text" (not "name"). Where do I set that?
Thanks.

Comments

  • edited 11:18PM
    Set your display_field value for your module in your MY_fuel_modules.php file to 'text'. Additionally, you can add "filters" field names to your model. The fuel/modules/blog/models/blog_posts_model.php file has an example:
    http://www.getfuelcms.com/user_guide/libraries/base_module_model
  • edited 11:18PM
    Got it! Thx.
  • edited 11:18PM
    How do you add more UI elements for searching other than a generic text search field UI? Like several drop down lists or a combination of them? Or maybe an Advanced Search option.
  • edited 11:18PM
    You can add a filter property to your module. The property should contain an array of form_builder fields (similar to a model's form_fields method).
    The navigation module has something similar if you view the fuel/modules/fuel/config/fuel_modules.php

    The options for the navigation modules drop down are set in it's controller.
  • edited July 2011
    Ok, I tried to implement this and getting stuck. I see the Category UI filter drop down list on my list view but there's no list items being displayed.

    I built a controller to use an existing model.

    <?php

    require_once(FUEL_PATH.'models/module.php');

    class Drills extends Module {

    function __construct()
    {
    parent::__construct();
    }

    function items()
    {
    $CI =& get_instance();
    $CI->load->model('categories_model');
    if (!empty($this->filters['category_id'])) $this->filters['category_id']['options'] = $this->categories_model->options_list('id', 'name', array(), false);
    parent::items();
    }
    }

    What else am I missing? Can you provide a working example?
  • edited 11:18PM
    What does your module configuration parameters look like? Does it include a line like so:
    'filters' => array('category_id' => array('default' => 1, 'label' => 'Category'), 'type' => 'select'))
    Also, as an FYI, since you are in a controller, you don't need to use $CI =& get_instance() since the $CI object is the Drills controller
  • edited 11:18PM
    Here's my module config parms:

    $config['modules']['drills'] = array(
    'module_name' => 'Drills',
    'model_location' => 'drills',
    'display_field' => 'categories.name',
    'default_col' => 'categories.name',
    'default_order' => 'asc',
    'filters' => array('category_id' => array('default' => 1, 'label' => 'Category', 'type' => 'select')),
    'instructions' => 'Here you can manage your drills'
    );
  • edited 11:18PM
    Do any values appear if you do a print_r on $this->filters['category_id']['options'] in the controller?
  • edited 11:18PM
    none
  • edited 11:18PM
    I'm still stuck on how to implement drop down list box as well as customizing the search fields. Where is the best place to start my own custom search using some basic layout.

    Type [list box] Status [lsit box]
    Last Name [text field] First Name [text field]
    City [text field] State [list box]
    Active [checkbox]

    I'd like this to replace the existing one line - [text field] Search button implementation.
  • edited 11:18PM
    If $this->categories_model->options_list('id', 'name', array(), false); returns an empty array, then the options parameter will also be empty and you will not see anything in the dropdown. Do you have any categories in the database? You can further debug the query by using the debug_query method after it is called like so:
    ... if (!empty($this->filters['category_id'])) $this->filters['category_id']['options'] = $this->categories_model->options_list('id', 'name', array(), false); $this->categories_model->debug_query(); ...
  • edited 11:18PM
    Would it be possible to post a working example using the existing Authors, Articles and Categories module? I think it would help others than myself see a working example of customizing the search fields.
  • edited 11:18PM
    I can put it on the list, but unfortunately, it probably won't be for a while. However, in the meantime, you can send me your model(s) and SQL and I can take a look at it for you (email is in my profile).
  • edited 11:18PM
    Does anyone have any examples of providing multiple search fields within the admin UI?
  • edited 11:18PM
    I'm trying to do a similar thing with a simple module in the Fuel admin as well. I have a field called "status" with 2 options: open and sent stored as enum and a field called "type" with multiple options stored as enum in the corresponding table that the model is associated with and would like to expose these as filters on the list view in Fuel.

    I have this so far in MY_fuel_modules.php configuration:

    $config['modules']['gift_certificates'] = array( 'module_name' => 'Gift Certificates', 'module_uri' => 'gift_certificates', 'model_name' => 'gift_certificates_model', 'model_location' => 'store', 'table_headers' => array( 'id', 'gift_certificate_number', 'type', 'status', 'transaction_id', 'transaction_date', 'customer_zip' ), 'display_field' => 'type', 'permission' => 'gift_certificates', 'instructions' => lang('module_instructions_default', 'gift certificates'), 'archivable' => FALSE, 'nav_selected' => 'gift_certificates', 'hidden' => TRUE, 'table_actions' => array('view'), 'item_actions' => array('view'), 'rows_selectable' => FALSE, 'filters' => array ( 'type' => array('default' => 0, 'label' => lang('gift_certificate_type'), 'type' => 'select'), 'status' => array('default' => 0, 'label' => lang('gift_certificate_status'), 'type' => 'select') ) );

    The filters look correctly defined, no? I am experiencing the same empty dropdown issue jmobile mentioned. I am NOT using a controller for the module, so do I need to add that in as demonstrated by jmobile's example or can Fuel "discover" the allowed values for the two columns and automatically populate the dropdown with those values?

    Thanks,
    Erik
  • edited 11:18PM
    The select is populated if you add an options array to your config though right?

    For example this works for me:
    $config['modules']['posts'] = array( 'filters' => array( 'post_type' => array( 'default' => 'blog', 'label' => 'Post type', 'type' => 'select', 'options' => array( 'blog' => 'Blog', 'story' => 'Story' ) ), 'title' => array( 'default' => 'blog', 'label' => 'Post type', 'type' => 'select', 'options' => array( 'one' => 'Test one', 'two' => 'Test two' ) ) ), );

    Just had a quick look and I don't see anywhere that it automatically pulls values to build the options array. Maybe I missed it. I'm looking in fuel's module::items() controller method.
    Dave's comment above is setting the options in a controller with options_list(). You'll not be able to get at your model in the config files to do that there. Might be able to do it in a hook if you don't want to write a controller. I've done that with js_controller_params[] before.
  • domdom
    edited 11:18PM
    Hi there,

    I am trying the same thing as Lance, but it only seems to work for the first filter - I get PHP errors for the 2nd filter:

    A PHP Error was encountered
    Severity: Warning
    Message: strtolower() expects parameter 1 to be string, array given
    Filename: models/base_module_model.php
    Line Number: 374

    Both fields are enums. And it only seems to work if they are in the model (not in the config file).

    public $filters = array( 'customer_type' => array( 'default' => 'res', 'label' => 'Customers', 'type' => 'select', 'options' => array( 'res' => 'Residential', 'sme' => 'SME' ), ), 'shape' => array( 'default' => 'flat', 'label' => 'Shape', 'type' => 'select', 'options' => array( 'flat' => 'Flat', 'bump' => 'Bumpy', 'spike' => 'Spikey', ) ) ); // filters to apply to when searching for items

    Any ideas?
  • edited 11:18PM
    Is there possibly an error in how your are nesting your arrays for the module version? Can you post that code as well.
Sign In or Register to comment.