0

0

yii2源码学习笔记(十七)

php中文网

php中文网

发布时间:2016-06-20 08:42:16

|

1124人浏览过

|

来源于php中文网

原创

theme 类,应用的主题,通过替换路径实现主题的应用,方法为获取根路径和根链接:yii2ase heme.php

<span style="color: #008080;">  1</span> <?<span style="color: #000000;">php
</span><span style="color: #008080;">  2</span> <span style="color: #008000;">/*</span><span style="color: #008000;">*
</span><span style="color: #008080;">  3</span> <span style="color: #008000;"> * @link </span><span style="color: #008000; text-decoration: underline;">http://www.yiiframework.com/</span>
<span style="color: #008080;">  4</span> <span style="color: #008000;"> * @copyright Copyright (c) 2008 Yii Software LLC
</span><span style="color: #008080;">  5</span> <span style="color: #008000;"> * @license </span><span style="color: #008000; text-decoration: underline;">http://www.yiiframework.com/license/</span>
<span style="color: #008080;">  6</span>  <span style="color: #008000;">*/</span>
<span style="color: #008080;">  7</span> 
<span style="color: #008080;">  8</span> <span style="color: #0000ff;">namespace</span> yii<span style="color: #0000ff;">base</span><span style="color: #000000;">;
</span><span style="color: #008080;">  9</span> 
<span style="color: #008080;"> 10</span> <span style="color: #000000;">use Yii;
</span><span style="color: #008080;"> 11</span> <span style="color: #000000;">use yiihelpersFileHelper;
</span><span style="color: #008080;"> 12</span> 
<span style="color: #008080;"> 13</span> <span style="color: #008000;">/*</span><span style="color: #008000;">*
</span><span style="color: #008080;"> 14</span> <span style="color: #008000;"> * Theme represents an application theme.
</span><span style="color: #008080;"> 15</span> <span style="color: #008000;"> * Theme &#31867;&#65292;&#24212;&#29992;&#30340;&#20027;&#39064;
</span><span style="color: #008080;"> 16</span> <span style="color: #008000;"> * When [[View]] renders a view file, it will check the [[View::theme|active theme]]
</span><span style="color: #008080;"> 17</span> <span style="color: #008000;"> * to see if there is a themed version of the view file exists. If so, the themed version will be rendered instead.
</span><span style="color: #008080;"> 18</span> <span style="color: #008000;"> * &#35270;&#22270;&#23545;&#35937;[[View]]&#28210;&#26579;&#35270;&#22270;&#25991;&#20214;&#30340;&#26102;&#20505;&#65292;&#20250;&#26816;&#26597;&#35270;&#22270;&#30340;&#20027;&#39064;&#26159;&#21542;&#23384;&#22312;&#65292;&#22914;&#26524;&#23384;&#22312;&#21017;&#28210;&#26579;&#20027;&#39064;&#21462;&#20195;&#40664;&#35748;&#26679;&#24335;
</span><span style="color: #008080;"> 19</span> <span style="color: #008000;"> * A theme is a directory consisting of view files which are meant to replace their non-themed counterparts.
</span><span style="color: #008080;"> 20</span> <span style="color: #008000;"> *
</span><span style="color: #008080;"> 21</span> <span style="color: #008000;"> * Theme uses [[pathMap]] to achieve the view file replacement:
</span><span style="color: #008080;"> 22</span> <span style="color: #008000;"> *
</span><span style="color: #008080;"> 23</span> <span style="color: #008000;"> * 1. It first looks for a key in [[pathMap]] that is a substring of the given view file path;
</span><span style="color: #008080;"> 24</span> <span style="color: #008000;"> *  &#39318;&#20808;&#26597;&#25214;&#20851;&#38190;&#23383;&#65292;&#20851;&#38190;&#23383;&#26159;&#19968;&#20010;&#32473;&#23450;&#30340;&#35270;&#22270;&#36335;&#24452;&#30340;&#23383;&#31526;&#20018;
</span><span style="color: #008080;"> 25</span> <span style="color: #008000;"> * 2. If such a key exists, the corresponding value will be used to replace the corresponding part
</span><span style="color: #008080;"> 26</span> <span style="color: #008000;"> *    in the view file path;&#20851;&#38190;&#23383;&#23384;&#22312;&#65292;&#21017;&#29992;&#23545;&#24212;&#20540;&#26367;&#25442;&#32473;&#23450;&#30340;&#35270;&#22270;&#25991;&#20214;&#36335;&#24452;&#20013;&#23545;&#24212;&#30340;&#37096;&#20998;
</span><span style="color: #008080;"> 27</span> <span style="color: #008000;"> * 3. It will then check if the updated view file exists or not. If so, that file will be used
</span><span style="color: #008080;"> 28</span> <span style="color: #008000;"> *    to replace the original view file.&#26816;&#26597;&#26367;&#25442;&#21518;&#30340;&#36335;&#24452;&#23545;&#24212;&#30340;&#25991;&#20214;&#26159;&#21542;&#23384;&#22312;&#65292;&#23384;&#22312;&#23601;&#26367;&#25442;&#21407;&#25991;&#20214;
</span><span style="color: #008080;"> 29</span> <span style="color: #008000;"> * 4. If Step 2 or 3 fails, the original view file will be used.
</span><span style="color: #008080;"> 30</span> <span style="color: #008000;"> * 2&#21644;3&#22833;&#36133;&#30340;&#35805;&#65292;&#36820;&#22238;&#21407;&#26469;&#30340;&#36335;&#24452;
</span><span style="color: #008080;"> 31</span> <span style="color: #008000;"> * For example, if [[pathMap]] is `['@app/views' => '@app/themes/basic']`,
</span><span style="color: #008080;"> 32</span> <span style="color: #008000;"> * then the themed version for a view file `@app/views/site/index.php` will be
</span><span style="color: #008080;"> 33</span> <span style="color: #008000;"> * `@app/themes/basic/site/index.php`.
</span><span style="color: #008080;"> 34</span> <span style="color: #008000;"> *
</span><span style="color: #008080;"> 35</span> <span style="color: #008000;"> * It is possible to map a single path to multiple paths. For example,
</span><span style="color: #008080;"> 36</span> <span style="color: #008000;"> *
</span><span style="color: #008080;"> 37</span> <span style="color: #008000;"> * ~~~
</span><span style="color: #008080;"> 38</span> <span style="color: #008000;"> * 'pathMap' => [
</span><span style="color: #008080;"> 39</span> <span style="color: #008000;"> *     '@app/views' => [
</span><span style="color: #008080;"> 40</span> <span style="color: #008000;"> *         '@app/themes/christmas',
</span><span style="color: #008080;"> 41</span> <span style="color: #008000;"> *         '@app/themes/basic',
</span><span style="color: #008080;"> 42</span> <span style="color: #008000;"> *     ],
</span><span style="color: #008080;"> 43</span> <span style="color: #008000;"> * ]
</span><span style="color: #008080;"> 44</span> <span style="color: #008000;"> * ~~~
</span><span style="color: #008080;"> 45</span> <span style="color: #008000;"> *
</span><span style="color: #008080;"> 46</span> <span style="color: #008000;"> * In this case, the themed version could be either `@app/themes/christmas/site/index.php` or
</span><span style="color: #008080;"> 47</span> <span style="color: #008000;"> * `@app/themes/basic/site/index.php`. The former has precedence over the latter if both files exist.
</span><span style="color: #008080;"> 48</span> <span style="color: #008000;"> *
</span><span style="color: #008080;"> 49</span> <span style="color: #008000;"> * To use a theme, you should configure the [[View::theme|theme]] property of the "view" application
</span><span style="color: #008080;"> 50</span> <span style="color: #008000;"> * component like the following:
</span><span style="color: #008080;"> 51</span> <span style="color: #008000;"> *
</span><span style="color: #008080;"> 52</span> <span style="color: #008000;"> * ~~~
</span><span style="color: #008080;"> 53</span> <span style="color: #008000;"> * 'view' => [
</span><span style="color: #008080;"> 54</span> <span style="color: #008000;"> *     'theme' => [
</span><span style="color: #008080;"> 55</span> <span style="color: #008000;"> *         'basePath' => '@app/themes/basic',
</span><span style="color: #008080;"> 56</span> <span style="color: #008000;"> *         'baseUrl' => '@web/themes/basic',
</span><span style="color: #008080;"> 57</span> <span style="color: #008000;"> *     ],
</span><span style="color: #008080;"> 58</span> <span style="color: #008000;"> * ],
</span><span style="color: #008080;"> 59</span> <span style="color: #008000;"> * ~~~
</span><span style="color: #008080;"> 60</span> <span style="color: #008000;"> *
</span><span style="color: #008080;"> 61</span> <span style="color: #008000;"> * The above configuration specifies a theme located under the "themes/basic" directory of the Web folder
</span><span style="color: #008080;"> 62</span> <span style="color: #008000;"> * that contains the entry script of the application. If your theme is designed to handle modules,
</span><span style="color: #008080;"> 63</span> <span style="color: #008000;"> * you may configure the [[pathMap]] property like described above.
</span><span style="color: #008080;"> 64</span> <span style="color: #008000;"> *
</span><span style="color: #008080;"> 65</span> <span style="color: #008000;"> * @property string $basePath The root path of this theme. All resources of this theme are located under this
</span><span style="color: #008080;"> 66</span> <span style="color: #008000;"> * directory.
</span><span style="color: #008080;"> 67</span> <span style="color: #008000;"> * @property string $baseUrl The base URL (without ending slash) for this theme. All resources of this theme
</span><span style="color: #008080;"> 68</span> <span style="color: #008000;"> * are considered to be under this base URL. This property is read-only.
</span><span style="color: #008080;"> 69</span> <span style="color: #008000;"> *
</span><span style="color: #008080;"> 70</span> <span style="color: #008000;"> * @author Qiang Xue <qiang.xue@gmail.com>
</span><span style="color: #008080;"> 71</span> <span style="color: #008000;"> * @since 2.0
</span><span style="color: #008080;"> 72</span>  <span style="color: #008000;">*/</span>
<span style="color: #008080;"> 73</span> <span style="color: #0000ff;">class</span><span style="color: #000000;"> Theme extends Component
</span><span style="color: #008080;"> 74</span> <span style="color: #000000;">{
</span><span style="color: #008080;"> 75</span>     <span style="color: #008000;">/*</span><span style="color: #008000;">*
</span><span style="color: #008080;"> 76</span> <span style="color: #008000;">     * @var array the mapping between view directories and their corresponding themed versions.
</span><span style="color: #008080;"> 77</span> <span style="color: #008000;">     * This property is used by [[applyTo()]] when a view is trying to apply the theme.
</span><span style="color: #008080;"> 78</span> <span style="color: #008000;">     * Path aliases can be used when specifying directories.
</span><span style="color: #008080;"> 79</span> <span style="color: #008000;">     * &#36335;&#24452;&#26144;&#23556;&#23646;&#24615; &#35774;&#32622;&#26367;&#25442;&#26144;&#23556;&#20851;&#31995;
</span><span style="color: #008080;"> 80</span> <span style="color: #008000;">     * If this property is empty or not set, a mapping [[Application::basePath]] to [[basePath]] will be used.
</span><span style="color: #008080;"> 81</span>      <span style="color: #008000;">*/</span>
<span style="color: #008080;"> 82</span>     <span style="color: #0000ff;">public</span><span style="color: #000000;"> $pathMap;
</span><span style="color: #008080;"> 83</span> 
<span style="color: #008080;"> 84</span>     <span style="color: #0000ff;">private</span> $_baseUrl;<span style="color: #008000;">//</span><span style="color: #008000;">&#35774;&#32622;&#35201;&#35775;&#38382;&#36164;&#28304;&#30340;url</span>
<span style="color: #008080;"> 85</span> 
<span style="color: #008080;"> 86</span>     <span style="color: #008000;">/*</span><span style="color: #008000;">*
</span><span style="color: #008080;"> 87</span> <span style="color: #008000;">     * @return string the base URL (without ending slash) for this theme. All resources of this theme are considered
</span><span style="color: #008080;"> 88</span> <span style="color: #008000;">     * to be under this base URL. &#36820;&#22238;&#24403;&#21069;&#20027;&#39064;&#30340;&#22522;&#30784;&#38142;&#25509;&#65292;&#20854;&#20182;&#36164;&#28304;&#37117;&#22312;&#38142;&#25509;&#37324;
</span><span style="color: #008080;"> 89</span>      <span style="color: #008000;">*/</span>
<span style="color: #008080;"> 90</span>     <span style="color: #0000ff;">public</span><span style="color: #000000;"> function getBaseUrl()
</span><span style="color: #008080;"> 91</span> <span style="color: #000000;">    {
</span><span style="color: #008080;"> 92</span>         <span style="color: #0000ff;">return</span> $<span style="color: #0000ff;">this</span>-><span style="color: #000000;">_baseUrl;
</span><span style="color: #008080;"> 93</span> <span style="color: #000000;">    }
</span><span style="color: #008080;"> 94</span> 
<span style="color: #008080;"> 95</span>     <span style="color: #008000;">/*</span><span style="color: #008000;">*
</span><span style="color: #008080;"> 96</span> <span style="color: #008000;">     * @param $url string the base URL or path alias for this theme. All resources of this theme are considered
</span><span style="color: #008080;"> 97</span> <span style="color: #008000;">     * to be under this base URL. &#35774;&#32622;&#22522;&#30784;&#38142;&#25509;
</span><span style="color: #008080;"> 98</span>      <span style="color: #008000;">*/</span>
<span style="color: #008080;"> 99</span>     <span style="color: #0000ff;">public</span><span style="color: #000000;"> function setBaseUrl($url)
</span><span style="color: #008080;">100</span> <span style="color: #000000;">    {
</span><span style="color: #008080;">101</span>         $<span style="color: #0000ff;">this</span>->_baseUrl = rtrim(Yii::getAlias($url), <span style="color: #800000;">'</span><span style="color: #800000;">/</span><span style="color: #800000;">'</span><span style="color: #000000;">);
</span><span style="color: #008080;">102</span> <span style="color: #000000;">    }
</span><span style="color: #008080;">103</span> 
<span style="color: #008080;">104</span>     <span style="color: #0000ff;">private</span> $_basePath;<span style="color: #008000;">//</span><span style="color: #008000;">&#26681;&#36335;&#24452;</span>
<span style="color: #008080;">105</span> 
<span style="color: #008080;">106</span>     <span style="color: #008000;">/*</span><span style="color: #008000;">*
</span><span style="color: #008080;">107</span> <span style="color: #008000;">     * @return string the root path of this theme. All resources of this theme are located under this directory.
</span><span style="color: #008080;">108</span> <span style="color: #008000;">     * &#24471;&#21040;&#24403;&#21069;&#20027;&#39064;&#30340;&#26681;&#36335;&#24452;
</span><span style="color: #008080;">109</span> <span style="color: #008000;">     * @see pathMap
</span><span style="color: #008080;">110</span>      <span style="color: #008000;">*/</span>
<span style="color: #008080;">111</span>     <span style="color: #0000ff;">public</span><span style="color: #000000;"> function getBasePath()
</span><span style="color: #008080;">112</span> <span style="color: #000000;">    {
</span><span style="color: #008080;">113</span>         <span style="color: #0000ff;">return</span> $<span style="color: #0000ff;">this</span>-><span style="color: #000000;">_basePath;
</span><span style="color: #008080;">114</span> <span style="color: #000000;">    }
</span><span style="color: #008080;">115</span> 
<span style="color: #008080;">116</span>     <span style="color: #008000;">/*</span><span style="color: #008000;">*
</span><span style="color: #008080;">117</span> <span style="color: #008000;">     * @param string $path the root path or path alias of this theme. All resources of this theme are located
</span><span style="color: #008080;">118</span> <span style="color: #008000;">     * under this directory. &#35774;&#32622;&#24403;&#21069;&#20027;&#39064;&#26681;&#36335;&#24452;
</span><span style="color: #008080;">119</span> <span style="color: #008000;">     * @see pathMap
</span><span style="color: #008080;">120</span>      <span style="color: #008000;">*/</span>
<span style="color: #008080;">121</span>     <span style="color: #0000ff;">public</span><span style="color: #000000;"> function setBasePath($path)
</span><span style="color: #008080;">122</span> <span style="color: #000000;">    {
</span><span style="color: #008080;">123</span>         $<span style="color: #0000ff;">this</span>->_basePath =<span style="color: #000000;"> Yii::getAlias($path);
</span><span style="color: #008080;">124124</span> <span style="color: #000000;">    }
</span><span style="color: #008080;">125</span> 
<span style="color: #008080;">126</span>     <span style="color: #008000;">/*</span><span style="color: #008000;">*
</span><span style="color: #008080;">127</span> <span style="color: #008000;">     * Converts a file to a themed file if possible. &#23558;&#19968;&#20010;&#25991;&#20214;&#26367;&#25442;&#20027;&#39064;&#25991;&#20214;
</span><span style="color: #008080;">128</span> <span style="color: #008000;">     * If there is no corresponding themed file, the original file will be returned.
</span><span style="color: #008080;">129</span> <span style="color: #008000;">     * &#27809;&#26377;&#30456;&#24212;&#30340;&#20027;&#39064;&#25991;&#20214;&#65292;&#36820;&#22238;&#21407;&#25991;&#20214;&#12290;
</span><span style="color: #008080;">130</span> <span style="color: #008000;">     * @param string $path the file to be themed
</span><span style="color: #008080;">131</span> <span style="color: #008000;">     * @return string the themed file, or the original file if the themed version is not available.
</span><span style="color: #008080;">132</span> <span style="color: #008000;">     * @throws InvalidConfigException if [[basePath]] is not set
</span><span style="color: #008080;">133</span>      <span style="color: #008000;">*/</span>
<span style="color: #008080;">134</span>     <span style="color: #0000ff;">public</span><span style="color: #000000;"> function applyTo($path)
</span><span style="color: #008080;">135</span> <span style="color: #000000;">    {
</span><span style="color: #008080;">136</span>         $pathMap = $<span style="color: #0000ff;">this</span>->pathMap; <span style="color: #008000;">//</span><span style="color: #008000;">&#21462;&#24471;&#36335;&#24452;&#26144;&#23556;</span>
<span style="color: #008080;">137</span>         <span style="color: #0000ff;">if</span> (empty($pathMap)) {<span style="color: #008000;">//</span><span style="color: #008000;">&#27809;&#26377;&#35774;&#32622;&#20540; &#25243;&#20986;&#24322;&#24120;</span>
<span style="color: #008080;">138</span>             <span style="color: #0000ff;">if</span> (($basePath = $<span style="color: #0000ff;">this</span>->getBasePath()) === <span style="color: #0000ff;">null</span><span style="color: #000000;">) {
</span><span style="color: #008080;">139</span>                 <span style="color: #0000ff;">throw</span> <span style="color: #0000ff;">new</span> InvalidConfigException(<span style="color: #800000;">'</span><span style="color: #800000;">The "basePath" property must be set.</span><span style="color: #800000;">'</span><span style="color: #000000;">);
</span><span style="color: #008080;">140</span> <span style="color: #000000;">            }
</span><span style="color: #008080;">141</span>             <span style="color: #008000;">//</span><span style="color: #008000;">&#35774;&#32622;&#20540;&#20026;[&#27169;&#22359;&#26681;&#36335;&#24452;=>&#20027;&#39064;&#26681;&#36335;&#24452;]&#30340;&#24418;&#24335;</span>
<span style="color: #008080;">142</span>             $pathMap = [Yii::$app->getBasePath() =><span style="color: #000000;"> [$basePath]];
</span><span style="color: #008080;">143</span> <span style="color: #000000;">        }
</span><span style="color: #008080;">144</span> 
<span style="color: #008080;">145</span>         $path = FileHelper::normalizePath($path);<span style="color: #008000;">//</span><span style="color: #008000;">&#23545;&#36335;&#24452;&#20013;&#30340;"/".""&#36827;&#34892;&#32479;&#19968;</span>
<span style="color: #008080;">146</span> 
<span style="color: #008080;">147</span>         <span style="color: #0000ff;">foreach</span> ($pathMap <span style="color: #0000ff;">as</span> $<span style="color: #0000ff;">from</span> =><span style="color: #000000;"> $tos) {
</span><span style="color: #008080;">148</span>             <span style="color: #008000;">//</span><span style="color: #008000;">&#26144;&#23556;&#25968;&#32452;&#20013;&#30340;&#26469;&#28304;</span>
<span style="color: #008080;">149</span>             $<span style="color: #0000ff;">from</span> = FileHelper::normalizePath(Yii::getAlias($<span style="color: #0000ff;">from</span><span style="color: #000000;">)) . DIRECTORY_SEPARATOR;
</span><span style="color: #008080;">150</span>             <span style="color: #0000ff;">if</span> (strpos($path, $<span style="color: #0000ff;">from</span>) === <span style="color: #800080;">0</span>) {<span style="color: #008000;">//</span><span style="color: #008000;">&#22914;&#26524;&#22312;$path&#20013;&#26377;&#21487;&#26367;&#25442;&#30340;&#26087;&#20540;</span>
<span style="color: #008080;">151</span>                 $n = strlen($<span style="color: #0000ff;">from</span><span style="color: #000000;">);
</span><span style="color: #008080;">152</span>                 <span style="color: #0000ff;">foreach</span> ((array) $tos <span style="color: #0000ff;">as</span><span style="color: #000000;"> $to) {
</span><span style="color: #008080;">153</span>                     $to =<span style="color: #000000;"> FileHelper::normalizePath(Yii::getAlias($to)) . DIRECTORY_SEPARATOR;
</span><span style="color: #008080;">154</span>                     $file = $to . substr($path, $n);<span style="color: #008000;">//</span><span style="color: #008000;">&#25226;$path&#20013;&#30340;$from&#26367;&#25442;&#20026;$to</span>
<span style="color: #008080;">155</span>                     <span style="color: #0000ff;">if</span><span style="color: #000000;"> (is_file($file)) {
</span><span style="color: #008080;">156</span>                         <span style="color: #0000ff;">return</span> $file; <span style="color: #008000;">//</span><span style="color: #008000;">&#26159;&#25991;&#20214;&#30452;&#25509;&#36820;&#22238;</span>
<span style="color: #008080;">157</span> <span style="color: #000000;">                    }
</span><span style="color: #008080;">158</span> <span style="color: #000000;">                }
</span><span style="color: #008080;">159</span> <span style="color: #000000;">            }
</span><span style="color: #008080;">160</span> <span style="color: #000000;">        }
</span><span style="color: #008080;">161</span> 
<span style="color: #008080;">162</span>         <span style="color: #0000ff;">return</span><span style="color: #000000;"> $path;
</span><span style="color: #008080;">163</span> <span style="color: #000000;">    }
</span><span style="color: #008080;">164</span> 
<span style="color: #008080;">165</span>     <span style="color: #008000;">/*</span><span style="color: #008000;">*
</span><span style="color: #008080;">166</span> <span style="color: #008000;">     * Converts a relative URL into an absolute URL using [[baseUrl]].
</span><span style="color: #008080;">167</span> <span style="color: #008000;">     * &#23558;&#19968;&#20010;&#30456;&#23545;URL&#36716;&#25442;&#20026;&#32477;&#23545;URL
</span><span style="color: #008080;">168</span> <span style="color: #008000;">     * @param string $url the relative URL to be converted.&#35201;&#36716;&#25442;&#30340;&#30456;&#23545;URL
</span><span style="color: #008080;">169</span> <span style="color: #008000;">     * @return string the absolute URL  &#26367;&#25442;&#21518;&#30340;&#32477;&#23545;URL
</span><span style="color: #008080;">170</span> <span style="color: #008000;">     * @throws InvalidConfigException if [[baseUrl]] is not set
</span><span style="color: #008080;">171</span>      <span style="color: #008000;">*/</span>
<span style="color: #008080;">172</span>     <span style="color: #0000ff;">public</span><span style="color: #000000;"> function getUrl($url)
</span><span style="color: #008080;">173</span> <span style="color: #000000;">    {
</span><span style="color: #008080;">174</span>         <span style="color: #0000ff;">if</span> (($baseUrl = $<span style="color: #0000ff;">this</span>->getBaseUrl()) !== <span style="color: #0000ff;">null</span>) {<span style="color: #008000;">//</span><span style="color: #008000;">URL&#23384;&#22312;&#65292;&#36827;&#34892;&#36716;&#25442;</span>
<span style="color: #008080;">175</span>             <span style="color: #0000ff;">return</span> $baseUrl . <span style="color: #800000;">'</span><span style="color: #800000;">/</span><span style="color: #800000;">'</span> . ltrim($url, <span style="color: #800000;">'</span><span style="color: #800000;">/</span><span style="color: #800000;">'</span><span style="color: #000000;">);
</span><span style="color: #008080;">176</span>         } <span style="color: #0000ff;">else</span> {<span style="color: #008000;">//</span><span style="color: #008000;">&#19981;&#23384;&#22312;&#25243;&#20986;&#24322;&#24120;</span>
<span style="color: #008080;">177</span>             <span style="color: #0000ff;">throw</span> <span style="color: #0000ff;">new</span> InvalidConfigException(<span style="color: #800000;">'</span><span style="color: #800000;">The "baseUrl" property must be set.</span><span style="color: #800000;">'</span><span style="color: #000000;">);
</span><span style="color: #008080;">178</span> <span style="color: #000000;">        }
</span><span style="color: #008080;">179</span> <span style="color: #000000;">    }
</span><span style="color: #008080;">180</span> 
<span style="color: #008080;">181</span>     <span style="color: #008000;">/*</span><span style="color: #008000;">*
</span><span style="color: #008080;">182</span> <span style="color: #008000;">     * Converts a relative file path into an absolute one using [[basePath]].
</span><span style="color: #008080;">183</span> <span style="color: #008000;">     * &#36890;&#36807;&#30456;&#23545;&#36335;&#24452;&#29983;&#25104;&#32477;&#23545;&#36335;&#24452;
</span><span style="color: #008080;">184</span> <span style="color: #008000;">     * @param string $path the relative file path to be converted. &#35201;&#36716;&#25442;&#30340;&#30456;&#23545;&#25991;&#20214;&#36335;&#24452;&#12290;
</span><span style="color: #008080;">185</span> <span style="color: #008000;">     * @return string the absolute file path &#36716;&#25442;&#21518;&#30340;&#32477;&#23545;&#36335;&#24452;
</span><span style="color: #008080;">186</span> <span style="color: #008000;">     * @throws InvalidConfigException if [[baseUrl]] is not set
</span><span style="color: #008080;">187</span>      <span style="color: #008000;">*/</span>
<span style="color: #008080;">188</span>     <span style="color: #0000ff;">public</span><span style="color: #000000;"> function getPath($path)
</span><span style="color: #008080;">189</span> <span style="color: #000000;">    {
</span><span style="color: #008080;">190</span>         <span style="color: #0000ff;">if</span> (($basePath = $<span style="color: #0000ff;">this</span>->getBasePath()) !== <span style="color: #0000ff;">null</span><span style="color: #000000;">) {
</span><span style="color: #008080;">191</span>             <span style="color: #008000;">//</span><span style="color: #008000;">&#36820;&#22238;&#25340;&#25509;&#30340;&#36335;&#24452;</span>
<span style="color: #008080;">192</span>             <span style="color: #0000ff;">return</span> $basePath . DIRECTORY_SEPARATOR . ltrim($path, <span style="color: #800000;">'</span><span style="color: #800000;">/\</span><span style="color: #800000;">'</span><span style="color: #000000;">);
</span><span style="color: #008080;">193</span>         } <span style="color: #0000ff;">else</span><span style="color: #000000;"> {
</span><span style="color: #008080;">194</span>             <span style="color: #0000ff;">throw</span> <span style="color: #0000ff;">new</span> InvalidConfigException(<span style="color: #800000;">'</span><span style="color: #800000;">The "basePath" property must be set.</span><span style="color: #800000;">'</span><span style="color: #000000;">);
</span><span style="color: #008080;">195</span> <span style="color: #000000;">        }
</span><span style="color: #008080;">196</span> <span style="color: #000000;">    }
</span><span style="color: #008080;">197</span> }

 

