-
-
Save carlchen1986/1bf6c432d932cd3c1478ba84ab05d0b9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="box box-primary"> | |
<div class="box-header with-border"> | |
<h3 class="box-title">Neuen Artikel anlegen</h3> | |
</div> | |
<!-- /.box-header --> | |
<!-- form start --> | |
<?= $this->Form->create($article, ['class' => 'form-horizontal', 'type' => 'file']) ?> | |
<?php | |
$myTemplates = [ | |
'inputContainer' => '{{content}}', | |
]; | |
$this->Form->templates($myTemplates); | |
?> | |
<div class="box-body"> | |
<div class="form-group"> | |
<label for="title" class="col-sm-2 control-label">Titel</label> | |
<div class="col-sm-10"> | |
<input type="text" name="title" required="required" maxlength="255" id="title" class="form-control"> | |
</div> | |
</div> | |
<div class="form-group"> | |
<label for="text" class="col-sm-2 control-label">Text</label> | |
<div class="col-sm-10"> | |
<textarea name="text" required="required" id="text" class="form-control textarea" rows="3" placeholder="Dein Text ..."></textarea> | |
</div> | |
</div> | |
<div class="form-group"> | |
<label for="fachbereiche-id" class="col-sm-2 control-label">Fachbereich</label> | |
<?= $this->Form->input('fachbereiche_id', ['options' => $fachbereiches, 'label' => false]); ?> | |
</div> | |
<div class="form-group"> | |
<label for="attachments-filename" class="col-sm-2 control-label">Datei</label> | |
<div class="col-sm-10"> | |
<?= $this->Form->input('filename', ['type' => 'file', 'label' => false, 'multiple' => true, 'name' => 'filename[]']); ?> | |
</div> | |
</div> | |
</div> | |
<!-- /.box-body --> | |
<div class="box-footer"> | |
<?= $this->Form->button(__('Speichern'), ['class' => 'btn btn-info pull-right']) ?> | |
</div> | |
<!-- /.box-footer --> | |
<?= $this->Form->end() ?> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Add method | |
* | |
* @return \Cake\Network\Response|void Redirects on successful add, renders view otherwise. | |
*/ | |
public function add() | |
{ | |
$article = $this->Articles->newEntity(); | |
if ($this->request->is('post')) { | |
$article = $this->Articles->patchEntity($article, $this->request->data); | |
$saving = $this->Articles->save($article); | |
if ($saving) { | |
// Load Model to save attachments | |
$this->loadModel('Attachments'); | |
foreach ($saving['filename'] as $value) { | |
$attachmentdata = [ | |
'filename' => $value['name'], | |
'filetype' => $value['type'], | |
'articles_id' => $saving->id | |
]; | |
$attachment = $this->Attachments->newEntity(); | |
$attachment = $this->Attachments->patchEntity($attachment, $attachmentdata); | |
$saveattachment = $this->Attachments->save($attachment); | |
} | |
// If saving article was successfull | |
$this->Flash->success(__('The article has been saved.')); | |
return $this->redirect(['action' => 'index']); | |
} else { | |
$this->Flash->error(__('The article could not be saved. Please, try again.')); | |
} | |
} | |
$fachbereiches = $this->Articles->Fachbereiches->find('list', ['limit' => 200]); | |
$this->set(compact('article', 'fachbereiches')); | |
$this->set('_serialize', ['article']); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function initialize(array $config) | |
{ | |
parent::initialize($config); | |
$this->table('articles'); | |
$this->displayField('title'); | |
$this->primaryKey('id'); | |
$this->addBehavior('Timestamp'); | |
$this->belongsTo('Fachbereiches', [ | |
'foreignKey' => 'fachbereiche_id', | |
'joinType' => 'INNER' | |
]); | |
$this->hasMany('Attachments', [ | |
'foreignKey' => 'articles_id', | |
'dependent' => true, | |
]); | |
$this->addBehavior('Josegonzalez/Upload.Upload', [ | |
// Configure as many upload fields as possible where the pattern is 'field' => 'config' | |
'filename' => [ | |
'fields' => [ | |
'type' => 'filetype' // Field to save filetype | |
], | |
'filesystem' => [ | |
'root' => $_SERVER['HOME'] | |
], | |
'path' => '{DS}Sites{DS}turngau{DS}webroot{DS}files{DS}' | |
], | |
]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment