Kind of modelling my latest project after Vokuro and running into an issue. When I try to do User::findFirst([...]), I'm getting a 500 error that " Class 'Zipline\Controllers\User' not found in /var/www/html/zipline/app/controllers/NoauthajaxController.php on line 11"
Here is part of my config:
'application' => [
'controllersDir' => APP_PATH . '/controllers/',
'modelsDir' => APP_PATH . '/models/',
//'formsDir' => APP_PATH . '/forms/',
'viewsDir' => APP_PATH . '/views/',
'libraryDir' => APP_PATH . '/library/',
//'pluginsDir' => APP_PATH . '/plugins/',
//'cacheDir' => BASE_PATH . '/cache/',
],
Here is my loader:
<?php
use Phalcon\Loader;
$loader = new Loader();
/**
* We're a registering a set of directories taken from the configuration file
*/
$loader->registerNamespaces([
'Zipline\Models' => $config->application->modelsDir,
'Zipline\Controllers' => $config->application->controllersDir,
//'Zipline\Forms' => $config->application->formsDir,
'Zipline' => $config->application->libraryDir
]);
$loader->register();
// Use composer autoloader to load vendor classes
require_once BASE_PATH . '/vendor/autoload.php';
Here is my controller:
<?php namespace Zipline\Controllers;
use Phalcon\Http\Response;
use Phalcon\Http\Request;
class NoauthajaxController extends ControllerBase {
public function userloginAction() {
$response = $this->getResponse();
$request = $this->getRequest();
$U = User::findFirst([
'conditions' => 'email = :username:',
'bind' => [
'username' => $request->username
]
]);
if (empty($U)) {
$response['error'] = "Invalid username or password.";
} else if ($U->login($request)) {
$response['success'] = true;
$response['data']['user'] = $this->session->get('auth_user');
} else {
$response['error'] = $this->errors($U->getMessages());
}
$this->respond($response);
}
}
Here is my model:
<?php namespace Zipline\Models;
use Phalcon\Mvc\Model;
use Phalcon\Mvc\Model\Message;
/*
use Phalcon\Validation;
use Phalcon\Mvc\Model\Validator\Uniqueness;
use Phalcon\Mvc\Model\Validator\Email;
use Phalcon\Mvc\Model\Validator\PresenceOf;
use Phalcon\Mvc\Model\Behavior\SoftDelete;
*/
class User extends Model {
public function initialize() {
$this->setSource("users");
}
public function login() {
var_dump($this->toArray());
}
}
Trying to make this as simple as possible, but for some reason when I call User::findFirst, it's thinking I'm looking for a controller named User... Not the model.