I got index.php, Models/empresas.php
on index->
try {
$loader = new \Phalcon\Loader();
$loader->registerDirs(array(
'models/'
))->register();
$di = new \Phalcon\DI\FactoryDefault();
//Set up the database service
$di->set('db', function(){
return new \Phalcon\Db\Adapter\Pdo\Mysql(array(
"host" => "localhost",
"username" => "username",
"password" => "password",
"dbname" => "db"
));
});
$app = new \Phalcon\Mvc\Micro();
$app->setDI($di);
//Retrieves all empresas
$app->get('/api/empresas', function() use ($app) {
$phql = "SELECT * FROM empresas ORDER BY Nombre";
$empresas = $app->modelsManager->executeQuery($phql);
$data = array();
foreach ($empresas as $empresa) {
$data[] = array(
'ID' => $empresa->ID,
'Nombre' => $empresa->Nombre,
);
}
echo json_encode($data);
});
//Retrive all semanas from empresa
$app->get('/api/empresas/suc/{suc_id}/year/{year}/week/{week}', function($suc_id,$year,$week) use ($app) {
$phql = "SELECT * FROM sec_configuracion WHERE year = :year: AND week = :week:";
$empresas = $app->modelsManager->executeQuery($phql);
$data = array();
foreach ($empresas as $k => $v) {
$data[] = array(
'ID' => $empresa->ID,
'Nombre' => $empresa->Nombre,
);
}
echo json_encode($data);
});
$app->handle();
} catch(\Phalcon\Exception $e) { echo "PhalconException: ", $e->getMessage(); }
on Models at empresas.php
use Phalcon\Mvc\Model,
Phalcon\Mvc\Model\Message,
Phalcon\Mvc\Model\Validator\InclusionIn,
Phalcon\Mvc\Model\Validator\Uniqueness;
class secconfiguracion extends Model
{
public function getSource()
{
return "sec_configuracion";
}
public function validation()
{
$this->validate(new Uniqueness(
array(
"field" => "ID",
"message" => "El id de 'Configuración' debe ser único"
)
));
if ($this->validationHasFailed() == true) {
return false;
}
}
}
class empresas extends Model
{
public function validation()
{
$this->validate(new Uniqueness(
array(
"field" => "ID",
"message" => "El id de la empresa debe ser único"
)
));
if ($this->validationHasFailed() == true) {
return false;
}
}
}
When I acces to -> https://www.sys21.com.mx/lanomina/api/empresas/
I get -> <code>[{"ID":"1","Nombre":"Del Campo"},{"ID":"2","Nombre":"Rodriguez"}]</code> but when I access to...
https://www.sys21.com.mx/lanomina/api/empresas/suc/1/year/2015/week/7
I get -> <code>PhalconException: Model 'sec_configuracion' could not be loaded</code>