Witam,
mam zagwozdkę i próbuję się z nią uporać od wczoraj.
Otóż, zdefiniowałem połączenie do bazy:
$app = new Silex\Application();
$app->register(new Silex\Provider\DoctrineServiceProvider(), array(
'db.options' => array(
'driver' => 'pdo_mysql',
'dbname' => 'crm',
'user' => 'root',
'password' => 'root',
'charset' => 'UTF8'
),
));
w phpMyAdmin, utworzyłem bazę danych o nazwie crm, z kodowaniem UTF8-Polish-ci.
Napisałem funkcję getClients, pobierającą wszystkich klientów z bazy danych:
public function getClients()
{
$sql = "SELECT c.*, cs.name as sector_name, u.name as account_manager_name FROM clients as c LEFT JOIN company_sectors as cs ON c.sector_id = cs.id LEFT JOIN users as u ON c.account_manager_id = u.id";
return $this->db->fetchAll($sql);
}
i pare linijek z JSa:
app.js
app.controller('ClientsListCtrl', ['$scope','clients', function($scope, clients){
$scope.clients = [];
clients.getClients(function (clients){
$scope.clients = clients;
console.log($scope.clients);
});
}]);
services.js
(function(){
var app = angular.module('crmService', []);
app.factory('clients',['$http', function($http){
var _getClients = function (callback){
callback = callback||function(){};
$http.get('/api.php/clients')
.success(function(data){
callback(data);
});
};
return {
getClients: _getClients
};
}]);
})();
i log z konsoli google chrome (próbowałem też IE, Mozillą i to samo błąd 500):
http://fotserv.pl/?topic=load&image=1461309196-Capture.JPG
Jednak ciągle wydaje mi się, że powyższy kod jest dobry, a coś jest nie tak z połączeniem do bazy danych. Proszę o pomoc.