とても単純なものがとても難しいことがあるのはとてもクレイジーです。
すべてのcakephp2.1の達人に電話してください。フォームがあり、名前とテキスト画像(var)フィールドがあります。
画像を投稿したいのですが、サイズ変更、サムネイル、特別なことは何もありません。画像を投稿してview.ctpで表示する簡単なMVCの例です。
それでおしまい。私はcakephp.orgの/en/2.1ブックとAPIを調べましたが、フォルダーにアップロードしてctpで表示する限り、mvcを機能させることができないようです。
私のコントローラー
public function add() {
if ($this->request->is('post')) {
$this->ListShExPainImage->create();
if ($this->ListShExPainImage->save($this->request->data)) {
$this->Session->setFlash(__('The list sh ex pain image has been saved'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The list sh ex pain image could not be saved. Please, try again.'));
}
}
}
public function view($id = null) {
$this->ListShExPainImage->id = $id;
if (!$this->ListShExPainImage->exists()) {
throw new NotFoundException(__('Invalid list sh ex pain image'));
}
$this->set('listShExPainImage', $this->ListShExPainImage->read(null, $id));
}
私のadd.ctp
<?php echo $this->Form->create('ListShExPainImage');?>
<fieldset>
<legend><?php echo __('Add List Sh Ex Pain Image'); ?></legend>
<?php
echo $this->Form->input('name');
echo $this->Form->input('image', array('type' => 'file'));
?>
</fieldset>
<?php echo $this->Form->end(__('Submit'));?>
私のview.ctp
<h2><?php echo __('List Sh Ex Pain Image');?></h2>
<dl>
<dt><?php echo __('Id'); ?></dt>
<dd>
<?php echo h($listShExPainImage['ListShExPainImage']['id']); ?>
</dd>
<dt><?php echo __('Name'); ?></dt>
<dd>
<?php echo h($listShExPainImage['ListShExPainImage']['name']); ?>
</dd>
<dt><?php echo __('Image'); ?></dt>
<dd>
<?php echo h($listShExPainImage['ListShExPainImage']['image']); ?>
</dd>
</dl>
よろしくお願いします。