I followed tutorial 3: Create a simpel REST API, and I just can't understand why Apache registers this error:
Call to undefined method Phalcon\Mvc\Application::get() in C:\wamp\www\followapp\api\v1\public\index.php
This is my code:
index.php
<?php
$loader = new \Phalcon\Loader();
$loader->registerDirs(array(
__DIR__ . '/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" => "root",
"password" => "",
"dbname" => "followapp"
));
});
$app = new Phalcon\Mvc\Micro($di);
//Retrieves all robots
$app->get('/users', function() use ($app) {
$phql = "SELECT * FROM user ORDER BY username";
$users = $app->modelsManager->executeQuery($phql);
$data = array();
foreach ($users as $user) {
$data[] = array(
'id' => $user->id,
'name' => $user->name,
);
}
echo json_encode($data);
});
$app->handle();
?>
users.php
<?php
use Phalcon\Mvc\Model,
Phalcon\Mvc\Model\Message,
Phalcon\Mvc\Model\Validator\Uniqueness;
class Users extends Model
{
public function validation()
{
//Robot name must be unique
$this->validate(new Uniqueness(
array(
"field" => "username",
"message" => "The user name must be unique"
)
));
//Check if any messages have been produced
if ($this->validationHasFailed() == true) {
return false;
}
}
}
?>
I'm running Phalcon 2.0.0 on Apache 2.2.22 and PHP 5.4.3 with WAMP Server on a Windows 7 machine.