一键职达
一键职达

AI全自动批量代投简历软件,自动浏览招聘网站从海量职位中用AI匹配职位并完成投递的全自动操作,真正实现'一键职达'的便捷体验。

下载

本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热门AI工具

更多
DeepSeek
DeepSeek

幻方量化公司旗下的开源大模型平台

豆包大模型
豆包大模型

字节跳动自主研发的一系列大型语言模型

通义千问
通义千问

阿里巴巴推出的全能AI助手

腾讯元宝
腾讯元宝

腾讯混元平台推出的AI助手

文心一言
文心一言

文心一言是百度开发的AI聊天机器人,通过对话可以生成各种形式的内容。

讯飞写作
讯飞写作

基于讯飞星火大模型的AI写作工具,可以快速生成新闻稿件、品宣文案、工作总结、心得体会等各种文文稿

即梦AI
即梦AI

一站式AI创作平台,免费AI图片和视频生成。

ChatGPT
ChatGPT

最最强大的AI聊天机器人程序,ChatGPT不单是聊天机器人,还能进行撰写邮件、视频脚本、文案、翻译、代码等任务。

相关专题

更多
雨课堂网页版登录入口与使用指南_官方在线教学平台访问方法
雨课堂网页版登录入口与使用指南_官方在线教学平台访问方法

