0
我試圖創建一個自定義查找,但我仍然有一個錯誤。自定義查詢cakephp3
在控制器代碼中的TableModel
class AnunciosController extends AppController
{
public function listaServicos($id = null)
{
$anuncios = $this->loadModel('Anuncios')->find('ByService', ['service_id' => $id]);
die(print_r($anuncios));
//$anuncios = $this->paginate($this->Anuncios);
//$this->set(compact('anuncios'));
//$this->set('_serialize', ['anuncios']);
}
}
代碼:
class AnunciosTable extends Table
{
public function findByService(\Cake\ORM\Query $query, array $options)
{
print_r($options);
$query = $this->find()
->select(['id','user_prof_id'])
->where(['service_id'=>$options['service_id']]);
$return = $query->execute();
return $return;
}
}
和運行之後,返回的是這樣的錯誤:
陣列([的service_id] => 7)
Cake\Database\Statement\CallbackStatement Object ([_callback:protected] => Cake\Database\FieldTypeConverter Object ([_typeMap:protected] => Array ([Anuncios__id] => Cake\Database\Type\IntegerType Object ([_name:protected] => integer) [Anuncios__user_prof_id] => Cake\Database\Type\IntegerType Object ([_name:protected] => integer)) [_driver:protected] => Cake\Database\Driver\Mysql Object ([connected] => 1)) [_statement:protected] => Cake\Database\Log\LoggingStatement Object ([_logger:protected] => DebugKit\Database\Log\DebugLog Object ([_queries:protected] => Array ([0] => Array ([query] => SELECT Facs.id AS `Facs__id`, Facs.name AS `Facs__name`, Facs.description AS `Facs__description`, Facs.created AS `Facs__created`, Facs.modified AS `Facs__modified` FROM facs Facs [took] => 2 [rows] => 8) [1] => Array ([query] => SELECT Servicos.id AS `Servicos__id`, Servicos.category_id AS `Servicos__category_id`, Servicos.name AS `Servicos__name`, Servicos.created AS `Servicos__created`, Servicos.modified AS `Servicos__modified` FROM servicos Servicos [took] => 1 [rows] => 53) [2] => Array ([query] => SELECT Anuncios.id AS `Anuncios__id`, Anuncios.user_prof_id AS `Anuncios__user_prof_id` FROM anuncios Anuncios WHERE service_id = 7 [took] => 1 [rows] => 0)) [_logger:protected] => [_connectionName:protected] => default [_totalTime:protected] => 4 [_totalRows:protected] => 61) [_compiledParams:protected] => Array ([c0] => 7) [_statement:protected] => Cake\Database\Statement\MysqlStatement Object ([_statement:protected] => PDOStatement Object ([queryString] => SELECT Anuncios.id AS `Anuncios__id`, Anuncios.user_prof_id AS `Anuncios__user_prof_id` FROM anuncios Anuncios WHERE service_id = :c0) [_driver:protected] => Cake\Database\Driver\Mysql Object ([connected] => 1) [_hasExecuted:protected] => [_bufferResults:protected] => 1) [_driver:protected] => Cake\Database\Driver\Mysql Object ([connected] => 1) [_hasExecuted:protected] => 1) [_driver:protected] => Cake\Database\Driver\Mysql Object ([connected] => 1) [_hasExecuted:protected] =>) 1
Can a nyone helpme?什麼即時做錯了?
我改變了你說的代碼,但我仍然得到相同的錯誤。 :/ – Rodolfo
更多提示,可能是什麼問題? – Rodolfo