Я управлял эшафотом «Красавица-фалькон», загруженным localhost:8000/beauties
и он загружается нормально, однако, когда я нажимаю ссылку Создать красоты, я получаю следующую ошибку:
BeautifyController handler class cannot be loaded
Я запускаю Phalcon, используя встроенный сервер php:
php -S localhost:8000 -e -t public/ public/htrouter.php
Htrouter.php
<?php
if (!file_exists(__DIR__ . '/' . $_SERVER['REQUEST_URI'])) {
$_GET['_url'] = $_SERVER['REQUEST_URI'];
}
return false;
BeautifyController:
<?php
use Phalcon\Mvc\Model\Criteria;
use Phalcon\Paginator\Adapter\Model as Paginator;
class BeautiesController extends ControllerBase
{
/**
* Index action
*/
public function indexAction()
{
$this->persistent->parameters = null;
}
/**
* Searches for beauties
*/
public function searchAction()
{
$numberPage = 1;
if ($this->request->isPost()) {
$query = Criteria::fromInput($this->di, "Beauties", $_POST);
$this->persistent->parameters = $query->getParams();
} else {
$numberPage = $this->request->getQuery("page", "int");
}
$parameters = $this->persistent->parameters;
if (!is_array($parameters)) {
$parameters = array();
}
$parameters["order"] = "id";
$beauties = Beauties::find($parameters);
if (count($beauties) == 0) {
$this->flash->notice("The search did not find any beauties");
return $this->dispatcher->forward(array(
"controller" => "beauties",
"action" => "index"));
}
$paginator = new Paginator(array(
"data" => $beauties,
"limit"=> 10,
"page" => $numberPage
));
$this->view->page = $paginator->getPaginate();
}
/**
* Displayes the creation form
*/
public function newAction()
{
}
/**
* Edits a beautie
*
* @param string $id
*/
public function editAction($id)
{
if (!$this->request->isPost()) {
$beautie = Beauties::findFirstByid($id);
if (!$beautie) {
$this->flash->error("beautie was not found");
return $this->dispatcher->forward(array(
"controller" => "beauties",
"action" => "index"));
}
$this->view->id = $beautie->id;
$this->tag->setDefault("id", $beautie->id);
$this->tag->setDefault("title", $beautie->title);
$this->tag->setDefault("image", $beautie->image);
$this->tag->setDefault("content", $beautie->content);
}
}
/**
* Creates a new beautie
*/
public function createAction()
{
if (!$this->request->isPost()) {
return $this->dispatcher->forward(array(
"controller" => "beauties",
"action" => "index"));
}
$beautie = new Beauties();
$beautie->title = $this->request->getPost("title");
$beautie->image = $this->request->getPost("image");
$beautie->content = $this->request->getPost("content");if (!$beautie->save()) {
foreach ($beautie->getMessages() as $message) {
$this->flash->error($message);
}
return $this->dispatcher->forward(array(
"controller" => "beauties",
"action" => "new"));
}
$this->flash->success("beautie was created successfully");
return $this->dispatcher->forward(array(
"controller" => "beauties",
"action" => "index"));
}
/**
* Saves a beautie edited
*
*/
public function saveAction()
{
if (!$this->request->isPost()) {
return $this->dispatcher->forward(array(
"controller" => "beauties",
"action" => "index"));
}
$id = $this->request->getPost("id");
$beautie = Beauties::findFirstByid($id);
if (!$beautie) {
$this->flash->error("beautie does not exist " . $id);
return $this->dispatcher->forward(array(
"controller" => "beauties",
"action" => "index"));
}
$beautie->title = $this->request->getPost("title");
$beautie->image = $this->request->getPost("image");
$beautie->content = $this->request->getPost("content");if (!$beautie->save()) {
foreach ($beautie->getMessages() as $message) {
$this->flash->error($message);
}
return $this->dispatcher->forward(array(
"controller" => "beauties",
"action" => "edit",
"params" => array($beautie->id)
));
}
$this->flash->success("beautie was updated successfully");
return $this->dispatcher->forward(array(
"controller" => "beauties",
"action" => "index"));
}
/**
* Deletes a beautie
*
* @param string $id
*/
public function deleteAction($id)
{
$beautie = Beauties::findFirstByid($id);
if (!$beautie) {
$this->flash->error("beautie was not found");
return $this->dispatcher->forward(array(
"controller" => "beauties",
"action" => "index"));
}
if (!$beautie->delete()) {
foreach ($beautie->getMessages() as $message) {
$this->flash->error($message);
}
return $this->dispatcher->forward(array(
"controller" => "beauties",
"action" => "search"));
}
$this->flash->success("beautie was deleted successfully");
return $this->dispatcher->forward(array(
"controller" => "beauties",
"action" => "index"));
}
}
Htaccess:
AddDefaultCharset UTF-8
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>
Есть идеи?
В вашем файле BeautifyController.php имя контроллера не BeautifyController, а BeautiesController.
Я думаю, что это твоя проблема.
Возможно, если вы расскажете нам, что еще вы сделали в маршрутизации Phalcon, мы могли бы помочь в дальнейшем.
Других решений пока нет …