简体   繁体   English

在PHP中错误保存项目(无效名称)

[英]Error Saving Item (Invalid Name) in PHP

I am using the Zoo CCK and have fiddled with the code long enough to get it to look like I want it to look. 我正在使用Zoo CCK,并且花了足够长的时间摆弄代码,以使其看起来像我想要的样子。 However, when I submit the item I receive an error (in the title) that I cannot figure out. 但是,当我提交项目时,会收到错误消息(标题中),我无法弄清。

To be less confusing, I should mention that the edit I made to the file was to add the parts for $message and any related code identifying it. 为避免混淆,我应该提到对文件所做的编辑是添加$ message的部件以及标识它的所有相关代码。

Any help would be appreciated. 任何帮助,将不胜感激。 Here is the file code below: 这是下面的文件代码:

ERROR: Error Saving Item (Invalid Name) 错误:错误保存项目(无效名称)

<?php

// no direct access
defined('_JEXEC') or die('Restricted access');

// register ElementOption class
App::getInstance('zoo')->loader->register('ElementOption', 'elements:option/option.php');
// register ElementRepeatable class
App::getInstance('zoo')->loader->register('ElementRepeatable', 'elements:repeatable/repeatable.php');
/*
Class: ElementSelect
    The select element class
*/

class ElementMessage extends ElementOption implements iSubmittable  {

/*
   Function: edit
       Renders the edit form field.

   Returns:
       String - html
*/
public function edit(){

    $this->app->document->addStylesheet('elements:message/assets/css/submission.css');
    // init vars
    $options_from_config = $this->config->get('option', array());
    $multiple            = $this->config->get('multiple');
    $default             = $this->config->get('default');
    $name                = $this->config->get('name');
    $message         = $this->get('message');

    if (count($options_from_config)) {

        // set default, if item is new
        if ($default != '' && $this->_item != null && $this->_item->id == 0) {
            $this->set('option', $default);
        }

        $options = array();
        if (!$multiple) {
            $options[] = $this->app->html->_('select.option', '', '-' . JText::sprintf('Select %s', $name) . '-');
        }
        foreach ($options_from_config as $option) {
            $options[] = $this->app->html->_('select.option', $option['value'], $option['name']);
        }

        $style = $multiple ? 'multiple="multiple" size="5"' : '';

        $html[] = $this->app->html->_('select.genericlist', $options, $this->getControlName('option', true), $style, 'value', 'text', $this->get('option', array()));
        $html[] = $this->app->html->_('control.text', $this->getControlName('Message'), $this->get('message'), 'name="message" size="30" maxlength="255" placeholder="'.JText::_('Message').'"');

        // workaround: if nothing is selected, the element is still being transfered
        $html[] = '<input type="hidden" name="'.$this->getControlName('select').'" value="1" />';

        return implode("\n", $html);
    }

    return JText::_("There are no options to choose from.");
}
public function hasValue($params = array()) {

    $message = $this->get('message');
    return !empty($message);
}
}

try changing: 尝试更改:

$message         = $this->get('message');

to

$message         = $this->config->get('message');

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

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