CakePHP
  • 文档
    • 书籍
    • API
    • 视频
    • 报告安全问题
    • 隐私政策
    • 标识和商标
  • 商业解决方案
  • 商品
  • 公路旅行
  • 团队
  • 社区
    • 社区
    • 参与
    • 问题 (Github)
    • 烘焙坊
    • 精选资源
    • 培训
    • 聚会
    • 我的 CakePHP
    • CakeFest
    • 新闻通讯
    • 领英
    • YouTube
    • Facebook
    • 推特
    • Mastodon
    • 帮助和支持
    • 论坛
    • Stack Overflow
    • IRC
    • Slack
    • 付费支持
CakePHP

C CakePHP 5.1 Chiffon API

  • 项目
    • CakePHP
      • CakePHP
      • Chronos
      • Elastic Search
      • 队列
  • 版本
    • 5.1
      • 5.1
      • 5.0
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

命名空间

  • 全局
  • Cake
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Form
    • Http
      • Client
      • Cookie
      • Exception
      • Middleware
      • Session
      • TestSuite
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View

类 BaseApplication

全栈应用程序的基类

此类充当将 CakePHP 用作全栈框架的应用程序的基类。如果您只使用 Http 或 Console 库,则应直接实现相关的接口。

应用程序类负责引导应用程序,并确保附加了中间件。它还被调用为最后一个中间件,并将请求/响应处理委托给正确的控制器。

抽象
命名空间: Cake\Http

属性摘要

  • $_eventClass protected
    string

    新事件对象的默认类名。

  • $_eventManager protected
    Cake\Event\EventManagerInterface|null

    Cake\Event\EventManager 实例,此对象使用它来调度内部事件。

  • $configDir protected
    string
  • $container protected
    Cake\Core\ContainerInterface|null

    容器

  • $controllerFactory protected
    Cake\Http\ControllerFactoryInterface|null

    控制器工厂

  • $plugins protected
    Cake\Core\PluginCollection

    插件集合

方法摘要

  • __construct() public

    构造函数

  • addOptionalPlugin() public

    添加可选插件

  • addPlugin() public

    将插件添加到已加载的插件集中。

  • bootstrap() public

    加载所有应用程序配置和引导逻辑。

  • buildContainer() protected

    构建服务容器

  • console() public

    为应用程序定义控制台命令。

  • dispatchEvent() public

    创建和调度事件的包装器。

  • events() public

    注册应用程序事件。

  • getContainer() public

    获取应用程序的依赖注入容器。

  • getEventManager() public

    返回此对象的 Cake\Event\EventManager 管理器实例。

  • getPlugins() public

    获取正在使用的插件集合。

  • handle() public

    调用应用程序。

  • middleware() abstract public

    为应用程序定义 HTTP 中间件层。

  • pluginBootstrap() public

    运行已加载插件的引导逻辑。

  • pluginConsole() public

    运行插件的控制台钩子

  • pluginEvents() public
  • pluginMiddleware() public

    运行插件的中间件钩子

  • pluginRoutes() public

    运行已加载插件的路由钩子

  • routes() public

    为应用程序定义路由。

  • services() public

    注册应用程序容器服务。

  • setEventManager() public

    返回此对象的 Cake\Event\EventManagerInterface 实例。

方法详细信息

__construct() ¶ public

__construct(string $configDir, Cake\Event\EventManagerInterface|null $eventManager = null, Cake\Http\ControllerFactoryInterface|null $controllerFactory = null)

构造函数

参数
string $configDir

保存引导配置的目录。

Cake\Event\EventManagerInterface|null $eventManager 可选

应用程序事件管理器实例。

Cake\Http\ControllerFactoryInterface|null $controllerFactory 可选

控制器工厂。

addOptionalPlugin() ¶ public

addOptionalPlugin(Cake\Core\PluginInterface|string $name, array<string, mixed> $config = []): $this

添加可选插件

如果它不可用,则忽略它。

参数
Cake\Core\PluginInterface|string $name

插件名称或插件对象。

array<string, mixed> $config 可选

如果使用 $name 的字符串,则为插件的配置数据

返回值
$this

addPlugin() ¶ public

addPlugin(Cake\Core\PluginInterface|string $name, array<string, mixed> $config = []): $this

将插件添加到已加载的插件集中。

如果命名插件不存在,或者没有定义 Plugin 类,则将使用 Cake\Core\BasePlugin 的实例。此生成的类将启用所有插件钩子。

参数
Cake\Core\PluginInterface|string $name
array<string, mixed> $config 可选
返回值
$this

bootstrap() ¶ public

bootstrap(): void

加载所有应用程序配置和引导逻辑。

覆盖此方法以添加应用程序的额外引导逻辑。

返回值
void

buildContainer() ¶ protected

buildContainer(): Cake\Core\ContainerInterface

构建服务容器

如果您需要使用自定义容器或想要更改容器的构建方式,请覆盖此方法。

返回值
Cake\Core\ContainerInterface

console() ¶ public

console(Cake\Console\CommandCollection $commands): Cake\Console\CommandCollection

为应用程序定义控制台命令。

默认情况下,CakePHP、插件和应用程序中的所有命令都将使用基于约定的名称加载。

参数
Cake\Console\CommandCollection $commands

要添加命令的 CommandCollection。

返回值
Cake\Console\CommandCollection

dispatchEvent() ¶ public

dispatchEvent(string $name, array $data = [], TSubject|null $subject = null): Cake\Event\EventInterface<TSubject>

创建和调度事件的包装器。

返回一个已分派的事件。

