简体   繁体   English

在Joomla Component 3.0中组合列表视图和搜索表单

[英]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. searh表单由复选框组成,这些复选框需要预先填充数据库数据。

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(). 由于“ JModelList”与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" 我尝试了几个JForm等和继承的类,但是随后出现以下错误:“警告:为C:\\ Users \\ Nick \\ Documents \\ Dropbox \\ yourstudent \\ Development \\ Live \\ components \\ com_jobs \\中的foreach()提供了无效的参数第18行的views \\ jobs \\ tmpl \\ default.php“

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. 但是当您要么a)将列表视图与表单组合在一起,要么b)不需要表单时,表单就可以像预填充数据的搜索表单一样工作。

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. 感谢Joomla Coding 3.0子论坛上的论坛帖子 ,我得到了答案。

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 然后,我搜索了一个不错的教程,然后发现了这个基于2.5的教程,教程仍然适用于3.0

If anybody is interested I'll post my code below. 如果有人感兴趣,我将在下面发布我的代码。 (The model code remains the same.) (模型代码保持不变。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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