简体   繁体   中英

Combining list view and a search form in Joomla Component 3.0

I'm trying to add a search form in my jobs view. It's supposed to be a list of all the available jobs along with a search form that filters out the result. The searh form consists out of checkboxes that will need to be prepopulated with the database data.

So I have a number of questions.

  1. Should I accomplish this by using filters or am I looking in the right direction?
  2. Where do I even start, I tried adding the code used for forms in the view below before but I don't even know which class I should inherit from.

Since "JModelList" in combination with getListQuery(). I tried a couple JForm etc and the inherited classes but then I get the following error: "Warning: Invalid argument supplied for foreach() in C:\\Users\\Nick\\Documents\\Dropbox\\yourstudent\\Development\\Live\\components\\com_jobs\\views\\jobs\\tmpl\\default.php on line 18"

I'm not having any troubles with creating a form, there are a couple of good examples for the crud operations needed on objects. But not when you either a) combine the list view with the form or b) need the form to act like a search form prepopulated with data.

I'm stuck at combining those 2 views essentially, I can't even test if my form fields etc are correct. Below is a snippet of the model jobs. Do you guys need any other code for helping me out here?

(This is my first question here, so bear with me and I'll try to adjust my question if needed.)

Code Snippet :

<?php

/* ------------------------------------------------------------------------
  # jobs.php - jobs Component
  # ------------------------------------------------------------------------
  # author    Breens Nick
  # copyright Copyright (C) 2013. All Rights Reserved
  # license   GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html
  # website   www.nick.breens.be
  ------------------------------------------------------------------------- */

// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import the Joomla modellist library
jimport('joomla.application.component.modellist');

/**
 * Jobs Model
 */
class JobsModeljobs extends JModelList {

    /**
     * Method to build an SQL query to load the list data.
     *
     * @return      string  An SQL query
     */
    protected function getListQuery() {
        // Create a new query object.
        $db = JFactory::getDBO();
        $query = $db->getQuery(true);
        // Select some fields
        $query->select('*');
        $query->from('#__yourstudent_jobs');

        return $query;
    }
}

?>

Thanks to a forum post on the Joomla Coding 3.0 subforum I got the answer.

Someone replied telling me that I should use filters in my case and base my component on the articles. I then searched for a good tutorial and then found this 2.5 based tutorial which still applies for 3.0

If anybody is interested I'll post my code below. (The model code remains the same.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM