猿问

Joomla Subform field

我们继承了一个Joomla项目,需要为产品图像实现一个重复字段。


我们很难理解如何在数据库中实现它。有没有一些命名约定来告诉Joomla使用什么表/外键?


我们在 xml 文件中提供了以下内容:


<?xml version="1.0" encoding="UTF-8"?>

<field

    name="gallery_images"

    type="subform"

    label="Gallery Images"

    description="Images for the gallery"

    multiple="true"

    min="1"

    max="10"

    >

    <form>

        <field

            name="image_url"

            type="media"

            label="Image"

            />

    </form>

</field>

然后,我们将 is 拉入表单 edit.php 文件,如下所示:


<div class="control-group">

    <div class="control-label"><?php echo $this->form->getLabel('gallery_images'); ?></div>

    <div class="controls"><?php echo $this->form->getInput('gallery_images'); ?></div>

</div>

这实际上一切都在后端完美运行。但它不会保存任何地方。我们尝试在产品表上创建一个字段,认为它可能会存储为JSON。我们尝试为图像创建另一个带有product_id的表格,认为也许Joomla只是计算出外键?


Joomla文档似乎没有说明它在数据库中是如何工作的。(https://docs.joomla.org/Subform_form_field_type)


BIG阳
浏览 69回答 1
1回答

qq_花开花谢_0

因此,由于gallery_images字段被joomla保存到其中,因此我们编写了一些代码来手动执行此操作。class ModelProduct extends JModelAdmin{&nbsp; &nbsp; public function save($data) {&nbsp; &nbsp; &nbsp; &nbsp; if (parent::save($data)) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $registry = new Registry;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $registry->loadArray($data['gallery_image']);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $data['gallery_image'] = (string) $registry;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $db = JFactory::getDbo();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $query = $db->getQuery(true);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Fields to update.&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $fields = array(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $db->quoteName('gallery_image') . ' = ' . $db->quote($data['gallery_image']),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Conditions for which records should be updated.&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $conditions = array(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $db->quoteName('id') . ' = '.$data['id'],&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $query->update($db->quoteName('v4yn2_product'))->set($fields)->where($conditions);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $db->setQuery($query);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $result = $db->execute();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return true;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; return false;&nbsp; &nbsp; }}
随时随地看视频慕课网APP
我要回答