参数
string $name

事件的名称。

array $data 可选

您希望通过此事件传输的任何值,监听器都可以读取。

TSubject|null $subject 可选

此事件适用的对象(默认情况下为 $this)。

返回值
Cake\Event\EventInterface<TSubject>

events() ¶ public

events(Cake\Event\EventManagerInterface $eventManager): Cake\Event\EventManagerInterface

注册应用程序事件。

参数
Cake\Event\EventManagerInterface $eventManager

要注册监听器的全局事件管理器

返回值
Cake\Event\EventManagerInterface

getContainer() ¶ public

getContainer(): Cake\Core\ContainerInterface

获取应用程序的依赖注入容器。

第一次获取容器时,它将被构造并存储以供将来调用。

返回值
Cake\Core\ContainerInterface

getEventManager() ¶ public

getEventManager(): Cake\Event\EventManagerInterface

返回此对象的 Cake\Event\EventManager 管理器实例。

您可以使用此实例将任何新的监听器或回调注册到对象事件,或者创建自己的事件并按需触发它们。

返回值
Cake\Event\EventManagerInterface

getPlugins() ¶ public

getPlugins(): Cake\Core\PluginCollection

获取正在使用的插件集合。

返回值
Cake\Core\PluginCollection

handle() ¶ public

handle(ServerRequestInterface $request): Psr\Http\Message\ResponseInterface

调用应用程序。

  • 将请求添加到容器,使其能够注入到其他服务中。
  • 创建将处理此请求的控制器。
  • 调用控制器。
参数
ServerRequestInterface $request

请求

返回值
Psr\Http\Message\ResponseInterface

middleware() ¶ 抽象 公共

middleware(Cake\Http\MiddlewareQueue $middlewareQueue): Cake\Http\MiddlewareQueue

为应用程序定义 HTTP 中间件层。

参数
Cake\Http\MiddlewareQueue $middlewareQueue

在您的 App 类中设置的中间件队列

返回值
Cake\Http\MiddlewareQueue

pluginBootstrap() ¶ 公共

pluginBootstrap(): void

运行已加载插件的引导逻辑。

返回值
void

pluginConsole() ¶ 公共

pluginConsole(Cake\Console\CommandCollection $commands): Cake\Console\CommandCollection

运行插件的控制台钩子

参数
Cake\Console\CommandCollection $commands
返回值
Cake\Console\CommandCollection

pluginEvents() ¶ 公共

pluginEvents(Cake\Event\EventManagerInterface $eventManager): Cake\Event\EventManagerInterface
参数
Cake\Event\EventManagerInterface $eventManager

要注册监听器的全局事件管理器

返回值
Cake\Event\EventManagerInterface

pluginMiddleware() ¶ 公共

pluginMiddleware(Cake\Http\MiddlewareQueue $middleware): Cake\Http\MiddlewareQueue

运行插件的中间件钩子

参数
Cake\Http\MiddlewareQueue $middleware
返回值
Cake\Http\MiddlewareQueue

pluginRoutes() ¶ 公共

pluginRoutes(Cake\Routing\RouteBuilder $routes): Cake\Routing\RouteBuilder

运行已加载插件的路由钩子

参数
Cake\Routing\RouteBuilder $routes
返回值
Cake\Routing\RouteBuilder

routes() ¶ 公共

routes(Cake\Routing\RouteBuilder $routes): void

为应用程序定义路由。

默认情况下,这将加载 config/routes.php 以便于使用和向后兼容。

参数
Cake\Routing\RouteBuilder $routes

一个路由构建器,用于添加路由。

返回值
void

services() ¶ 公共

services(Cake\Core\ContainerInterface $container): void

注册应用程序容器服务。

已注册的服务可以使用 get() 从容器中获取实例。依赖项和参数将根据服务定义进行解析。

参数
Cake\Core\ContainerInterface $container

要更新的容器。

返回值
void

setEventManager() ¶ 公共

setEventManager(Cake\Event\EventManagerInterface $eventManager): $this

返回此对象的 Cake\Event\EventManagerInterface 实例。

您可以使用此实例将任何新的监听器或回调注册到对象事件,或者创建自己的事件并按需触发它们。

参数
Cake\Event\EventManagerInterface $eventManager

要设置的事件管理器

返回值
$this

属性详情

$_eventClass ¶ 受保护的

新事件对象的默认类名。

类型
string

$_eventManager ¶ 受保护的

Cake\Event\EventManager 实例,此对象使用它来调度内部事件。

类型
Cake\Event\EventManagerInterface|null

$configDir ¶ 受保护的

类型
string

$container ¶ 受保护的

容器

类型
Cake\Core\ContainerInterface|null

$controllerFactory ¶ 受保护的

控制器工厂

类型
Cake\Http\ControllerFactoryInterface|null

$plugins ¶ 受保护的

插件集合

类型
Cake\Core\PluginCollection
OpenHub
Pingping
Linode
  • 商业解决方案
  • 展示
  • 文档
  • 书籍
  • API
  • 视频
  • 报告安全问题
  • 隐私政策
  • 标识和商标
  • 社区
  • 参与
  • 问题 (Github)
  • 烘焙坊
  • 精选资源
  • 培训
  • 聚会
  • 我的 CakePHP
  • CakeFest
  • 新闻通讯
  • 领英
  • YouTube
  • Facebook
  • 推特
  • Mastodon
  • 帮助和支持
  • 论坛
  • Stack Overflow
  • IRC
  • Slack
  • 付费支持

使用 CakePHP API 文档 生成