本专题系统整理雨课堂网页版官方入口及在线登录方式,涵盖账号登录流程、官方直连入口及平台访问方法说明,帮助师生用户快速进入雨课堂在线教学平台,实现便捷、高效的课程学习与教学管理体验。

1

2026.02.12

豆包AI网页版入口与智能创作指南_官方在线写作与图片生成使用方法
豆包AI网页版入口与智能创作指南_官方在线写作与图片生成使用方法

本专题汇总豆包AI官方网页版入口及在线使用方式,涵盖智能写作工具、图片生成体验入口和官网登录方法,帮助用户快速直达豆包AI平台,高效完成文本创作与AI生图任务,实现便捷智能创作体验。

10

2026.02.12

PostgreSQL性能优化与索引调优实战
PostgreSQL性能优化与索引调优实战

本专题面向后端开发与数据库工程师,深入讲解 PostgreSQL 查询优化原理与索引机制。内容包括执行计划分析、常见索引类型对比、慢查询优化策略、事务隔离级别以及高并发场景下的性能调优技巧。通过实战案例解析,帮助开发者提升数据库响应速度与系统稳定性。

2

2026.02.12

Next.js全栈开发与SSR服务端渲染实战
Next.js全栈开发与SSR服务端渲染实战

本专题系统讲解 Next.js 框架在现代全栈开发中的应用,重点解析 SSR、SSG 与 ISR 渲染模式的原理与差异。内容涵盖路由系统、API Routes、数据获取策略、性能优化以及部署实践。通过完整项目示例,帮助开发者掌握高性能 SEO 友好的 React 全栈开发方案。

