控制器和模板(如何正确过滤结果或通过后端提供参数?) [英] Controllers and Template (how to filter results correctly or give arguments via backend?)

查看:73
本文介绍了控制器和模板(如何正确过滤结果或通过后端提供参数?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我手上出现了以下问题.我的网站有一个扩展名(由我写),用于模拟一个停车场.有车辆(德语:Fahrzeug对此表示怀疑,将来在我的代码/帖子中使用德语时也是如此),并且有VCategories(FzKategorie).它们以N-1关系站立,这意味着N辆车全部具有1类最小/最大.我为该任务创建了第二个插件,并为其指定了默认操作:ListByCateory.现在,我被困在何时过滤我的结果,何时传递应该显示类别项目的参数以及如何使控制器和流体模板变得更有意义的问题上.我阅读了整个(过时的和//缺少的代码)扩展程序开发文档,但我还不能进一步.

I got following problem on my hand. My Site has a extension (written by me) which modelates a vehicle park. There are vehicles (german: Fahrzeug sry about that and in the future when I use german in my code/post) and there are VCategories (FzKategorie). They stand in N-1 relation , meaning N vehicles have all 1 Category min/max. I created a second plugin for the task, and gave it the default action: ListByCateory. Now I'm stuck WHEN to filter my restults, WHERE to hand over arguments which Category items should be shown and HOW to make sense of controllers and Fluid Templates in general. I read up on the whole (outdated and missing //code) extension developiong documentation and I can't get further, yet.

<?php
namespace Y7group\Y7Fahrzeugdatenbank\Controller;
/**
* FahrzeugController
*/
class FahrzeugController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
    /**
     * fahrzeugRepository
     *
     * @var \Y7group\Y7Fahrzeugdatenbank\Domain\Repository\FahrzeugRepository
     * @inject
     */
    protected $fahrzeugRepository = NULL;
    [...]
    /**
     * action listByCategory
     *
     * @return void
     */
    public function listByCategoryAction(){//\Y7group\Y7Fahrzeugdatenbank\Domain\Model\FzKategorie $cat) {
        $vehicles = $this->fahrzeugRepository->findAll(); // get all vehicles
        $this->view->assign('category', 1); // here assign another variable like $cat.
        $this->view->assign('vehicles', $vehicles); // hand over the query results
    }
}

这是我的模板:

<f:layout name="Default" />
<f:section name="main">
<h1>Alle Fahrzeuge Category</h1>
<f:flashMessages renderMode="div" />
<table  class="tx_y7fahrzeugdatenbank" >
<tr>
    <th><f:translate key="tx_y7fahrzeugdatenbank_domain_model_fahrzeug.name" /></th>
    <th><f:translate key="tx_y7fahrzeugdatenbank_domain_model_fahrzeug.beschreibung" /></th>
    <th><f:translate key="tx_y7fahrzeugdatenbank_domain_model_fahrzeug.bild" /></th>
    <th><f:translate key="tx_y7fahrzeugdatenbank_domain_model_fahrzeug.datenblatt" /></th>
</tr>

<f:for each="{vehicles}" as="fahrzeug">
<f:if condition="{category}=={fahrzeug.category}">
    <tr>
        <td><f:link.action action="show" arguments="{fahrzeug : fahrzeug}"> {fahrzeug.name}</f:link.action></td>
        <td><f:link.action action="show" arguments="{fahrzeug : fahrzeug}"> {fahrzeug.beschreibung}</f:link.action></td>
        <td><f:image src="{fahrzeug.bild.originalResource.originalFile.uid}" alt="{fahrzeug.beschreibung}" width="300"/></td>
        <td><f:link.action action="show" arguments="{fahrzeug : fahrzeug}"> {fahrzeug.datenblatt.originalResource.name}</f:link.action></td>
    </tr>
</f:if>
</f:for>

谁能说明我的观点,谁能帮助我?直到明天我都会做这个工作. :_(

Who get's my point and who is able to help me? I have do get this working till tomorrow. :_(

推荐答案

仅从数据库中获取与您的类别匹配的车辆怎么样?如果您正确设置了TCA,而不是

How about just getting the vehicles from the DB that matches your category? If you set up your TCA properly, instead of

$vehicles = $this->fahrzeugRepository->findAll();

尝试

$vehicles = $this->fahrzeugRepository->findByCategory($category);

您很可能希望将$category配置为可配置的.让我知道,如果您需要帮助.

You most likely want to make the $category configurable. Let me know, if you need help with that.

这篇关于控制器和模板(如何正确过滤结果或通过后端提供参数?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