Note that there are some explanatory texts on larger screens.

plurals
  1. POCakePHP Variable becomes empty
    primarykey
    data
    text
    <pre><code>&lt;?php class UploadsController extends AppController { var $name = 'Uploads'; var $components = array('Auth'); var $uses = array('Upload'); function beforeFilter() { $this-&gt;Auth-&gt;allow('*'); } function upload($event) { App::import('Vendor', 'UploadedFiles', array('file' =&gt; 'UploadedFiles.php')); $user = $this-&gt;Auth-&gt;user('id'); $this-&gt;set('user', $user); if(!$this-&gt;Auth-&gt;user()) { $this-&gt;Session-&gt;setFlash(__('Please login.', true)); } echo $user; echo $event; $vardir = date('d-m-Y'); $dir = 'img/gallery/'.$vardir.'/'; $thmbdir = 'img/gallery/'.$vardir.'/thumbnails/'; if(!is_dir($dir)) { mkdir($dir, 0777); mkdir($thmbdir, 0777); } $galleryPath = $dir; $absGalleryPath = realpath($galleryPath) . '/'; $absThumbnailsPath = realpath($galleryPath . 'thumbnails/') . '/'; //Iterate through uploaded data and save the original file, thumbnail, and description. while(($file = UploadedFiles::fetchNext()) !== null) { $fileName = $file-&gt;getSourceFile()-&gt;getSafeFileName($absGalleryPath); $file-&gt;getSourceFile()-&gt;save($absGalleryPath . '/' . $fileName); $thumbFileName = $file-&gt;getThumbnail(1)-&gt;getSafeFileName($absThumbnailsPath); $file-&gt;getThumbnail(1)-&gt;save($absThumbnailsPath . '/' . $thumbFileName); $this-&gt;Upload-&gt;create(); $this-&gt;Upload-&gt;set(array( 'name' =&gt; $absGalleryPath . $fileName, 'width' =&gt; $file-&gt;getSourceFile()-&gt;getWidth(), 'height' =&gt; $file-&gt;getSourceFile()-&gt;getHeight(), 'description' =&gt; $file-&gt;getDescription(), 'event_id' =&gt; $event, 'user_id' =&gt; $user )); $this-&gt;Upload-&gt;save(); } } } </code></pre> <p>Check the last part of the code where I try to save to the database. It doesn't save because $event and $users become empty. But when I echo them (line 17 and 18), they do appear on the page with correct values. It seems that they are being 'erased' in the while loop... If I put some dummy data for <code>'event_id' =&gt; '123'</code> and <code>'user_id' =&gt; '123'</code>, the scripts saves successfully. But if I use the variables, it doesn't save. <strong>What happens with my variables</strong>? Any idea?</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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