【问题标题】:SQL Error: 1054: Unknown column 'Array' cakephp 1.3SQL 错误:1054:未知列 'Array' cakephp 1.3
【发布时间】:2013-04-12 02:33:59
【问题描述】:

我正在使用位于 https://github.com/dilab/CakePHP-Photo-Behavior 的 CakePHP-Photo-Behavior 并收到以下错误。

SQL 错误:1054:“字段列表”中的未知列“数组”[CORE\cake\libs\model\datasources\dbo_source.php,第 684 行]

查询:INSERT INTO photos (title, description, photo_dir, photo, school_id, user_id, is_slider, modified, @98765433 skjg', 'lkhg', '', 数组, 1, 1, 1, '2013-04-12 01:14:09', '2013-04-12 01:14:09')

型号:

var $actsAs = array('Photo'=>array(
                    'dir'=>array('upload_directory'),
                    'file_field'=>array('photo'),
                    'file_db_file'=>array('photo'),
                    'thumb'=>array(true),
                    'thumb_size'=>array(array("100x100"))
));

查看:

<?php echo $this->Form->create('Photo', array('type' => 'file')); ?>
<?php echo $this->Form->input('Photo.title'); ?>
<?php echo $this->Form->input('Photo.description', array('type' => 'textarea', 'rows' => 3)); ?>
<?php echo $this->Form->input('Photo.photo', array('type' => 'file')); ?>
<?php echo $this->Form->input('Photo.photo_dir', array('type' => 'hidden')); ?>
<?php echo $this->Form->end(__('Upload', true));?>

控制器:

function admin_add_slider() {
    debug($this->params);

    if (!empty($this->data)) {

        //set the school id
        $session_school_id = $this->Session->read('Userinfo.currentSchoolid');
        $session_user_id = $this->Session->read('Userinfo.id');
        $this->data['Photo']['school_id'] = $session_school_id;
        $this->data['Photo']['user_id'] = $session_user_id;
        $this->data['Photo']['is_slider'] = 1;
        $this->Photo->create();
        if ($this->Photo->save($this->data)) {
            $this->Session->setFlash(__('The Photo has been saved', true));
            $this->redirect(array('action' => 'view_slider'));
        } else {
            $this->Session->setFlash(__('The Photo could not be saved. Please, try again.', true));
        }
    }

}

调试:

data] => Array
    (
        [Photo] => Array
            (
                [title] => skjg
                [description] => lkhg
                [photo_dir] => 
                [photo] => Array
                    (
                        [name] => PLDMonth6Student_img_2.jpg
                        [type] => image/jpeg
                        [tmp_name] => C:\xampp\tmp\phpBA8C.tmp
                        [error] => 0
                        [size] => 42085
                    )

            )

    )

表: id, title, description, small, large, is_slider, created, modified, school_id, user_id, user_id, user_id, @98765434 >

谢谢 罗伯特

【问题讨论】:

    标签: php cakephp


    【解决方案1】:

    我没有使用过该行为,但你确定你的设置不应该是:

    var $actsAs = array('Photo'=>array(
        'dir'=>'upload_directory',
        'file_field'=>'photo',
        'file_db_file'=>'photo',
        'thumb'=>true,
        'thumb_size'=>array("100x100")
    ));
    

    【讨论】:

      【解决方案2】:

      在配置数组中添加 "dbColumn" 字段。仅当 "allowEmpty"TRUE 时才有效。此字段应与您的数据库列名称相同。就我而言,它是“图像”

      public $actsAs = array( 
      'Uploader.Attachment' => array(
          'image' => array(
                  'baseDir'       => '',
                  'uploadDir'     => 'files/uploads/',
                  'overwrite'     => true,
                  'stopSave'      => true,
                  'allowEmpty'    => true,
                  'dbColumn' => 'image'                           
          )
        )
      );
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-08-19
        • 1970-01-01
        • 2016-04-01
        • 2012-03-09
        • 2017-03-17
        • 1970-01-01
        • 2011-11-12
        • 1970-01-01
        相关资源
        最近更新 更多