Note that there are some explanatory texts on larger screens.

plurals
  1. POCakePHP Uploader Plugin only works on one Model
    text
    copied!<p>I've installed <a href="http://milesj.me/code/cakephp/uploader#uploading-files-through-the-model" rel="nofollow">Miles Johnson's Uploader plugin</a> and set it up with one of my models and got it working perfectly. Very nice.</p> <p>Then I went and set it up on another model with almost identical code [the only difference is the upload path] and it won't work on the second model. When I submit the form the plugin doesn't seem to notice; I get an SQL error from an attempt to insert the POST file array straight into the DB.</p> <p>Here is the code. [Other than this the plugin is imported in the bootstrap]</p> <pre><code>public $actsAs = array( 'Uploader.Attachment' =&gt; array( 'photo' =&gt; array( 'name' =&gt; 'formatFileName', 'uploadDir' =&gt; '/uploads/uses/img/', 'dbColumn' =&gt; 'photo', 'maxNameLength' =&gt; 30, 'overwrite' =&gt; true, 'stopSave' =&gt; true, 'allowEmpty' =&gt; false, 'transforms' =&gt; array( array('method' =&gt; 'resize', 'width' =&gt; 240, 'dbColumn' =&gt; 'photo_thumb')) ) ), 'Uploader.FileValidation' =&gt; array( 'fileName' =&gt; array( 'extension' =&gt; array('gif', 'jpg', 'png', 'jpeg'), 'required' =&gt; true ) ) ); </code></pre> <p>This is on the model that is not uploading and the only difference is the uploadDir.</p> <p>Does the plugin only work on one model? Any clues? thnx :}</p> <hr> <h2>Edit for extra clarity</h2> <p>Here is my view code:</p> <pre><code>echo $this-&gt;Form-&gt;create('Use', array('type' =&gt; 'file')); echo $this-&gt;Form-&gt;input('Use.photo', array('type' =&gt; 'file')); echo $this-&gt;Form-&gt;input('Use.desc', array('rows' =&gt; '3', 'label' =&gt; 'Description')); echo $this-&gt;Form-&gt;end('Add to Gallery'); </code></pre> <p>And here is my controller code:</p> <pre><code>public function add() { if ($this-&gt;request-&gt;is('post')) { $this-&gt;Use-&gt;set('user_id', $this-&gt;Auth-&gt;user('id')); if ($this-&gt;Use-&gt;save($this-&gt;request-&gt;data)) { $this-&gt;Session-&gt;setFlash('Your Use has been saved.'); $this-&gt;redirect(array('action' =&gt; 'index')); } else { $this-&gt;Session-&gt;setFlash('Unable to add your Use.'); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload