Class yii\console\controllers\ServeController
运行 PHP 内置 web 服务器。
要从远程计算机访问服务器,请使用 0.0.0.0:8000。这在虚拟机中运行服务器 时特别有用。
公共属性
属性 | 类型 | 描述 | 被定义在 |
---|---|---|---|
$action | yii\base\Action | The action that is currently being executed. | yii\base\Controller |
$behaviors | yii\base\Behavior[] | List of behaviors attached to this component | yii\base\Component |
$color | boolean | 是否在输出中启用 ANSI 颜色。 如果未设置,则仅为支持 ANSI 颜色的终端启用 ANSI 颜色。 | yii\console\Controller |
$defaultAction | string | The ID of the action that is used when the action ID is not specified in the request. | yii\base\Controller |
$docroot | string | 路径或 path alias 到服务的目录 | yii\console\controllers\ServeController |
$help | boolean | 是否显示有关当前命令的帮助信息。 | yii\console\Controller |
$helpSummary | string | yii\console\Controller | |
$id | string | The ID of this controller. | yii\base\Controller |
$interactive | boolean | 是否以交互方式运行命令。 | yii\console\Controller |
$layout | null|string|false | The name of the layout to be applied to this controller's views. | yii\base\Controller |
$module | yii\base\Module | The module that this controller belongs to. | yii\base\Controller |
$modules | yii\base\Module[] | All ancestor modules that this controller is located within. | yii\base\Controller |
$passedOptionValues | array | 与传递的选项对应的属性 | yii\console\Controller |
$passedOptions | array | 执行期间传递的选项的名称 | yii\console\Controller |
$port | integer | 提供服务的端口。 | yii\console\controllers\ServeController |
$route | string | The route (module ID, controller ID and action ID) of the current request. | yii\base\Controller |
$router | string | 路由器脚本的路径。 See https://secure. | yii\console\controllers\ServeController |
$uniqueId | string | The controller ID that is prefixed with the module ID (if any). | yii\base\Controller |
$view | yii\base\View|yii\web\View | The view object that can be used to render views or view files. | yii\base\Controller |
$viewPath | string | The directory containing the view files for this controller. | yii\base\Controller |
公共方法
方法 | 描述 | 被定义在 |
---|---|---|
__call() | Calls the named method which is not a class method. | yii\base\Component |
__clone() | This method is called after the object is created by cloning an existing one. | yii\base\Component |
__construct() | yii\base\Controller | |
__get() | Returns the value of a component property. | yii\base\Component |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\base\Component |
__set() | Sets the value of a component property. | yii\base\Component |
__unset() | Sets a component property to be null. | yii\base\Component |
actionIndex() | 运行 PHP 内置 web 服务器。 | yii\console\controllers\ServeController |
actions() | Declares external actions for the controller. | yii\base\Controller |
afterAction() | This method is invoked right after an action is executed. | yii\base\Controller |
ansiFormat() | 使用 ANSI 代码格式化字符串。 | yii\console\Controller |
attachBehavior() | Attaches a behavior to this component. | yii\base\Component |
attachBehaviors() | Attaches a list of behaviors to the component. | yii\base\Component |
beforeAction() | This method is invoked right before an action is executed. | yii\base\Controller |
behaviors() | Returns a list of behaviors that this component should behave as. | yii\base\Component |
bindActionParams() | 将参数绑定到动作。 当 yii\base\Action 开始使用给定的参数运行时,此方法被调用。 此方法首先将参数与操作可用的 options绑定。 然后验证给定的参数。 | yii\console\Controller |
canGetProperty() | Returns a value indicating whether a property can be read. | yii\base\Component |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\base\Component |
className() | Returns the fully qualified name of this class. | yii\base\BaseObject |
confirm() | 要求用户通过键入 y 或 n 来确认。 | yii\console\Controller |
createAction() | Creates an action based on the given action ID. | yii\base\Controller |
detachBehavior() | Detaches a behavior from the component. | yii\base\Component |
detachBehaviors() | Detaches all behaviors from the component. | yii\base\Component |
ensureBehaviors() | Makes sure that the behaviors declared in behaviors() are attached to this component. | yii\base\Component |
findLayoutFile() | Finds the applicable layout file. | yii\base\Controller |
getActionArgsHelp() | 返回动作的匿名参数的帮助信息。 | yii\console\Controller |
getActionHelp() | 返回指定动作的详细帮助信息。 | yii\console\Controller |
getActionHelpSummary() | 返回描述指定动作的一行简短摘要。 | yii\console\Controller |
getActionOptionsHelp() | 返回动作选项的帮助信息。 | yii\console\Controller |
getBehavior() | Returns the named behavior object. | yii\base\Component |
getBehaviors() | Returns all behaviors attached to this component. | yii\base\Component |
getHelp() | 返回此控制器的帮助信息。 | yii\console\Controller |
getHelpSummary() | 返回描述此控制器的一行简短摘要。 | yii\console\Controller |
getModules() | Returns all ancestor modules of this controller. | yii\base\Controller |
getOptionValues() | 返回与动作 ID 的选项对应的属性 子类可以重写此方法以指定可能的属性。 | yii\console\Controller |
getPassedOptionValues() | 返回与传递的选项对应的属性。 | yii\console\Controller |
getPassedOptions() | 返回执行期间传递的有效选项的名称。 | yii\console\Controller |
getRoute() | Returns the route of the current request. | yii\base\Controller |
getUniqueId() | Returns the unique ID of the controller. | yii\base\Controller |
getView() | Returns the view object that can be used to render views or view files. | yii\base\Controller |
getViewPath() | Returns the directory containing view files for this controller. | yii\base\Controller |
hasEventHandlers() | Returns a value indicating whether there is any handler attached to the named event. | yii\base\Component |
hasMethod() | Returns a value indicating whether a method is defined. | yii\base\Component |
hasProperty() | Returns a value indicating whether a property is defined for this component. | yii\base\Component |
init() | Initializes the object. | yii\base\BaseObject |
isColorEnabled() | 返回一个指示是否启用 ANSI 颜色的值。 | yii\console\Controller |
off() | Detaches an existing event handler from this component. | yii\base\Component |
on() | Attaches an event handler to an event. | yii\base\Component |
optionAliases() | 返回选项别名。 子类可以重写此方法以指定别名选项。 | yii\console\controllers\ServeController |
options() | 返回操作的有效选项的动作(id) 选项要求存在一个名为选项名的 公共成员变量。 子类可以重写此方法以指定可能的选项。 | yii\console\controllers\ServeController |
prompt() | 提示用户输入并验证它。 | yii\console\Controller |
render() | Renders a view and applies layout if available. | yii\base\Controller |
renderContent() | Renders a static string by applying a layout. | yii\base\Controller |
renderFile() | Renders a view file. | yii\base\Controller |
renderPartial() | Renders a view without applying layout. | yii\base\Controller |
run() | Runs a request specified in terms of a route. | yii\base\Controller |
runAction() | 使用指定的动作 ID 和参数运行动作。 如果动作 ID 为空,则该方法将使用 $defaultAction。 | yii\console\Controller |
select() | 为用户提供可供选择的选项。给予 '?' 作为输入将显示 可供选择的选项列表及其解释。 | yii\console\Controller |
setView() | Sets the view object to be used by this controller. | yii\base\Controller |
setViewPath() | Sets the directory that contains the view files. | yii\base\Controller |
stderr() | 将字符串打印到 STDERR。 | yii\console\Controller |
stdout() | 将字符串打印到 STDOUT。 | yii\console\Controller |
trigger() | Triggers an event. | yii\base\Component |
受保护的方法
方法 | 描述 | 被定义在 |
---|---|---|
getActionMethodReflection() | yii\console\Controller | |
isAddressTaken() | yii\console\controllers\ServeController | |
parseDocCommentDetail() | 返回 docblock 的完整描述。 | yii\console\Controller |
parseDocCommentSummary() | 返回 docblock 的第一行。 | yii\console\Controller |
parseDocCommentTags() | 将注释块解析为标记。 | yii\console\Controller |
Events
事件 | 类型 | 描述 | 被定义在 |
---|---|---|---|
EVENT_AFTER_ACTION | yii\base\ActionEvent | An event raised right after executing a controller action. | yii\base\Controller |
EVENT_BEFORE_ACTION | yii\base\ActionEvent | An event raised right before executing a controller action. | yii\base\Controller |
常量
常量 | 值 | 描述 | 被定义在 |
---|---|---|---|
EXIT_CODE_ADDRESS_TAKEN_BY_ANOTHER_PROCESS | 5 | yii\console\controllers\ServeController | |
EXIT_CODE_ADDRESS_TAKEN_BY_ANOTHER_SERVER | 4 | yii\console\controllers\ServeController | |
EXIT_CODE_ERROR | 1 | Deprecated 自 2.0.13。使用 \yii\console\controllers\ExitCode::UNSPECIFIED_ERROR 替代。 | yii\console\Controller |
EXIT_CODE_NORMAL | 0 | Deprecated 自 2.0.13。使用 \yii\console\controllers\ExitCode::OK 替代。 | yii\console\Controller |
EXIT_CODE_NO_DOCUMENT_ROOT | 2 | yii\console\controllers\ServeController | |
EXIT_CODE_NO_ROUTING_FILE | 3 | yii\console\controllers\ServeController |
属性详情
路径或 path alias 到服务的目录
提供服务的端口。
方法详情
运行 PHP 内置 web 服务器。
public integer actionIndex($address = 'localhost') | ||
$address | string | 服务器地址。"host" 或 "host:port"。 |
protected boolean isAddressTaken($address) | ||
$address | string | 服务器地址 |
return | boolean | 地址是否已被使用 |
---|
返回选项别名。 子类可以重写此方法以指定别名选项。
public array optionAliases() | ||
return | array | 选项别名对操作有效, 其中键是选项的别名,值是选项名。 |
---|
返回操作的有效选项的动作(id) 选项要求存在一个名为选项名的 公共成员变量。 子类可以重写此方法以指定可能的选项。
请注意,通过选项设置的值不可用 直到调用 beforeAction()。
public string[] options($actionID) | ||
$actionID | string | 当前请求的动作 id |
return | string[] | 对操作有效的选项名称 |
---|