Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 如何使用cakephp在数据库中插入数据_Mysql_Cakephp - Fatal编程技术网

Mysql 如何使用cakephp在数据库中插入数据

Mysql 如何使用cakephp在数据库中插入数据,mysql,cakephp,Mysql,Cakephp,我有一个表名stores,控制器名StoresController.php,模型名stores.php,在stores文件夹中有一个add.ctp文件,但我无法从表单中插入数据。这是我的add.ctp文件 <div class="row form-main"> <div class="panel panel-default"> <div class="panel-body"> <?php echo $this->Form-&

我有一个表名stores,控制器名StoresController.php,模型名stores.php,在stores文件夹中有一个add.ctp文件,但我无法从表单中插入数据。这是我的add.ctp文件

<div class="row form-main">
  <div class="panel panel-default">
    <div class="panel-body">
      <?php echo $this->Form->create('Store', array('class'=>"contact-
          form")); 
      ?>
      <div class="form-group">
         <div class="col-sm-6">
      <?php 
      echo $this->Form->input('name',array('required'=>false,'class'=>"form-
      control",  'placeholder'=>"Enter Name","label"=>false)); 
      ?>
     </div>
     <div class="col-sm-6">
     <?php 
     echo $this->Form-
     >input('address1',array('required'=>false,'class'=>"form-control",  
    'placeholder'=>"Enter Address1","label"=>false)); 
     ?>
            </div>
          </div>
          <div class="form-group">        
            <div class="col-sm-offset-2 col-sm-10">
              <input type="submit" name="submit" value="Submit" class="btn 
              btn-success">
              <button type="submit" class="btn btn-info">Cancel</button>
            </div>
          </div>
         <?php echo $this->Form->end(); ?>

取消
这是我的StoresController.php

<?php
App::uses('AppController', 'Controller');
class StoresController extends AppController {
var $uses = array();
var $component = array("Common");
public $paginate = array();  


public function add(){
    $this->layout = 'user_layout';
    $user_id = $this->UserAuth->getUserId();
    $owner_id = $this->Common->getOwnerId($user_id);
    if ($this->request->is('post')) { 
        $this->Store->create(); 
        if ($this->Store->save($this->request->data)) { 
            $this->Flash->success(__('User has been Added')); 
            return $this->redirect(array('action' => 'add')); 
        } $this->Flash->error(__('Unable to add your post.')); 
    } 

}    

}

?>

我在控制器中的非对象上得到对成员函数create()的错误调用,您应该使用:

$this->Form->create('Store')


是的,我解决了这个问题。有个小问题。我忘记了控制器中的以下行:

var $uses = array('Store');

我还是遇到了同样的问题,你能展示一下你的模型吗。我可以看到您的型号名称是复数形式,因为它应该是单一的PAR CAKEPHP公约。
var $uses = array('Store');