D
D
Denis2014-07-08 13:43:57
CakePHP
Denis, 2014-07-08 13:43:57

How to elegantly and competently make CakePHP and AngularJS friends?

CakePHP has CRUD generation out of the box
AngularJS has the beauty of services.
The question is how to competently connect them so as not to fence crutches on one of the sides?
If anyone has something to read, please post links.
While there is this:
angular

// описываем сервис
angular.module('adminServices', ['ngResource']).
    factory('Command', function($resource){
           return $resource('/api/commands', {}, {
           query: {method:'POST', params:{}, isArray:true},
  });
});

cake controller (crutch)
public function api_index() {
  
                if ($this->request->is('post')) {
                    $req = json_decode(file_get_contents('php://input'), true);
                    if (isset($req['action'])){
                        switch ($req['action']):
                            case 'add':
                                $this->Command->create();
                                $data = array('name' => $req['name'], 'shortdescription' => $req['short']);
                                $this->Command->save($data);
                            break;
                            case 'save':
                            // сохраняем
                            break;
                            case 'del':
                            // удаляем
                            break;
                        endswitch;
                        $this->set('out', $this->Command->find('all', array('order'=>array('Command.name'=>'ASC'))));
                      }else{
                          $this->set('out', $this->Command->find('all', array('order'=>array('Command.name'=>'ASC'))));
                          return true;
                      }
                }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Pavlov, 2014-07-09
@joseperez

Look at the implementation of the angular and yii bundle . Perhaps in Cakephp you can do something similar

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question