我在表单中工作,每个表单都有很多输入,现在用于在我的数据库中插入此输入我在cakephp 3中使用ajax一切正常,只是一个问题,当我想要返回数据库中插入数据时这个数据以代码html返回,我无法访问信息示例 - >状态,消息,数据。 在我的控制器中有这个:
public function insertPassenger()
{
$this->layout = 'ajax';
$passenger = $this->Passengers->newEntity();
$dato=$this->request->data();
if ($this->request->is('ajax')) {
$passenger = $this->Passengers->patchEntity($passenger, $this->request->data);
$passenger->date = date('Y-m-d H:i:s');
if ($this->Passengers->save($passenger)) {
$data = [
'content' => $dato,
'status' => 'success',
'message' => 'El pasajero fue registrado correctamente',
];
} else {
$data = [
'content' => $dato,
'status' => 'error',
'message' => 'Verifique los datos',
];
}
}
$this->set(compact('data')); // Pass $data to the view
$this->set('_serialize', 'data'); // Let the JsonView class know what variable to use
}
现在我的js有这个
$(document).on('submit','form',function(e) {
e.preventDefault();
var values = $(this).serialize();
var options = {};
$.ajax({
url: "/passengers/insertPassenger.json",
type: "post",
data: values,
success: function(dato){
console.log(dato);
},
error:function(e){
console.log(e)
}
});
});
这里的一切都很好,但是当打印结果显示Google Chrome与console.log(dato);
时,我已经完成了(最后我的信息很重要):
<pre class="cake-error"><a href="javascript:void(0);" onclick="document.getElementById('cakeErr5540307e9b1de-trace').style.display = (document.getElementById('cakeErr5540307e9b1de-trace').style.display == 'none' ? '' : 'none');"><b>Warning</b> (2)</a>: array_combine(): Both parameters should have an equal number of elements [<b>CORE/src/ORM/Rule/ExistsIn.php</b>, line <b>102</b>]<div id="cakeErr5540307e9b1de-trace" class="cake-stack-trace" style="display: none;"><a href="javascript:void(0);" onclick="document.getElementById('cakeErr5540307e9b1de-code').style.display = (document.getElementById('cakeErr5540307e9b1de-code').style.display == 'none' ? '' : 'none')">Code</a> <a href="javascript:void(0);" onclick="document.getElementById('cakeErr5540307e9b1de-context').style.display = (document.getElementById('cakeErr5540307e9b1de-context').style.display == 'none' ? '' : 'none')">Context</a><pre id="cakeErr5540307e9b1de-code" class="cake-code-dump" style="display: none;"><code><span style="color: #000000"><span style="color: #0000BB"> $primary</span><span style="color: #007700">,</span></span></code>
<span class="code-highlight"><code><span style="color: #000000"><span style="color: #0000BB"> $entity</span><span style="color: #007700">-></span><span style="color: #0000BB">extract</span><span style="color: #007700">(</span><span style="color: #0000BB">$this</span><span style="color: #007700">-></span><span style="color: #0000BB">_fields</span><span style="color: #007700">)</span></span></code></span>
<code><span style="color: #000000"><span style="color: #0000BB"> </span><span style="color: #007700">);</span></span></code></pre><pre id="cakeErr5540307e9b1de-context" class="cake-context" style="display: none;">$entity = object(App\Model\Entity\Passenger) {
'new' => true,
'accessible' => [
'travel_id' => true,
'nombre' => true,
'ci' => true,
'edad' => true,
'genero' => true,
'num_emergencia' => true,
'numero_asiento' => true,
'orden_asiento' => true,
'date' => true,
'update' => true,
'travel' => true,
'invoices' => true
],
'properties' => [
'nombre' => 'sasd',
'ci' => (int) 23,
'edad' => (int) 23,
'genero' => 'MASCULINO',
'num_emergencia' => (int) 21,
'numero_asiento' => '14',
'orden_asiento' => '4_2',
'travel_id' => (int) 1,
'date' => '2015-04-28 21:14:38'
],
'dirty' => [
'nombre' => true,
'ci' => true,
'edad' => true,
'genero' => true,
'num_emergencia' => true,
'numero_asiento' => true,
'orden_asiento' => true,
'travel_id' => true,
'date' => true
],
'original' => [],
'virtual' => [],
'errors' => [],
'repository' => 'Passengers'
}
$options = [
'errorField' => 'travel_id',
'message' => 'This value does not exist',
'atomic' => true,
'associated' => true,
'checkRules' => true,
'checkExisting' => true,
'_primary' => true,
'repository' => object(App\Model\Table\PassengersTable) {
'registryAlias' => 'Passengers',
'table' => 'passengers',
'alias' => 'Passengers',
'entityClass' => 'App\Model\Entity\Passenger',
'associations' => [
[maximum depth reached]
],
'behaviors' => [[maximum depth reached]],
'defaultConnection' => 'default',
'connectionName' => 'default'
}
]
$nulls = (int) 0
$schema = object(Cake\Database\Schema\Table) {
[protected] _table => 'travels'
[protected] _columns => [
'id' => [
[maximum depth reached]
],
'fecha_hora' => [
[maximum depth reached]
],
'precio' => [
[maximum depth reached]
],
'date' => [
[maximum depth reached]
],
'update' => [
[maximum depth reached]
],
'output_id' => [
[maximum depth reached]
],
'destination_id' => [
[maximum depth reached]
],
'user_id' => [
[maximum depth reached]
],
'bus_id' => [
[maximum depth reached]
]
]
[protected] _indexes => [
'fk_travels_outputs1_idx' => [
[maximum depth reached]
],
'fk_travels_destinations1_idx' => [
[maximum depth reached]
],
'fk_travels_users1_idx' => [
[maximum depth reached]
],
'fk_travels_buses1_idx' => [
[maximum depth reached]
]
]
[protected] _constraints => [
'primary' => [
[maximum depth reached]
],
'fk_travels_buses1' => [
[maximum depth reached]
],
'fk_travels_destinations1' => [
[maximum depth reached]
],
'fk_travels_outputs1' => [
[maximum depth reached]
],
'fk_travels_users1' => [
[maximum depth reached]
]
]
[protected] _options => [
'engine' => 'InnoDB',
'collation' => 'utf8_general_ci'
]
[protected] _temporary => false
[protected] _columnKeys => [
'type' => null,
'length' => null,
'precision' => null,
'null' => null,
'default' => null,
'comment' => null
]
[protected] _columnExtras => [
'string' => [
[maximum depth reached]
],
'integer' => [
[maximum depth reached]
],
'biginteger' => [
[maximum depth reached]
],
'decimal' => [
[maximum depth reached]
],
'float' => [
[maximum depth reached]
]
]
[protected] _indexKeys => [
'type' => null,
'columns' => [[maximum depth reached]],
'length' => [[maximum depth reached]],
'references' => [[maximum depth reached]],
'update' => 'restrict',
'delete' => 'restrict'
]
[protected] _validIndexTypes => [
(int) 0 => 'index',
(int) 1 => 'fulltext'
]
[protected] _validConstraintTypes => [
(int) 0 => 'primary',
(int) 1 => 'unique',
(int) 2 => 'foreign'
]
[protected] _validForeignKeyActions => [
(int) 0 => 'cascade',
(int) 1 => 'setNull',
(int) 2 => 'setDefault',
(int) 3 => 'noAction',
(int) 4 => 'restrict'
]
}
$field = 'travel_id'
$alias = 'Travels'
$primary = [
(int) 0 => 'Travels.id',
(int) 1 => 'Travels.output_id',
(int) 2 => 'Travels.destination_id',
(int) 3 => 'Travels.user_id',
(int) 4 => 'Travels.bus_id'
]</pre><pre class="stack-trace">array_combine - [internal], line ??
Cake\ORM\Rule\ExistsIn::__invoke() - CORE/src/ORM/Rule/ExistsIn.php, line 102
Cake\ORM\RulesChecker::Cake\ORM\{closure}() - CORE/src/ORM/RulesChecker.php, line 378
Cake\ORM\RulesChecker::Cake\ORM\{closure}() - CORE/src/ORM/RulesChecker.php, line 378
Cake\ORM\RulesChecker::checkCreate() - CORE/src/ORM/RulesChecker.php, line 258
Cake\ORM\RulesChecker::check() - CORE/src/ORM/RulesChecker.php, line 231
Cake\ORM\Table::checkRules() - CORE/src/ORM/Table.php, line 2148
Cake\ORM\Table::_processSave() - CORE/src/ORM/Table.php, line 1410
Cake\ORM\Table::Cake\ORM\{closure}() - CORE/src/ORM/Table.php, line 1367
Cake\Database\Connection::transactional() - CORE/src/Database/Connection.php, line 561
Cake\ORM\Table::save() - CORE/src/ORM/Table.php, line 1368
App\Controller\PassengersController::insertPassenger() - APP/Controller/PassengersController.php, line 170
Cake\Controller\Controller::invokeAction() - CORE/src/Controller/Controller.php, line 412
Cake\Routing\Dispatcher::_invoke() - CORE/src/Routing/Dispatcher.php, line 114
Cake\Routing\Dispatcher::dispatch() - CORE/src/Routing/Dispatcher.php, line 87
[main] - ROOT/webroot/index.php, line 37</pre></div></pre><pre class="cake-error"><a href="javascript:void(0);" onclick="document.getElementById('cakeErr5540307e9c451-trace').style.display = (document.getElementById('cakeErr5540307e9c451-trace').style.display == 'none' ? '' : 'none');"><b>Warning</b> (4096)</a>: Argument 1 passed to Cake\Database\Expression\QueryExpression::_addConditions() must be of the type array, boolean given, called in /home/widrogo/Code/estacion/vendor/cakephp/cakephp/src/Database/Expression/QueryExpression.php on line 123 and defined [<b>CORE/src/Database/Expression/QueryExpression.php</b>, line <b>478</b>]<div id="cakeErr5540307e9c451-trace" class="cake-stack-trace" style="display: none;"><a href="javascript:void(0);" onclick="document.getElementById('cakeErr5540307e9c451-code').style.display = (document.getElementById('cakeErr5540307e9c451-code').style.display == 'none' ? '' : 'none')">Code</a> <a href="javascript:void(0);" onclick="document.getElementById('cakeErr5540307e9c451-context').style.display = (document.getElementById('cakeErr5540307e9c451-context').style.display == 'none' ? '' : 'none')">Context</a><pre id="cakeErr5540307e9c451-code" class="cake-code-dump" style="display: none;"><code><span style="color: #000000"><span style="color: #0000BB"> </span><span style="color: #007700">* @return </span><span style="color: #0000BB">void</span></span></code>
<span class="code-highlight"><code><span style="color: #000000"><span style="color: #0000BB"> </span><span style="color: #007700">*/</span></span></code></span>
<code><span style="color: #000000"><span style="color: #0000BB"> </span><span style="color: #007700">protected function </span><span style="color: #0000BB">_addConditions</span><span style="color: #007700">(array </span><span style="color: #0000BB">$conditions</span><span style="color: #007700">, array </span><span style="color: #0000BB">$types</span><span style="color: #007700">)</span></span></code></pre><pre id="cakeErr5540307e9c451-context" class="cake-context" style="display: none;">$this = object(Cake\Database\Expression\QueryExpression) {
[protected] _conjunction => 'AND'
[protected] _conditions => []
[protected] _typeMap => object(Cake\Database\TypeMap) {}
}</pre><pre class="stack-trace">Cake\Database\Expression\QueryExpression::_addConditions() - CORE/src/Database/Expression/QueryExpression.php, line 478
Cake\Database\Expression\QueryExpression::add() - CORE/src/Database/Expression/QueryExpression.php, line 123
Cake\Database\Query::_conjugate() - CORE/src/Database/Query.php, line 1653
Cake\Database\Query::where() - CORE/src/Database/Query.php, line 761
Cake\ORM\Table::exists() - CORE/src/ORM/Table.php, line 1256
Cake\ORM\Association::__call() - CORE/src/ORM/Association.php, line 837
Cake\ORM\Association\BelongsTo::exists() - CORE/src/ORM/Rule/ExistsIn.php, line 103
Cake\ORM\Rule\ExistsIn::__invoke() - CORE/src/ORM/Rule/ExistsIn.php, line 103
Cake\ORM\RulesChecker::Cake\ORM\{closure}() - CORE/src/ORM/RulesChecker.php, line 378
Cake\ORM\RulesChecker::Cake\ORM\{closure}() - CORE/src/ORM/RulesChecker.php, line 378
Cake\ORM\RulesChecker::checkCreate() - CORE/src/ORM/RulesChecker.php, line 258
Cake\ORM\RulesChecker::check() - CORE/src/ORM/RulesChecker.php, line 231
Cake\ORM\Table::checkRules() - CORE/src/ORM/Table.php, line 2148
Cake\ORM\Table::_processSave() - CORE/src/ORM/Table.php, line 1410
Cake\ORM\Table::Cake\ORM\{closure}() - CORE/src/ORM/Table.php, line 1367
Cake\Database\Connection::transactional() - CORE/src/Database/Connection.php, line 561</pre></div></pre><pre class="cake-error"><a href="javascript:void(0);" onclick="document.getElementById('cakeErr5540307e9d172-trace').style.display = (document.getElementById('cakeErr5540307e9d172-trace').style.display == 'none' ? '' : 'none');"><b>Warning</b> (2)</a>: Invalid argument supplied for foreach() [<b>CORE/src/Database/Expression/QueryExpression.php</b>, line <b>484</b>]<div id="cakeErr5540307e9d172-trace" class="cake-stack-trace" style="display: none;"><a href="javascript:void(0);" onclick="document.getElementById('cakeErr5540307e9d172-code').style.display = (document.getElementById('cakeErr5540307e9d172-code').style.display == 'none' ? '' : 'none')">Code</a> <a href="javascript:void(0);" onclick="document.getElementById('cakeErr5540307e9d172-context').style.display = (document.getElementById('cakeErr5540307e9d172-context').style.display == 'none' ? '' : 'none')">Context</a><pre id="cakeErr5540307e9d172-code" class="cake-code-dump" style="display: none;"><code><span style="color: #000000"><span style="color: #0000BB"> $typeMap </span><span style="color: #007700">= </span><span style="color: #0000BB">$this</span><span style="color: #007700">-></span><span style="color: #0000BB">typeMap</span><span style="color: #007700">()-></span><span style="color: #0000BB">types</span><span style="color: #007700">(</span><span style="color: #0000BB">$types</span><span style="color: #007700">);</span></span></code>
<span class="code-highlight"><code><span style="color: #000000"><span style="color: #0000BB"></span></span></code></span>
<code><span style="color: #000000"><span style="color: #0000BB"> </span><span style="color: #007700">foreach (</span><span style="color: #0000BB">$conditions </span><span style="color: #007700">as </span><span style="color: #0000BB">$k </span><span style="color: #007700">=> </span><span style="color: #0000BB">$c</span><span style="color: #007700">) {</span></span></code></pre><pre id="cakeErr5540307e9d172-context" class="cake-context" style="display: none;">$this = object(Cake\Database\Expression\QueryExpression) {
[protected] _conjunction => 'AND'
[protected] _conditions => []
[protected] _typeMap => object(Cake\Database\TypeMap) {}
}
$conditions = false
$types = []
$operators = [
(int) 0 => 'and',
(int) 1 => 'or',
(int) 2 => 'xor'
]
$typeMap = object(Cake\Database\TypeMap) {
[protected] _defaults => [
'Travels.id' => 'integer',
'id' => 'integer',
'Travels.fecha_hora' => 'datetime',
'fecha_hora' => 'datetime',
'Travels.precio' => 'float',
'precio' => 'float',
'Travels.date' => 'datetime',
'date' => 'datetime',
'Travels.update' => 'datetime',
'update' => 'datetime',
'Travels.output_id' => 'integer',
'output_id' => 'integer',
'Travels.destination_id' => 'integer',
'destination_id' => 'integer',
'Travels.user_id' => 'integer',
'user_id' => 'integer',
'Travels.bus_id' => 'integer',
'bus_id' => 'integer'
]
[protected] _types => []
}</pre><pre class="stack-trace">Cake\Database\Expression\QueryExpression::_addConditions() - CORE/src/Database/Expression/QueryExpression.php, line 484
Cake\Database\Expression\QueryExpression::add() - CORE/src/Database/Expression/QueryExpression.php, line 123
Cake\Database\Query::_conjugate() - CORE/src/Database/Query.php, line 1653
Cake\Database\Query::where() - CORE/src/Database/Query.php, line 761
Cake\ORM\Table::exists() - CORE/src/ORM/Table.php, line 1256
Cake\ORM\Association::__call() - CORE/src/ORM/Association.php, line 837
Cake\ORM\Association\BelongsTo::exists() - CORE/src/ORM/Rule/ExistsIn.php, line 103
Cake\ORM\Rule\ExistsIn::__invoke() - CORE/src/ORM/Rule/ExistsIn.php, line 103
Cake\ORM\RulesChecker::Cake\ORM\{closure}() - CORE/src/ORM/RulesChecker.php, line 378
Cake\ORM\RulesChecker::Cake\ORM\{closure}() - CORE/src/ORM/RulesChecker.php, line 378
Cake\ORM\RulesChecker::checkCreate() - CORE/src/ORM/RulesChecker.php, line 258
Cake\ORM\RulesChecker::check() - CORE/src/ORM/RulesChecker.php, line 231
Cake\ORM\Table::checkRules() - CORE/src/ORM/Table.php, line 2148
Cake\ORM\Table::_processSave() - CORE/src/ORM/Table.php, line 1410
Cake\ORM\Table::Cake\ORM\{closure}() - CORE/src/ORM/Table.php, line 1367
Cake\Database\Connection::transactional() - CORE/src/Database/Connection.php, line 561</pre></div></pre>{
"content": {
"nombre": "sasd",
"ci": "23",
"edad": "23",
"genero": "MASCULINO",
"num_emergencia": "21",
"numero_asiento": "14",
"orden_asiento": "4_2",
"travel_id": "1"
},
"status": "success",
"message": "El pasajero fue registrado correctamente"
}