yii2源码学习笔记(十七)

小磊吖_4194

小磊吖_4194

2016-06-20

1144人浏览

原创

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 类,应用的主题
</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;"> * 视图对象[[View]]渲染视图文件的时候,会检查视图的主题是否存在,如果存在则渲染主题取代默认样式
</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;"> *  首先查找关键字,关键字是一个给定的视图路径的字符串
</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;关键字存在,则用对应值替换给定的视图文件路径中对应的部分
</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.检查替换后的路径对应的文件是否存在,存在就替换原文件
</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和3失败的话,返回原来的路径
</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></qiang.xue></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;">     * 路径映射属性 设置替换映射关系
</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;">设置要访问资源的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. 返回当前主题的基础链接,其他资源都在链接里
</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. 设置基础链接
</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;">根路径</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;">     * 得到当前主题的根路径
</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. 设置当前主题根路径
</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. 将一个文件替换主题文件
</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;">     * 没有相应的主题文件,返回原文件。
</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;">取得路径映射</span>
<span style="color: #008080;">137</span>         <span style="color: #0000ff;">if</span> (empty($pathMap)) {<span style="color: #008000;">//</span><span style="color: #008000;">没有设置值 抛出异常</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;">设置值为[模块根路径=>主题根路径]的形式</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;">对路径中的"/".""进行统一</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;">映射数组中的来源</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;">如果在$path中有可替换的旧值</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;">把$path中的$from替换为$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;">是文件直接返回</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;">     * 将一个相对URL转换为绝对URL
</span><span style="color: #008080;">168</span> <span style="color: #008000;">     * @param string $url the relative URL to be converted.要转换的相对URL
</span><span style="color: #008080;">169</span> <span style="color: #008000;">     * @return string the absolute URL  替换后的绝对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存在,进行转换</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;">不存在抛出异常</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;">     * 通过相对路径生成绝对路径
</span><span style="color: #008080;">184</span> <span style="color: #008000;">     * @param string $path the relative file path to be converted. 要转换的相对文件路径。
</span><span style="color: #008080;">185</span> <span style="color: #008000;">     * @return string the absolute file path 转换后的绝对路径
</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;">返回拼接的路径</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> }

 

PHP速学视频免费教程(入门到精通)
PHP速学视频免费教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载

相关标签:

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

相关专题

更多
Go-Zero API开发使用教程
Go-Zero API开发使用教程

本专题聚焦Go-Zero的API开发,拆解.api描述文件的语法结构、路由与分组定义、参数绑定与校验规则,说明统一响应体、JWT鉴权、跨域与接口文档生成的落地方式,并给出网关聚合与接口测试的实践建议。

2026.11.12

120

15

Go-Zero安装与goctl环境配置教程
Go-Zero安装与goctl环境配置教程

本专题围绕Go-Zero的安装与工具链配置展开,讲清Go版本要求、goctl安装方式、代理镜像、protoc依赖与环境变量设置,说明多版本共存、升级回退与CI流水线安装的做法,并整理安装阶段的常见报错与验证步骤。

2026.11.12

100

15

Go-Zero零基础入门教程
Go-Zero零基础入门教程

本专题整理Go-Zero的入门知识,从框架定位、环境准备到跑通第一个API服务,讲清目录分层、配置加载、日志与中间件的基本用法,并对比Gin、Kratos的差异,帮助Go开发者建立整体认知,判断它是否适合当前项目。

2026.11.12

60

15

Postman身份认证怎么配置
Postman身份认证怎么配置

本专题从实际API接口调试场景出发,讲解Postman身份认证的完整配置流程,包括常见认证协议介绍、授权参数设置、访问令牌填写、OAuth 2.0授权及认证失败排查,帮助用户正确完成接口授权与访问验证。

2026.11.06

160

12

Postman请求头Headers怎么设置
Postman请求头Headers怎么设置

围绕Postman HTTP请求头配置展开,讲解Headers选项的具体使用方式,包括Key和Value参数填写、请求头信息添加、常见Header字段设置及请求头修改方法,帮助用户解决接口调试过程中遇到的请求头配置问题。

2026.11.06

140

13

Postman接口请求发送教程
Postman接口请求发送教程

详细介绍Postman接口请求的创建与发送方法,涵盖GET和POST请求、URL配置、请求参数、Headers请求头、Body请求体设置以及响应结果查看,帮助用户掌握Postman接口请求的完整操作流程。

2026.11.06

120

10

DBeaver怎么导入数据
DBeaver怎么导入数据

DBeaver数据导入专题,整理Excel、CSV、SQL、TXT等常见文件的数据导入方法,涵盖目标数据库选择、数据表创建、字段映射、数据类型设置及导入参数配置等操作,帮助用户将本地文件中的数据写入数据库,并了解批量导入、重复数据处理和导入失败等常见问题的解决方法。

2026.11.05

100

12

DBeaver安全防护教程大全
DBeaver安全防护教程大全

DBeaver安全防护专题,围绕数据库连接安全、账号密码保护和访问权限管理展开,整理SSL/TLS加密连接、SSH隧道、数据库凭据保存及证书验证等配置方法,同时介绍敏感信息保护、远程连接风险和高权限账号使用等注意事项,帮助用户提高数据库日常管理的安全性。

2026.11.05

100

12

DBeaver连接创建与配置教程
DBeaver连接创建与配置教程

本专题聚焦DBeaver数据库连接配置与管理,覆盖从新建连接、选择数据库类型到填写连接参数和验证连接的完整流程。针对MySQL、PostgreSQL、SQL Server等常见数据库,整理相应的连接设置方法,并提供驱动缺失、认证失败和连接异常等问题的排查方向。

2026.11.04

100

16

热门下载

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

精品课程

更多
热门推荐
/
最新课程
phpStudy极速入门视频教程
phpStudy极速入门视频教程

共6课时 | 54.7万人学习

独孤九贱(4)_PHP视频教程
独孤九贱(4)_PHP视频教程

共89课时 | 134.3万人学习