【问题标题】:Custom controllers in UserFrostingUserFrosting 中的自定义控制器
【发布时间】:2016-11-09 15:22:30
【问题描述】:

我一直在尝试创建一个自定义控制器来扩展 UserFrostingBaseController,然后从 index.php 调用它的方法。看起来很简单,但到目前为止我非常不成功。我是 UserFrosting 的新手,因此我很可能遗漏了一些明显的东西。

控制器/LGController.php:

<?php
namespace UserFrosting;
class LGController extends \UserFrosting\BaseController {
    public function __construct($app){
        $this->_app = $app;
    }

    public function lgRequestsList(){
        $groups = array('Luke #1', 'Luke #2');
            $this->_app->render('lg-request-list.twig', [
                "groups" => $groups
            ]);
    }
}

index.php:

...
    use UserFrosting as UF;

    $app->get('/lg/requests/?', function () use ($app) {
        $controller = new UF\LGController($app);
        return $controller->lgRequestsList();
    }); 
...

错误:

[Wed Nov 09 15:25:40 2016] [warn] [client 160.34.126.11] mod_fcgid: stderr: Fatal error (1) in /home2/test/public_html/index.php on line 66: Class 'UserFrosting\\LGController' not found, referer: http://xxx.co.uk/groups/g/1/auth

【问题讨论】:

  • 错误是什么?
  • 也..您不需要构造函数,因为它将从基本控制器继承..只有当您的类具有自定义属性时,您才需要自定义构造函数
  • 你有控制器吗?
  • 你的意思是php的include()吗?
  • 是的,这就是我写的。

标签: php slim userfrosting


【解决方案1】:

不要使用include 来包含您的新控制器类。 UserFrosting 使用Composer 自动加载您的文件。

一旦你install Composer globally,你需要做的就是在你的userfrosting/子目录中运行composer dump-autoload,它会为你添加新的类。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-12
    • 2016-09-27
    相关资源
    最近更新 更多