ajax-запрос laravel к ajax-запросу cakephp

Я хочу переключиться с laravel и использовать cakephp для своего проекта, но у меня проблема с выполнением той же функции:

в Laravel:

    public function posts() {

// retrieve params
$search = Input::get('search');
$param = Input::get('param');

if (Request::wantsJson()) {
if (strlen($search) >= '2') {
// define wich param to get
if ($param == 'ratname') {
// query with name
$posts = Post::where('name', 'LIKE', ''.$search.'%')
->get();
} elseif ($param == 'ratid') {
// query with id
$posts = Post::where('idLord', 'LIKE', ''.$search.'%')
->get();
} else {
// query normal
$posts = Post::get();
}
return $posts;
}
}
}

в CakePHP:

public function posts_ajax() {

// IS AJAX : VIEW SEPARATE WAY
if ($this->request->is('ajax')) {

$this->layout = null;
$this->autoRender = false;

// ANTI-SURCHARGE DE BDD
if (strlen($this->request->query['search']) >= '2') {

// CHARGEMENT MODEL : RATOUSEARCH
$this->loadModel('Ratousearch');

// param separate way
if($this->request->query['param'] == 'ratname') {
// QUERY => Requête de find ( 'all') : ratousearch ('name') | SANS CACHE
$posts = $this->Ratousearch->find('all', array(
'conditions' => array(
'Ratousearch.name LIKE' => ''.$this->request->query['search'].'%'),
'order' => array('Ratousearch.name' => 'asc')
));
} else if($this->request->query['param'] == 'ratid') {
// QUERY => Requête de find ( 'all') : ratousearch ('idLord') | SANS CACHE
$posts = $this->Ratousearch->find('all', array(
'conditions' => array(
'Ratousearch.idLord LIKE' => ''.$this->request->query['search'].'%'),
'order' => array('Ratousearch.idLord' => 'asc')
));
}

//print_r($posts);
$posts = (Set::extract('/Ratousearch/.', $posts)); // hide model
$this->set(compact('posts'));

} else {
// do nothing...
}

} else {

// ANTI-SURCHARGE DE BDD
if (strlen($this->request->query['search']) >= '2') {

// CHARGEMENT MODEL : RATOUSEARCH
$this->loadModel('Ratousearch');

// param separate way
if($this->request->query['param'] == 'ratname') {
// QUERY => Requête de find ( 'all') : ratousearch ('name') | SANS CACHE
$posts = $this->Ratousearch->find('all', array(
'conditions' => array(
'Ratousearch.name LIKE' => ''.$this->request->query['search'].'%'),
'order' => array('Ratousearch.name' => 'asc')
));
} else if($this->request->query['param'] == 'ratid') {
// QUERY => Requête de find ( 'all') : ratousearch ('idLord') | SANS CACHE
$posts = $this->Ratousearch->find('all', array(
'conditions' => array(
'Ratousearch.idLord LIKE' => ''.$this->request->query['search'].'%'),
'order' => array('Ratousearch.idLord' => 'asc')
));
}

// setters
echo "<pre>";
print_r(Set::extract('/Ratousearch/.', $posts)); // hide model
echo "</pre>";

} else {
// do nothing...
}

}

}

Я вызываю функцию из удаленного приложения angularjs, с laravel она работает хорошо, но с cakephp ничего не возвращается, запрос пуст ….

Что я пропустил, когда написал код для cakephp?

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector