簡體   English   中英

控制器處理程序類無法加載

[英]Controller handler class cannot be loaded

我運行了一個腳手架“ phalcon腳手架美女”,將其加載到localhost:8000/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>

有任何想法嗎?

在BeautifyController.php文件中,控制器名稱不是BeautifyController,而是BeautiesController。 我認為那是你的問題。

也許,如果您告訴我們您在Phalcon航線中還做了什么,我們可能會提供進一步的幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM