无法加载控制器处理程序类

时间:2015-01-01 21:49:45

标签: php phalcon phalcon-routing

我跑了一个脚手架" phalcon脚手架美女"加载localhost:8000/beauties并且加载正常,但是当我单击Create beauties链接时,我收到以下错误:

BeautifyController handler class cannot be loaded 

我使用php的内置服务器运行Phalcon:

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>

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

在BeautifyController.php文件中,controllername不是BeautifyController,而是BeautiesController。 我认为这是你的问题。

也许如果你告诉我们你在Phalcon路由中做了什么,我们可能会进一步提供帮助。