質問編集履歴

3

Controller\.phpの追加

2017/03/16 08:16

投稿

defaa
defaa

スコア11

test CHANGED
File without changes
test CHANGED
@@ -32,6 +32,40 @@
32
32
 
33
33
  【追記】
34
34
 
35
+ StoreArticlesController.php
36
+
37
+ ```
38
+
39
+ public function add()
40
+
41
+ {
42
+
43
+ $storeArticle = $this->StoreArticles->newEntity();
44
+
45
+ if ($this->request->is('post')) {
46
+
47
+ $storeArticle = $this->StoreArticles->patchEntity($storeArticle, $this->request->data);
48
+
49
+ if ($this->StoreArticles->save($storeArticle)) {
50
+
51
+ $this->Flash->success(__($this->request->data));
52
+
53
+ return $this->redirect(['action' => 'index']);
54
+
55
+ }
56
+
57
+ $this->Flash->error(__('The store article could not be saved. Please, try again.'));
58
+
59
+ }
60
+
61
+ $this->set(compact('storeArticle'));
62
+
63
+ $this->set('_serialize', ['storeArticle']);
64
+
65
+ }
66
+
67
+ ```
68
+
35
69
  StoreArticlesTable.php
36
70
 
37
71
  ```

2

ミス修正

2017/03/16 08:16

投稿

defaa
defaa

スコア11

test CHANGED
File without changes
test CHANGED
@@ -130,8 +130,6 @@
130
130
 
131
131
  ```
132
132
 
133
- ```
134
-
135
133
 
136
134
 
137
135
  期待する保存先ディレクトリ

1

関連するソースコードの追加、心当たりの追加

2017/03/16 08:15

投稿

defaa
defaa

スコア11

test CHANGED
File without changes
test CHANGED
@@ -30,9 +30,107 @@
30
30
 
31
31
 
32
32
 
33
- モデル
33
+ 【追記】
34
34
 
35
35
  StoreArticlesTable.php
36
+
37
+ ```
38
+
39
+ public function initialize(array $config)
40
+
41
+ {
42
+
43
+ parent::initialize($config);
44
+
45
+
46
+
47
+ $this->table('store_articles');
48
+
49
+ $this->displayField('title');
50
+
51
+ $this->primaryKey('id');
52
+
53
+ $this->addBehavior('Josegonzalez/Upload.Upload', [
54
+
55
+ 'photo' => [
56
+
57
+ 'path' => WWW_ROOT.'files{DS}{model}{DS}{field}{DS}',
58
+
59
+ 'fields' => [
60
+
61
+ 'dir' => 'photo_dir'
62
+
63
+ ]
64
+
65
+ ]
66
+
67
+ ]);
68
+
69
+ }
70
+
71
+ ```
72
+
73
+ add.ctp
74
+
75
+ ```
76
+
77
+ <?= $this->Form->create($storeArticle) ?>
78
+
79
+ <fieldset>
80
+
81
+ <legend><?= __('新規投稿') ?></legend>
82
+
83
+ <?php
84
+
85
+ echo $this->Form->input('start', ['empty' => true, 'label' => '掲載開始時間']);
86
+
87
+ echo $this->Form->input('title', ['label' => 'タイトル']);
88
+
89
+ echo $this->Form->input('body', ['label' => '本文']);
90
+
91
+ echo $this->Form->input('photo', ['type' => 'file', 'label' => '画像']);
92
+
93
+ echo $this->Form->input('photo_dir', ['type' => 'hidden']);
94
+
95
+ ?>
96
+
97
+ <script>
98
+
99
+ CKEDITOR.replace( 'body' );
100
+
101
+ </script>
102
+
103
+ </fieldset>
104
+
105
+ <?= $this->Form->button(__('投稿')) ?>
106
+
107
+ <?= $this->Form->end() ?>
108
+
109
+ ```
110
+
111
+ DBテーブル
112
+
113
+ ```
114
+
115
+ CREATE TABLE store_articles (
116
+
117
+ id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
118
+
119
+ start DATETIME,
120
+
121
+ title VARCHAR(64) NOT NULL,
122
+
123
+ photo varchar(255),
124
+
125
+ photo_dir varchar(255),
126
+
127
+ body TEXT NOT NULL
128
+
129
+ );
130
+
131
+ ```
132
+
133
+ ```
36
134
 
37
135
 
38
136
 
@@ -51,6 +149,16 @@
51
149
 
52
150
 
53
151
  必要な追加情報あればよろしくお願いいたします。
152
+
153
+
154
+
155
+ 【追記】
156
+
157
+ 保存されない原因のこころあたりとして、もうひとつ、store_articlesのテーブル構造をmysqlのコマンドライン上でALTER TABLEを用いてphotoとphoto_dirのフィールドを追加しました。
158
+
159
+ これに伴ってdebug_kitのchacheの部分からキャッシュを削除しましたが、テーブル構造の変更がUpload Plugin 3.0の認識されていない可能性があるのかも?と思います。そのようなケースはありますか?
160
+
161
+
54
162
 
55
163
 
56
164