yii2源码学习笔记(八),yii2源码学习笔记
Action是所有控制器的基类,接下来了解一下它的源码。yii2\base\Action.php
<span> 1</span> <?<span>php </span><span> 2</span> <span>/*</span><span>* </span><span> 3</span> <span> * @link </span><span>http://www.yiiframework.com/</span> <span> 4</span> <span> * @copyright Copyright (c) 2008 Yii Software LLC </span><span> 5</span> <span> * @license </span><span>http://www.yiiframework.com/license/</span> <span> 6</span> <span>*/</span> <span> 7</span> <span> 8</span> <span>namespace</span> yii\<span>base</span><span>; </span><span> 9</span> <span> 10</span> <span>use Yii; </span><span> 11</span> <span> 12</span> <span>/*</span><span>* </span><span> 13</span> <span> * Action is the base class for all controller action classes. </span><span> 14</span> <span> * 是所有控制器的基类 </span><span> 15</span> <span> * Action provides a way to divide a complex controller into </span><span> 16</span> <span> * smaller actions in separate class files. </span><span> 17</span> <span> * 控制器提供了一种重复使用操作方法的代码,在多个控制器或不同的项目中使用 </span><span> 18</span> <span> * Derived classes must implement a method named `run()`. This method </span><span> 19</span> <span> * will be invoked by the controller when the action is requested. </span><span> 20</span> <span> * The `run()` method can have parameters which will be filled up </span><span> 21</span> <span> * with user input values automatically according to their names. </span><span> 22</span> <span> * 派生类必须实现一个名为run()的方法,这个方法会在控制器被请求时调用。 </span><span> 23</span> <span> * 它可以有参数,将用户输入值的根据他们的名字自动填补。 </span><span> 24</span> <span> * For example, if the `run()` method is declared as follows: </span><span> 25</span> <span> * 例:run()方法调用声明如下: </span><span> 26</span> <span> * ~~~ </span><span> 27</span> <span> * public function run($id, $type = 'book') { ... } </span><span> 28</span> <span> * ~~~ </span><span> 29</span> <span> * </span><span> 30</span> <span> * And the parameters provided for the action are: `['id' => 1]`. </span><span> 31</span> <span> * Then the `run()` method will be invoked as `run(1)` automatically. </span><span> 32</span> <span> * 并且提供了操作的参数 ['id'=>1]; </span><span> 33</span> <span> * 当run(1)时自动调用run(); </span><span> 34</span> <span> * @property string $uniqueId The unique ID of this action among the whole application. This property is </span><span> 35</span> <span> * read-only. </span><span> 36</span> <span> * 整个应用程序中,这一行动的唯一标识。此属性是只读 </span><span> 37</span> <span> * @author Qiang Xue <qiang.xue@gmail.com> </span><span> 38</span> <span> * @since 2.0 </span><span> 39</span> <span>*/</span> <span> 40</span> <span>class</span><span> Action extends Component </span><span> 41</span> <span>{ </span><span> 42</span> <span>/*</span><span>* </span><span> 43</span> <span> * @var string ID of the action ID的动作 </span><span> 44</span> <span>*/</span> <span> 45</span> <span>public</span><span> $id; </span><span> 46</span> <span>/*</span><span>* </span><span> 47</span> <span> * @var Controller|\yii\web\Controller the controller that owns this action </span><span> 48</span> <span> * 拥有这一行动的控制器 </span><span> 49</span> <span>*/</span> <span> 50</span> <span>public</span><span> $controller; </span><span> 51</span> <span> 52</span> <span> 53</span> <span>/*</span><span>* </span><span> 54</span> <span> * Constructor. </span><span> 55</span> <span> * 构造函数 </span><span> 56</span> <span> * @param string $id the ID of this action 这一行动的ID </span><span> 57</span> <span> * @param Controller $controller the controller that owns this action 拥有这一行动的控制器 </span><span> 58</span> <span> * @param array $config name-value pairs that will be used to initialize the object properties </span><span> 59</span> <span> * 用来初始化对象属性的 name-value </span><span> 60</span> <span>*/</span> <span> 61</span> <span>public</span> function __construct($id, $controller, $config =<span> []) </span><span> 62</span> <span> { </span><span> 63</span> $<span>this</span>->id =<span> $id; </span><span> 64</span> $<span>this</span>->controller =<span> $controller; </span><span> 65</span> <span>//</span><span>调用父类的__construct()方法</span> <span> 66</span> <span> parent::__construct($config); </span><span> 67</span> <span> } </span><span> 68</span> <span> 69</span> <span>/*</span><span>* </span><span> 70</span> <span> * Returns the unique ID of this action among the whole application. </span><span> 71</span> <span> * 返回整个应用程序中的唯一ID。 </span><span> 72</span> <span> * @return string the unique ID of this action among the whole application. </span><span> 73</span> <span> * 在整个应用程序中,这一行动的唯一ID。 </span><span> 74</span> <span>*/</span> <span> 75</span> <span>public</span><span> function getUniqueId() </span><span> 76</span> <span> { </span><span> 77</span> <span>return</span> $<span>this</span>->controller->getUniqueId() . <span>'</span><span>/</span><span>'</span> . $<span>this</span>-><span>id; </span><span> 78</span> <span> } </span><span> 79</span> <span> 80</span> <span>/*</span><span>* </span><span> 81</span> <span> * Runs this action with the specified parameters. 用指定的参数运行此操作。 </span><span> 82</span> <span> * This method is mainly invoked by the controller. 该方法主要由控制器调用。 </span><span> 83</span> <span> * </span><span> 84</span> <span> * @param array $params the parameters to be bound to the action's run() method.绑定到行动的run()方法的参数。 </span><span> 85</span> <span> * @return mixed the result of the action 行动的结果 命名参数是否有效的 </span><span> 86</span> <span> * @throws InvalidConfigException if the action class does not have a run() method </span><span> 87</span> <span> * 如果动作类没有run()方法 扔出异常 </span><span> 88</span> <span>*/</span> <span> 89</span> <span>public</span> function runWithParams($<span>params</span><span>) </span><span> 90</span> <span> { </span><span> 91</span> <span>if</span> (!method_exists($<span>this</span>, <span>'</span><span>run</span><span>'</span>)) {<span>//</span><span>如果动作类没有run()方法 抛出异常</span> <span> 92</span> <span>throw</span> <span>new</span> InvalidConfigException(get_class($<span>this</span>) . <span>'</span><span> must define a "run()" method.</span><span>'</span><span>); </span><span> 93</span> <span> } </span><span> 94</span> <span>//</span><span>调用bindActionParams()方法将参数绑定到动作。</span> <span> 95</span> $args = $<span>this</span>->controller->bindActionParams($<span>this</span>, $<span>params</span><span>); </span><span> 96</span> <span>//</span><span>记录跟踪消息</span> <span> 97</span> Yii::trace(<span>'</span><span>Running action: </span><span>'</span> . get_class($<span>this</span>) . <span>'</span><span>::run()</span><span>'</span><span>, __METHOD__); </span><span> 98</span> <span>if</span> (Yii::$app->requestedParams === <span>null</span><span>) { </span><span> 99</span> <span>//</span><span>请求的动作提供的参数</span> <span>100</span> Yii::$app->requestedParams =<span> $args; </span><span>101</span> <span> } </span><span>102</span> <span>if</span> ($<span>this</span>-><span>beforeRun()) { </span><span>103</span> <span>//</span><span>执行run()方法</span> <span>104</span> $result = call_user_func_array([$<span>this</span>, <span>'</span><span>run</span><span>'</span><span>], $args); </span><span>105</span> $<span>this</span>-><span>afterRun(); </span><span>106</span> <span>107</span> <span>return</span><span> $result; </span><span>108</span> } <span>else</span><span> { </span><span>109</span> <span>return</span> <span>null</span><span>; </span><span>110</span> <span> } </span><span>111</span> <span> } </span><span>112</span> <span>113</span> <span>/*</span><span>* </span><span>114</span> <span> * This method is called right before `run()` is executed. </span><span>115</span> <span> * ` run() `执行前方法被调用。 </span><span>116</span> <span> * You may override this method to do preparation work for the action run. </span><span>117</span> <span> * 可以重写此方法,为该操作运行的准备工作。 </span><span>118</span> <span> * If the method returns false, it will cancel the action. </span><span>119</span> <span> * 如果该方法返回false,取消该操作。 </span><span>120</span> <span> * @return boolean whether to run the action. </span><span>121</span> <span>*/</span> <span>122</span> <span>protected</span><span> function beforeRun() </span><span>123</span> <span> { </span><span>124</span> <span>return</span> <span>true</span><span>; </span><span>125</span> <span> } </span><span>126</span> <span>127</span> <span>/*</span><span>* </span><span>128</span> <span> * This method is called right after `run()` is executed. ` run() `执行后 方法被调用。 </span><span>129</span> <span> * You may override this method to do post-processing work for the action run. </span><span>130</span> <span> * 可以重写此方法来处理该动作的后续处理工作。 </span><span>131</span> <span>*/</span> <span>132</span> <span>protected</span><span> function afterRun() </span><span>133</span> <span> { </span><span>134</span> <span> } </span><span>135</span> }
接下来我们看一下事件参数相关重要的一个类ActionEvent。yii2\base\ActionEvent.php
<span> 1</span> <?<span>php </span><span> 2</span> <span>/*</span><span>* </span><span> 3</span> <span> * @link </span><span>http://www.yiiframework.com/</span> <span> 4</span> <span> * @copyright Copyright (c) 2008 Yii Software LLC </span><span> 5</span> <span> * @license </span><span>http://www.yiiframework.com/license/</span> <span> 6</span> <span>*/</span> <span> 7</span> <span> 8</span> <span>namespace</span> yii\<span>base</span><span>; </span><span> 9</span> <span>10</span> <span>/*</span><span>* </span><span>11</span> <span> * ActionEvent represents the event parameter used for an action event. </span><span>12</span> <span> * 用于操作事件的事件参数 </span><span>13</span> <span> * By setting the [[isValid]] property, one may control whether to continue running the action. </span><span>14</span> <span> * 通过设置[[isValid]]属性,控制是否继续运行action。 </span><span>15</span> <span> * @author Qiang Xue <qiang.xue@gmail.com> </span><span>16</span> <span> * @since 2.0 </span><span>17</span> <span>*/</span> <span>18</span> <span>class</span><span> ActionEvent extends Event </span><span>19</span> <span>{ </span><span>20</span> <span>/*</span><span>* </span><span>21</span> <span> * @var Action the action currently being executed </span><span>22</span> <span> * 目前正在执行的行动 </span><span>23</span> <span>*/</span> <span>24</span> <span>public</span><span> $action; </span><span>25</span> <span>/*</span><span>* </span><span>26</span> <span> * @var mixed the action result. Event handlers may modify this property to change the action result. </span><span>27</span> <span> * 操作结果 事件处理程序可以修改此属性来更改操作结果。 </span><span>28</span> <span>*/</span> <span>29</span> <span>public</span><span> $result; </span><span>30</span> <span>/*</span><span>* </span><span>31</span> <span> * @var boolean whether to continue running the action. Event handlers of </span><span>32</span> <span> * [[Controller::EVENT_BEFORE_ACTION]] may set this property to decide whether </span><span>33</span> <span> * to continue running the current action. </span><span>34</span> <span> * 是否继续运行该动作。设置[[Controller::EVENT_BEFORE_ACTION]]属性决定是否执行当前的操作 </span><span>35</span> <span>*/</span> <span>36</span> <span>public</span> $isValid = <span>true</span><span>; </span><span>37</span> <span>38</span> <span>39</span> <span>/*</span><span>* </span><span>40</span> <span> * Constructor.构造函数。 </span><span>41</span> <span> * @param Action $action the action associated with this action event.与此事件相关联的动作。 </span><span>42</span> <span> * @param array $config name-value pairs that will be used to initialize the object properties </span><span>43</span> <span> * 用来初始化对象属性的 name-value </span><span>44</span> <span>*/</span> <span>45</span> <span>public</span> function __construct($action, $config =<span> []) </span><span>46</span> <span> { </span><span>47</span> $<span>this</span>->action =<span> $action; </span><span>48</span> <span> parent::__construct($config); </span><span>49</span> <span> } </span><span>50</span> }
今天最后看一下操作过滤器的基类吧ActionFilter。yii2\base\ActionFilter.php。
<span> 1</span> <?<span>php </span><span> 2</span> <span>/*</span><span>* </span><span> 3</span> <span> * @link </span><span>http://www.yiiframework.com/</span> <span> 4</span> <span> * @copyright Copyright (c) 2008 Yii Software LLC </span><span> 5</span> <span> * @license </span><span>http://www.yiiframework.com/license/</span> <span> 6</span> <span>*/</span> <span> 7</span> <span> 8</span> <span>namespace</span> yii\<span>base</span><span>; </span><span> 9</span> <span> 10</span> <span>/*</span><span>* </span><span> 11</span> <span> * ActionFilter is the base class for action filters. </span><span> 12</span> <span> * 是操作过滤器的基类。 </span><span> 13</span> <span> * An action filter will participate in the action execution workflow by responding to </span><span> 14</span> <span> * the `beforeAction` and `afterAction` events triggered by modules and controllers. </span><span> 15</span> <span> * 一个操作过滤器将参与行动的执行工作流程,通过触发模型和控制器的`beforeAction` 和`afterAction` 事件 </span><span> 16</span> <span> * Check implementation of [[\yii\filters\AccessControl]], [[\yii\filters\PageCache]] and [[\yii\filters\HttpCache]] as examples on how to use it. </span><span> 17</span> <span> * </span><span> 18</span> <span> * @author Qiang Xue <qiang.xue@gmail.com> </span><span> 19</span> <span> * @since 2.0 </span><span> 20</span> <span>*/</span> <span> 21</span> <span>class</span><span> ActionFilter extends Behavior </span><span> 22</span> <span>{ </span><span> 23</span> <span>/*</span><span>* </span><span> 24</span> <span> * @var array list of action IDs that this filter should apply to. If this property is not set, </span><span> 25</span> <span> * then the filter applies to all actions, unless they are listed in [[except]]. </span><span> 26</span> <span> * 操作标识列表。如果该属性未设置,过滤器适用于所有的行动,除非它们被列入[[except]]中。 </span><span> 27</span> <span> * If an action ID appears in both [[only]] and [[except]], this filter will NOT apply to it. </span><span> 28</span> <span> * 如果一个操作ID 出现在[[only]] 和[[except]]中,该筛选器将不适用它 </span><span> 29</span> <span> * Note that if the filter is attached to a module, the action IDs should also include child module IDs (if any) </span><span> 30</span> <span> * and controller IDs. </span><span> 31</span> <span> * 如果过滤器是链接到一个模块,操作检测还应包括子模块和控制器 </span><span> 32</span> <span> * </span><span> 33</span> <span> * @see except </span><span> 34</span> <span>*/</span> <span> 35</span> <span>public</span><span> $only; </span><span> 36</span> <span>/*</span><span>* </span><span> 37</span> <span> * @var array list of action IDs that this filter should not apply to. </span><span> 38</span> <span> * 此筛选器不应适用于操作ID。 </span><span> 39</span> <span> * @see only </span><span> 40</span> <span>*/</span> <span> 41</span> <span>public</span> $except =<span> []; </span><span> 42</span> <span> 43</span> <span> 44</span> <span>/*</span><span>* </span><span> 45</span> <span> * @inheritdoc </span><span> 46</span> <span> * 将行为对象附加到组件。 </span><span> 47</span> <span>*/</span> <span> 48</span> <span>public</span><span> function attach($owner) </span><span> 49</span> <span> { </span><span> 50</span> $<span>this</span>->owner =<span> $owner; </span><span> 51</span> $owner->on(Controller::EVENT_BEFORE_ACTION, [$<span>this</span>, <span>'</span><span>beforeFilter</span><span>'</span><span>]); </span><span> 52</span> <span> } </span><span> 53</span> <span> 54</span> <span>/*</span><span>* </span><span> 55</span> <span> * @inheritdoc </span><span> 56</span> <span> * 将行为对象和组件分离。 </span><span> 57</span> <span>*/</span> <span> 58</span> <span>public</span><span> function detach() </span><span> 59</span> <span> { </span><span> 60</span> <span>if</span> ($<span>this</span>-><span>owner) { </span><span> 61</span> $<span>this</span>->owner->off(Controller::EVENT_BEFORE_ACTION, [$<span>this</span>, <span>'</span><span>beforeFilter</span><span>'</span><span>]); </span><span> 62</span> $<span>this</span>->owner->off(Controller::EVENT_AFTER_ACTION, [$<span>this</span>, <span>'</span><span>afterFilter</span><span>'</span><span>]); </span><span> 63</span> $<span>this</span>->owner = <span>null</span><span>; </span><span> 64</span> <span> } </span><span> 65</span> <span> } </span><span> 66</span> <span> 67</span> <span>/*</span><span>* </span><span> 68</span> <span> * @param ActionEvent $event 在动作之前调用 </span><span> 69</span> <span>*/</span> <span> 70</span> <span>public</span> function beforeFilter($<span>event</span><span>) </span><span> 71</span> <span> { </span><span> 72</span> <span>if</span> (!$<span>this</span>->isActive($<span>event</span>-><span>action)) { </span><span> 73</span> <span>return</span><span>; </span><span> 74</span> <span> } </span><span> 75</span> <span> 76</span> $<span>event</span>->isValid = $<span>this</span>->beforeAction($<span>event</span>-><span>action); </span><span> 77</span> <span>if</span> ($<span>event</span>-><span>isValid) { </span><span> 78</span> <span>//</span><span> call afterFilter only if beforeFilter succeeds beforeFilter 执行成功调用afterFilter </span><span> 79</span> <span>//</span><span> beforeFilter and afterFilter should be properly nested 两者要配合应用</span> <span> 80</span> $<span>this</span>->owner->on(Controller::EVENT_AFTER_ACTION, [$<span>this</span>, <span>'</span><span>afterFilter</span><span>'</span>], <span>null</span>, <span>false</span><span>); </span><span> 81</span> } <span>else</span><span> { </span><span> 82</span> $<span>event</span>->handled = <span>true</span><span>; </span><span> 83</span> <span> } </span><span> 84</span> <span> } </span><span> 85</span> <span> 86</span> <span>/*</span><span>* </span><span> 87</span> <span> * @param ActionEvent $event </span><span> 88</span> <span>*/</span> <span> 89</span> <span>public</span> function afterFilter($<span>event</span><span>) </span><span> 90</span> <span> { </span><span> 91</span> $<span>event</span>->result = $<span>this</span>->afterAction($<span>event</span>->action, $<span>event</span>-><span>result); </span><span> 92</span> $<span>this</span>->owner->off(Controller::EVENT_AFTER_ACTION, [$<span>this</span>, <span>'</span><span>afterFilter</span><span>'</span><span>]); </span><span> 93</span> <span> } </span><span> 94</span> <span> 95</span> <span>/*</span><span>* </span><span> 96</span> <span> * This method is invoked right before an action is to be executed (after all possible filters.) </span><span> 97</span> <span> * 此方法是在一个动作之前被调用的( </span><span> 98</span> <span> * You may override this method to do last-minute preparation for the action. </span><span> 99</span> <span> * @param Action $action the action to be executed.要执行的动作 </span><span>100</span> <span> * @return boolean whether the action should continue to be executed. </span><span>101</span> <span> * 是否应继续执行该动作。 </span><span>102</span> <span>*/</span> <span>103</span> <span>public</span><span> function beforeAction($action) </span><span>104</span> <span> { </span><span>105</span> <span>return</span> <span>true</span><span>; </span><span>106</span> <span> } </span><span>107</span> <span>108</span> <span>/*</span><span>* </span><span>109</span> <span> * This method is invoked right after an action is executed. </span><span>110</span> <span> * 此方法是在执行动作之后调用的。 </span><span>111</span> <span> * You may override this method to do some postprocessing for the action. </span><span>112</span> <span> * @param Action $action the action just executed. 刚刚执行的动作 </span><span>113</span> <span> * @param mixed $result the action execution result 行动执行结果 </span><span>114</span> <span> * @return mixed the processed action result. 处理结果。 </span><span>115</span> <span>*/</span> <span>116</span> <span>public</span><span> function afterAction($action, $result) </span><span>117</span> <span> { </span><span>118</span> <span>return</span><span> $result; </span><span>119</span> <span> } </span><span>120</span> <span>121</span> <span>/*</span><span>* </span><span>122</span> <span> * Returns a value indicating whether the filer is active for the given action. </span><span>123</span> <span> * 返回一个值,给定的过滤器的行动是否为是积极的。 </span><span>124</span> <span> * @param Action $action the action being filtered 被过滤的动作 </span><span>125</span> <span> * @return boolean whether the filer is active for the given action. </span><span>126</span> <span> * 给定的过滤器的行动是否为是积极的。 </span><span>127</span> <span>*/</span> <span>128</span> <span>protected</span><span> function isActive($action) </span><span>129</span> <span> { </span><span>130</span> <span>if</span> ($<span>this</span>-><span>owner instanceof Module) { </span><span>131</span> <span>//</span><span> convert action uniqueId into an ID relative to the module</span> <span>132</span> $mid = $<span>this</span>->owner-><span>getUniqueId(); </span><span>133</span> $id = $action-><span>getUniqueId(); </span><span>134</span> <span>if</span> ($mid !== <span>''</span> && strpos($id, $mid) === <span>0</span><span>) { </span><span>135</span> $id = substr($id, strlen($mid) + <span>1</span><span>); </span><span>136</span> <span> } </span><span>137</span> } <span>else</span><span> { </span><span>138</span> $id = $action-><span>id; </span><span>139</span> <span> } </span><span>140</span> <span>return</span> !in_array($id, $<span>this</span>->except, <span>true</span>) && (empty($<span>this</span>->only) || in_array($id, $<span>this</span>->only, <span>true</span><span>)); </span><span>141</span> <span> } </span><span>142</span> }

随着云计算技术的不断发展,数据的备份已经成为了每个企业必须要做的事情。在这样的背景下,开发一款高可用的云备份系统尤为重要。而PHP框架Yii是一款功能强大的框架,可以帮助开发者快速构建高性能的Web应用程序。下面将介绍如何使用Yii框架开发一款高可用的云备份系统。设计数据库模型在Yii框架中,数据库模型是非常重要的一部分。因为数据备份系统需要用到很多的表和关

随着互联网的不断发展,Web应用程序开发的需求也越来越高。对于开发人员而言,开发应用程序需要一个稳定、高效、强大的框架,这样可以提高开发效率。Yii是一款领先的高性能PHP框架,它提供了丰富的特性和良好的性能。Yii3是Yii框架的下一代版本,它在Yii2的基础上进一步优化了性能和代码质量。在这篇文章中,我们将介绍如何使用Yii3框架来开发PHP应用程序。

在当前信息时代,大数据、人工智能、云计算等技术已经成为了各大企业关注的热点。在这些技术中,显卡渲染技术作为一种高性能图形处理技术,受到了越来越多的关注。显卡渲染技术被广泛应用于游戏开发、影视特效、工程建模等领域。而对于开发者来说,选择一个适合自己项目的框架,是一个非常重要的决策。在当前的语言中,PHP是一种颇具活力的语言,一些优秀的PHP框架如Yii2、Ph

Yii框架是一个开源的PHPWeb应用程序框架,提供了众多的工具和组件,简化了Web应用程序开发的流程,其中数据查询是其中一个重要的组件之一。在Yii框架中,我们可以使用类似SQL的语法来访问数据库,从而高效地查询和操作数据。Yii框架的查询构建器主要包括以下几种类型:ActiveRecord查询、QueryBuilder查询、命令查询和原始SQL查询

随着Web应用需求的不断增长,开发者们在选择开发框架方面也越来越有选择的余地。Symfony和Yii2是两个备受欢迎的PHP框架,它们都具有强大的功能和性能,但在面对需要开发大型Web应用时,哪个框架更适合呢?接下来我们将对Symphony和Yii2进行比较分析,以帮助你更好地进行选择。基本概述Symphony是一个由PHP编写的开源Web应用框架,它是建立

yii框架:本文为大家介绍了yii将对象转化为数组或直接输出为json格式的方法,具有一定的参考价值,希望能够帮助到大家。

在现代软件开发中,构建一个强大的内容管理系统(CMS)并不是一项容易的任务。不仅需要开发人员具备丰富的技能以及经验,还需要使用最先进的技术和工具来使其功能与性能达到最优化。本文介绍了如何使用Yii2和GrapeJS,两个流行的开源软件来实现后台CMS和前端可视化编辑。Yii2是一个流行的PHPWeb框架,它提供了丰富的工具和组件来快速构

如果您问“Yii是什么?”查看我之前的教程:Yii框架简介,其中回顾了Yii的优点,并概述了2014年10月发布的Yii2.0的新增功能。嗯>在这个使用Yii2编程系列中,我将指导读者使用Yii2PHP框架。在今天的教程中,我将与您分享如何利用Yii的控制台功能来运行cron作业。过去,我在cron作业中使用了wget—可通过Web访问的URL来运行我的后台任务。这引发了安全问题并存在一些性能问题。虽然我在我们的启动系列安全性专题中讨论了一些减轻风险的方法,但我曾希望过渡到控制台驱动的命令


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Notepad++7.3.1
Easy-to-use and free code editor

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
