This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

ricardo_zurc
ricardo_zurc

Hi!

I was getting issues with the fields.yaml -> type fileupload, I already put on the $attachOne -> 'upfile' => ['System\Models\File'] but it complitly destroys my backend.

Here a prtscreen -> WITHOUT $attachOne -> 'upfile' => ['System\Models\File'] :=> http://i.imgur.com/5DA2Qra.png WITH $attachOne -> 'upfile' => ['System\Models\File'] :=> http://i.imgur.com/sJW10lW.png

philipptempel
philipptempel

To me it looks more like an error with your general HTML markup. Can you share more of your code? Like the controller's partials, content of fields.yaml. Without seeing the actual code it is really hard to pin the error down. I have several fields like that and it works perfectly for me. Also, the first error is obvious: because the relation is missing in the model, you cannot create the form field. The latter we'll need to dig into and see more code.

ricardo_zurc
ricardo_zurc

Here some of the code (I hope is want you want to see)

File.php (Controller) Code

<?php namespace Stronganswer\Filemanagement\Controllers;

use BackendMenu;
use Backend\Classes\Controller;

/**
 * Files Back-end Controller
 */
class Files extends Controller
{
    public $implement = [
        'Backend.Behaviors.FormController',
        'Backend.Behaviors.ListController'
    ];

    public $formConfig = 'config_form.yaml';
    public $listConfig = 'config_list.yaml';

    public function __construct()
    {
        parent::__construct();

        BackendMenu::setContext('Stronganswer.Filemanagement', 'filemanagement', 'files');
    }
}

File.php (Model)

<?php namespace Stronganswer\Filemanagement\Models;

use Model;

/**
 * File Model
 */
class File extends Model
{
    /**
     * @var string The database table used by the model.
     */
    public $table = 'stronganswer_filemanagement_files';

    /**
     * @var array Guarded fields
     */
    protected $guarded = ['*'];

    /**
     * @var array Fillable fields
     */
    protected $fillable = [];

    /**
     * @var array Relations
     */
    public $hasOne = [];
    public $hasMany = [];
    public $belongsTo = [];
    public $belongsToMany = [];
    public $morphTo = [];
    public $morphOne = [];
    public $morphMany = [];
    public $attachOne = [
      'upfile' => ['System\Models\File']
    ];

    public $attachMany = [];
    //'upfile' => ['System\Models\File']

}

fields.yaml

# ===================================
#  Form Field Definitions
# ===================================

fields:
    labelname:
        label: Name

    upfile:
        label: Upload
        type: fileupload

    schdate:
        label: Datepicker
        type: datepicker
        comment: If you want to upload now just leave it blank

    content:
        type: text
        disable: true
        label: File Size

create.htm

<style media="screen">

</style>
<?php Block::put('breadcrumb') ?>
    <ul>
        <li><a href="<?= Backend::url('stronganswer/filemanagement/files') ?>">Files</a></li>
        <li><?= e($this->pageTitle) ?></li>
    </ul>
<?php Block::endPut() ?>

<?php if (!$this->fatalError): ?>

    <?= Form::open(['class' => 'layout']) ?>

        <div class="layout-row">
            <?= $this->formRender() ?>
        </div>

        <div class="form-buttons">
            <div class="loading-indicator-container">
                <button
                    type="submit"
                    data-request="onSave"
                    data-hotkey="ctrl+s, cmd+s"
                    data-load-indicator="Creating File..."
                    class="btn btn-primary">
                    Create
                </button>
                <button
                    type="button"
                    data-request="onSave"
                    data-request-data="close:1"
                    data-hotkey="ctrl+enter, cmd+enter"
                    data-load-indicator="Creating File..."
                    class="btn btn-default">
                    Create and Close
                </button>
                <span class="btn-text">
                    or <a href="<?= Backend::url('stronganswer/filemanagement/files') ?>">Cancel</a>
                </span>
            </div>
        </div>

    <?= Form::close() ?>

<?php else: ?>

    <p class="flash-message static error"><?= e($this->fatalError) ?></p>
    <p><a href="<?= Backend::url('stronganswer/filemanagement/files') ?>" class="btn btn-default">Return to files list</a></p>

<?php endif ?>

Last updated

1-3 of 3

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.