CakePHP变量变为空

CakePHP变量变为空,php,cakephp,Php,Cakephp,我猜你的模型有错误。首先尝试创建数组,然后打印它,看看它是否正确创建了数组。然后确保您的模型与数组匹配,即字段类型与您输入的字段类型匹配。”123和123不一样,因为123是一个字符串,123是一个整数。我能想到一些我想尝试的事情,但不是说你还没有 在while循环之前和之后回显$user和$event行,以验证有问题的行 将变量设置为另一个临时变量: $t_user=$user $t_事件=$event 然后尝试在循环中使用$t_uu变量。您可以通过将值转换为字符串来检查此假设:eve

我猜你的模型有错误。首先尝试创建数组,然后打印它,看看它是否正确创建了数组。然后确保您的模型与数组匹配,即字段类型与您输入的字段类型匹配。”123和123不一样,因为123是一个字符串,123是一个整数。

我能想到一些我想尝试的事情,但不是说你还没有

  • 在while循环之前和之后回显$user和$event行,以验证有问题的行

  • 将变量设置为另一个临时变量:

$t_user=$user

$t_事件=$event


然后尝试在循环中使用$t_uu变量。

您可以通过将值转换为字符串来检查此假设:
event_uid'=>(string)$event,user_uid'=>(string)$user
Hi Tor,模型数组中没有错误。正在保存“123”和123。我只是不明白$event变量如何被清除?嗨,Ewan,我试过了,它插入了一个空白字段。同样,这意味着$event是空的。。。但当我在第17行回显它时,它是11042…当将$event转换为整数时,它显示为0。所以这个变量实际上是空的。。。真是个谜。
<?php
class UploadsController extends AppController {
var $name = 'Uploads';
var $components = array('Auth');
var $uses = array('Upload');

function beforeFilter() {
    $this->Auth->allow('*');
}

function upload($event) {
    App::import('Vendor', 'UploadedFiles', array('file' => 'UploadedFiles.php'));

    $user = $this->Auth->user('id');
    $this->set('user', $user);
    if(!$this->Auth->user()) { $this->Session->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->getSourceFile()->getSafeFileName($absGalleryPath);
      $file->getSourceFile()->save($absGalleryPath . '/' . $fileName);

      $thumbFileName = $file->getThumbnail(1)->getSafeFileName($absThumbnailsPath);
      $file->getThumbnail(1)->save($absThumbnailsPath . '/' . $thumbFileName);

        $this->Upload->create();
        $this->Upload->set(array(
            'name' => $absGalleryPath . $fileName,
            'width' => $file->getSourceFile()->getWidth(),
            'height' => $file->getSourceFile()->getHeight(),
            'description' => $file->getDescription(),
            'event_id' => $event,
            'user_id' => $user
          ));
        $this->Upload->save();
    }
  }
}