Editor upload with custom value
Editor upload with custom value
rpconsultants
Posts: 6Questions: 2Answers: 0
in Editor
This server side script was working correctly until I updated to editor v2.
<?php
include( "DataTables/Editor-PHP-2.2.2/lib/DataTables.php" );
$retcmpid = 0;
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Join,
DataTables\Editor\Upload,
DataTables\Editor\Validate,
DataTables\Editor\ValidateOptions;
Editor::inst( $db, 'ffam_competition', 'cmpid' )
->fields(
Field::inst( 'ffam_competition.cmpid' ),
Field::inst( 'ffam_competition.typeconcoursid' )
->options( 'core_typeconcours', 'typeconcoursid', 'typeconcourslabelid' ),
Field::inst( 'core_typeconcours.typeconcourslabelid' ),
Field::inst( 'core_typeconcours.typeconcoursdesc' ),
Field::inst( 'ffam_competition.typeid' )
->options( 'core_type', 'typeid', 'typecode' ),
Field::inst( 'core_type.typecode' ),
Field::inst( 'ffam_competition.catid' )
->options( 'core_categorie', 'id', 'libelle' ),
Field::inst( 'core_categorie.libelle' ),
Field::inst( 'ffam_competition.cmplibelle' ),
Field::inst( 'ffam_competition.color' ),
Field::inst( 'ffam_competition.cmpdate' ),
Field::inst( 'ffam_competition.cmpenddate' ),
Field::inst( 'ffam_competition.cmplieu' ),
Field::inst( 'ffam_competition.cmporganisateur' ),
Field::inst( 'ffam_competition.cmpvolphase1' ),
Field::inst( 'ffam_competition.cmpvolphase2' ),
Field::inst( 'ffam_competition.cmpvolphase3' ),
Field::inst( 'ffam_competition.cmpflagnautomatic' ),
Field::inst( 'ffam_competition.cmpistbl' ),
Field::inst( 'ffam_competition.cmpisoldnorm' ),
Field::inst( 'ffam_competition.cmppromotion' ),
//Field::inst( 'ffam_competition.cmppromprog' ),
Field::inst( 'ffam_competition.cmppromprog' )
->validator(Validate::notEmpty(ValidateOptions::inst()
->message('Field required')
)),
Field::inst( 'ffam_competition.cmpisadmin' ),
Field::inst( 'ffam_competition.cmpdisplayresultspublic' ),
Field::inst( 'ffam_competition.cmplogoid' )
->setFormatter( 'Format::NullEmpty' )
->upload(
Upload::inst( $_SERVER['DOCUMENT_ROOT'].'/img/logos/cmp/__NAME__' )
->db( 'ffam_file', 'fileid', array(
'filename' => Upload::DB_FILE_NAME,
'fileext' => Upload::DB_EXTN,
'filesize' => Upload::DB_FILE_SIZE,
'web_path' => Upload::DB_WEB_PATH,
'system_path' => Upload::DB_SYSTEM_PATH,
'filetype' => 'cmp'
) )
->validator( Validate::fileSize( 5000000, 'Files must be smaller that 5 Mo' ) )
->validator( Validate::fileExtensions( array( 'png', 'jpg', 'jpeg', 'gif' ), "Please upload an image" ) )
),
Field::inst( 'ffam_file.web_path' )
)
->leftJoin( 'ffam_file', 'ffam_file.fileid', '=', 'ffam_competition.cmplogoid' )
->leftJoin( 'core_categorie', 'core_categorie.id', '=', 'ffam_competition.catid' )
->leftJoin( 'core_type', 'core_type.typeid', '=', 'ffam_competition.typeid' )
->leftJoin( 'core_typeconcours', 'core_typeconcours.typeconcoursid', '=', 'ffam_competition.typeconcoursid' )
->process( $_POST )
->json();
?>
The 'filetype' field which should be set to 'cmp' is set to the WEB_PATH
Answers
That should work - what is happening instead? Are you getting an error, or is it just not setting or what?
This is the piece of code in question. It sets a temporary string value in the db, and then on lines 690+ it will write in the actual value to that row that was generated.
Allan
Perhaps you could add
->debug(true)
just before the->process()
call, and show me the JSON return from the server when you perform an upload action.Allan
Here it is
The ffam_file.filetype field is set to 'system_path' instead of the constant 'cmp'
Thanks.
It appears to be writing the path name to the Web path:
I hadn't clicked that this is exactly what you said in your initial post. Apologies.
That is indeed a bug and I've just committed a fix. It will be in Editor 2.3.1, or you can just patch your own copy of
Upload.php
with that fix directly, to get it immediately.Allan
Thanks a lot Allan. Will do