1

2026.02.12

Kotlin协程编程与Spring Boot集成实践
Kotlin协程编程与Spring Boot集成实践

本专题围绕 Kotlin 协程机制展开,深入讲解挂起函数、协程作用域、结构化并发与异常处理机制,并结合 Spring Boot 展示协程在后端开发中的实际应用。内容涵盖异步接口设计、数据库调用优化、线程资源管理以及性能调优策略,帮助开发者构建更加简洁高效的 Kotlin 后端服务架构。

7

2026.02.12

2026春节习俗大全
2026春节习俗大全

本专题整合了2026春节习俗大全,阅读专题下面的文章了解更多详细内容。

195

2026.02.11

Yandex网页版官方入口使用指南_国际版与俄罗斯版访问方法解析
Yandex网页版官方入口使用指南_国际版与俄罗斯版访问方法解析

本专题全面整理了Yandex搜索引擎的官方入口信息,涵盖国际版与俄罗斯版官网访问方式、网页版直达入口及免登录使用说明,帮助用户快速、安全地进入Yandex官网,高效使用其搜索与相关服务。

640

2026.02.11

虫虫漫画网页版入口与免费阅读指南_正版漫画全集在线查看方法
虫虫漫画网页版入口与免费阅读指南_正版漫画全集在线查看方法

本专题系统整理了虫虫漫画官网及网页版最新入口,涵盖免登录观看、正版漫画全集在线阅读方式,并汇总稳定可用的访问渠道,帮助用户快速找到虫虫漫画官方页面,轻松在线阅读各类热门漫画内容。

94

2026.02.11

Docker容器化部署与DevOps实践
Docker容器化部署与DevOps实践

本专题面向后端与运维开发者,系统讲解 Docker 容器化技术在实际项目中的应用。内容涵盖 Docker 镜像构建、容器运行机制、Docker Compose 多服务编排,以及在 DevOps 流程中的持续集成与持续部署实践。通过真实场景演示,帮助开发者实现应用的快速部署、环境一致性与运维自动化。

7

2026.02.11

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号