小编Bal*_*mbi的帖子

在CakePHP 3.x中保存HasMany关联数据

我有两张桌子.我的主要表是学生.我的次要表是考试.我正在尝试使用hasManybelongsToMany Association 保存这两个表.但它仅在学生表中保存数据,而不是在考试中保存.任何人都可以帮我解决这个问题.

学生型号:

class StudentsTable extends Table {
  public function initialize(array $config) {
    $this->addBehavior('Timestamp');
    parent::initialize($config);
    $this->table('students');
    $this->primaryKey(['id']);
    $this->hasMany('Exams', [
      'className' => 'Exams',
      'foreignKey' => 'student_id',
      'dependent'=>'true',
      'cascadeCallbacks'=>'true']);
  }
}
Run Code Online (Sandbox Code Playgroud)

考试模型:

class ExamsTable extends Table {
  public function initialize(array $config) {
    parent::initialize($config);
    $this->table('exams');
    $this->primaryKey(['id']);
    $this->belongsToMany('Students',[
      'className'=>'Students',
      'foreignKey' => 'subject_id',
      'dependent'=>'true',
      'cascadeCallbacks'=>'true']);
  }
}
Run Code Online (Sandbox Code Playgroud)

我的school.ctp:

echo $this->Form->create();
echo $this->Form->input('name');
echo $this->Form->input('exams.subject', array(
  'required'=>false,
  'multiple' => 'checkbox',
  'options' => array(
    0 …
Run Code Online (Sandbox Code Playgroud)

php mysql orm associations cakephp-3.0

5
推荐指数
1
解决办法
703
查看次数

如何在php中使用ajax上传多个图像

我有这样的UI:
在此输入图像描述

我想在php中使用ajax上传多个视频.为此我在jQuery中尝试了FormData().但它只上传了一张图片,而不是更多.

我的表格文件:

<form enctype="multipart/form-data" action="/test.php" 
method="post" class="putImages">
   <input name="media[]" type="file" multiple/>
   <input class="button" type="submit" alt="Upload" value="Upload" />
    <button type="button" id="add"></button>
</form>
Run Code Online (Sandbox Code Playgroud)

我的jQuery文件:

<script type="text/javascript">
    $(document).ready(function() {
        $("#add").click(function() {
            var $div = $('div[id^="inputdiv"]:last');
            var num = parseInt($div.prop("id").match(/\d+/g), 10) + 1;
            var $klon = $div.clone().prop('id', 'inputdiv' + num).appendTo("#athleteRegister").insertBefore("#submitbutton");
            $('#inputdiv' + num).find("input").attr('name', 'file[' + num + ']');
            $('#inputdiv' + num).find("input").val("");
            $('#inputdiv' + num).find("input").attr('id', 'file' + num);
            $('#inputdiv' + num).find("input").css("outline", "none");
            $('#inputdiv' + num).find("div.col-sm-1 i").attr('class', 'fa fa-minus');
            $('#inputdiv' + num).find("div.col-sm-1 button").attr('id', 'remove');
            $('#inputdiv' …
Run Code Online (Sandbox Code Playgroud)

javascript ajax jquery html5

5
推荐指数
1
解决办法
1003
查看次数

标签 统计

ajax ×1

associations ×1

cakephp-3.0 ×1

html5 ×1

javascript ×1

jquery ×1

mysql ×1

orm ×1

php ×1