外部フォームからExpressへのファイル保存について

2021年5月27日 at 13:33

フォーラムの皆さま

 いつも大変お世話になっております。
前回の質問に加え、外部フォームから、Expressエンティティ
へ添付ファイルを保存する工程を開発しております。

ビュー側とコントローラ側のコードは以下の通りです。
【ビュー側】
<p><label>添付ファイル1:<?php
echo $form->file('file1', '');
?></label></p>

【コントローラ側】
$entry = Express::buildEntry( 'autumn' )
->setAFiles1($this->post('file1'))
->save();

 しかし、このコードを実行しましても、Express
エントリーには何も登録されておらず、空白になっております。

ちなみに、Expressエンティティフォームから入力すると、
正常に登録されます。
ファイルは、ローカルファイルと、ファイルマネージャへ
アップロードしたファイル両方を試しましたが、いずれも
登録されませんでした。

Expressエンティティフォームの「添付ファイル」登録の
コードがどこにあるかわかれば、それを参考にしてコードを
作成することもできるかと考えております。

解決方法についてご教示いただけますと幸いです。
どうぞよろしくお願い申し上げます。

環境設定
# concrete5 Version
Core Version - 8.5.5
Version Installed - 8.5.5
Database Version - 20201116182100

# Database Information
Version: 5.1.73
SQL Mode:

# concrete5 Packages
Bootstrap4 Website Theme (1.0.0), Honest Websites Back To Top (1.1.0), Login/Logout Link (1.0)

# concrete5 Overrides
blocks/external_form/form/controller/autumn.php, blocks/external_form/form/controller/edit.php, blocks/external_form/form/controller, blocks/external_form/form/autumn.php, blocks/external_form/form, blocks/external_form, themes/tkpsurvey/default.php, themes/tkpsurvey/description.txt, themes/tkpsurvey/form.php, themes/tkpsurvey/thumbnail.png, themes/tkpsurvey/css/custom.css, themes/tkpsurvey/css, themes/tkpsurvey/elements/footer-form.php, themes/tkpsurvey/elements/header_top-form.php, themes/tkpsurvey/elements, themes/tkpsurvey/js/custom.js, themes/tkpsurvey/js, themes/tkpsurvey/__backup/yumekana_online.backup, themes/tkpsurvey/__backup/yumekana_zam.backup, themes/tkpsurvey/__backup/yumekana_zpm.backup, themes/tkpsurvey/__backup/controller/yumekana_online.backup, themes/tkpsurvey/__backup/controller/yumekana_zam.backup, themes/tkpsurvey/__backup/controller/yumekana_zpm.backup, themes/tkpsurvey/__backup/controller, themes/tkpsurvey/__backup, themes/tkpsurvey

# concrete5 Cache Settings
Block Cache - On
Overrides Cache - On
Full Page Caching - Off
Full Page Cache Lifetime - Every 6 hours (default setting).

# Server Software
Apache

# Server API
apache2handler

# PHP Version
7.3.15

# PHP Extensions
apache2handler, bcmath, bz2, calendar, Core, ctype, curl, date, dba, dom, enchant, exif, fileinfo, filter, ftp, gd, gettext, gmp, hash, iconv, imap, intl, json, ldap, libxml, mbstring, mcrypt, mysqli, mysqlnd, odbc, openssl, pcre, PDO, pdo_mysql, PDO_ODBC, pdo_pgsql, pdo_sqlite, pgsql, Phar, posix, pspell, recode, Reflection, session, shmop, SimpleXML, snmp, soap, sockets, SPL, sqlite3, standard, sysvmsg, sysvsem, sysvshm, tidy, tokenizer, wddx, xml, xmlreader, xmlrpc, xmlwriter, xsl, Zend OPcache, zip, zlib

# PHP Settings
max_execution_time - 3600
log_errors_max_len - 4096
max_file_uploads - 100
max_input_nesting_level - 64
max_input_time - 60
max_input_vars - 1000
memory_limit - 256M
post_max_size - 384M
upload_max_filesize - 256M
ldap.max_links - Unlimited
mbstring.regex_stack_limit - 100000
mysqli.max_links - Unlimited
mysqli.max_persistent - Unlimited
odbc.max_links - Unlimited
odbc.max_persistent - Unlimited
pcre.backtrack_limit - 1000000
pcre.recursion_limit - 100000
pgsql.max_links - Unlimited
pgsql.max_persistent - Unlimited
session.cache_limiter - no value
session.gc_maxlifetime - 7200
soap.wsdl_cache_limit - 5
opcache.max_accelerated_files - 4000
opcache.max_file_size - 0
opcache.max_wasted_percentage - 5

タグ:

Re: 外部フォームからExpressへのファイル保存について

2021年5月28日 at 13:03
いつもお世話になります。
昨日質問させていただきました、外部フォームからの
ファイル添付につきまして、進展がございましたので、
ご報告いたします。

ファイルマネージャからのファイルアップロードを
コードに追加して、ファイルをローカルコンピュータ
からアップロードすると、Expressに登録できました。

理由は不明ですが、取り急ぎご報告いたします。

【ビュー側】
<p><label>添付ファイル1:<?php
   $fm = Core::make('helper/concrete/asset_library');?>
<div class="ccm-attribute ccm-attribute-image-file">
<?php echo $fm->file('f1', 'file1', 'ファイルを選択してください');?>
</div>
</label></p>
 

Re: 外部フォームからExpressへのファイル保存について

2021年5月28日 at 14:25
添付ファイルをファイルマネージャから選択して、
Expressエントリーとして登録すると、

Expected value of type "Concrete\Core\Entity\File\File" for association field "Concrete\Core\Entity\Attribute\Value\Value\ImageFileValue#$file", got "string" instead.

のエラーが出ました。
ただし、Expressにはデータは正常に保存されております。
このエラーは何を意味するのでしょうか?

デバッグでは
public static function invalidAssociation(ClassMetadata $targetClass, $assoc, $actualValue)
{
$expectedType = 'Doctrine\Common\Collections\Collection|array';

if (($assoc['type'] & ClassMetadata::TO_ONE) > 0) {
$expectedType = $targetClass->getName();
}

return new self(sprintf(
'Expected value of type "%s" for association field "%s#$%s", got "%s" instead.',
$expectedType,
$assoc['sourceEntity'],
$assoc['fieldName'],
is_object($actualValue) ? get_class($actualValue) : gettype($actualValue)
));
}
のボールド部分がハイライトされております。
 

Re: 外部フォームからExpressへのファイル保存について

2021年5月28日 at 21:35
katzさん、本日は週刊concrete5でご教示いただきまして
ありがとうございました。

ローカルPCからダイレクトにExpressへファイルを取り込める
http://documentation.concrete5.org/developers/working-with-files-and-the-file-manager/importing-new-files も大変勉強になりました。

また、ファイルマネージャからExpressへ登録する方法については、
次のコードで実現できました。

【ビュー側】
<p><label>添付ファイル1:<?php
  $fm = Core::make('helper/concrete/asset_library');?>
<div class="ccm-attribute ccm-attribute-image-file">
<?php echo $fm->file('f1', 'file1', 'ファイルを選択してください');?>
</div>
</label></p>

【コントローラ側】
use File;
$f1 = File::getById($this->post('file1'));
$entry = Express::buildEntry( 'autumn' )
->setAFiles1($f1)
->save();

これで例外が発生せず、ファイルマネージャからファイル情報を
Expressへ登録することができました。
本当にありがとうございました。