028-86922220
建站资讯

网站建设资讯

为你提供网站建设行业资讯、网站优化知识、主机域名邮箱、网站开发常见问题等。

YII如何使用url组件美化管理-创新互联

这篇文章将为大家详细讲解有关YII如何使用url组件美化管理,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

昌江黎族网站建设公司成都创新互联,昌江黎族网站设计制作,有大型网站制作公司丰富经验。已为昌江黎族近千家提供企业网站建设服务。企业网站搭建\外贸网站制作要多少钱,请找那个售后服务好的昌江黎族做网站的公司定做!

具体如下:

urlManager组件

yii的官方文档对此的解释如下:

urlSuffix  此规则使用的url后缀,默认使用CurlManger::urlSuffix,值为null。例如可以将此设置为.html,让url看起来“像”是一个静态页面。
caseSensitive  是否大小写敏感,默认使用CUrlManager::caseSensitive,值为null。
defaultParams  该规则使用的默认get参数。当使用该规则来解析一个请求时,这个参数的值会被注入到$_GET参数中。
matchValue  当创建一个URL时,GET参数是否匹配相应的子模式。默认使用CurlManager::matchValue,值为null。

如果该属性为 false,那么意味着当路由和参数名匹配给定的规则时,将以此来创建一个URL。

如果该属性为true,那么给定的参数值夜必须匹配相应的参数子模式。

注意:将此属性设置为true会降低性能。

我们使用一些例子来解释网址工作规则。我们假设我们的规则包括如下三个:

array(
  'posts'=>'post/list',
  'post/'=>'post/read',
  'post//'=>'post/read',
)</pre><p>调用$this->createUrl('post/list')生成/index.php/posts。第一个规则适用。</p><p>调用$this->createUrl('post/read',array('id'=>100))生成/index.php/post/100。第二个规则适用。</p><p>调用$this->createUrl('post/read',array('year'=>2008,'title'=>'a sample post'))生成/index.php/post/2008/a%20sample%20post。第三个规则适用。</p><p>调用$this->createUrl('post/read')产生/index.php/post/read。请注意,没有规则适用。</p><p>总之,当使用createUrl生成网址,路线和传递给该方法的GET参数被用来决定哪些网址规则适用。如果关联规则中的每个参数可以在GET参数找到的,将被传递给createUrl ,如果路线的规则也匹配路线参数,规则将用来生成网址。</p><p>如果GET参数传递到createUrl是以上所要求的一项规则,其他参数将出现在查询字符串。例如,如果我们调用$this->createUrl('post/read',array('id'=>100,'year'=>2008)) ,我们将获得/index.php/post/100?year=2008。为了使这些额外参数出现在路径信息的一部分,我们应该给规则附加/* 。 因此,该规则post/<id:\d+>/* ,我们可以获取网址/index.php/post/100/year/2008 。</p><p>正如我们提到的,URL规则的其他用途是解析请求网址。当然,这是URL生成的一个逆过程。例如, 当用户请求/index.php/post/100 ,上面例子的第二个规则将适用来解析路线post/read和GET参数array('id'=>100) (可通过$_GET获得) 。</p><p>提示:此网址通过createurl方法所产生的是一个相对地址。为了得到一个绝对的url ,我们可以用前缀yii: :app()->hostInfo ,或调用createAbsoluteUrl 。</p><p>注:使用的URL规则将降低应用的性能。这是因为当解析请求的URL ,[ CUrlManager ]尝试使用每个规则来匹配它,直到某个规则可以适用。因此,高流量网站应用应尽量减少其使用的URL规则。</p><p>test.com/vthot 想生成 test.com/vthot/</p><br/><p>复制代码 代码如下:</p><p>'urlSuffix'=>'/',</p><p><br/>要更改URL格式,我们应该配置urlManager应用元件,以便createUrl可以自动切换到新格式和应用程序可以正确理解新的网址:</p><pre>'urlManager'=>array(
  'urlFormat'=>'path',
  'showScriptName'=>false,
  'urlSuffix'=>'.html',
  'rules'=>array(
    'posts'=>'post/list',
    'post/<id:\d+>'=>array('post/show','urlSuffix'=>'.html'),
    'post/<id:\d+>/<mid:\w+>'=>array('post/view','urlSuffix'=>'.xml'),
  ),
),</pre><p>示例一</p><p>Rule代码</p><br/><p>复制代码 代码如下:</p><p>'posts'=>'post/list',</p><p><br/>Action代码</p><br/><p>复制代码 代码如下:</p><p>echo $this->createAbsoluteUrl('post/list');</p><p>输出</p><p>http://localhost/test/index.php/post</p><p>示例二</p><p>Rule代码</p><br/><p>复制代码 代码如下:</p><p>'post/<id:\d+>'=>array('post/show','urlSuffix'=>'.html'),</p><p><br/>Action代码</p><br/><p>复制代码 代码如下:</p><p>echo $this->createAbsoluteUrl('post/show',array('id'=>998, 'name'=>'123'));</p><p>输出</p><p>http://localhost/test/index.php/post/998.html?name=123</p><p>示例三</p><p>Rule代码:</p><br/><p>复制代码 代码如下:</p><p>'post/<id:\d+>/<mid:\w+>'=>array('post/view','urlSuffix'=>'.xml'),</p><p>Action代码</p><br/><p>复制代码 代码如下:</p><p>echo $this->createAbsoluteUrl('post/view',array('id'=>998, 'mid'=>'tody'));</p><p><br/>输出</p><p>http://localhost/test/index.php/post/998/tody.xml</p><p>示例四</p><p>Rule代码</p><br/><p>复制代码 代码如下:</p><p>'http://<user:\w+>.vt.com/<_c:(look|seek)>'=>array('<_c>/host','urlSuffix'=>'.me'),</p><p>Action代码:</p><pre>echo $this->createAbsoluteUrl('look/host',array('user'=>'boy','mid'=>'ny-01'));
echo '';
echo $this->createAbsoluteUrl('looks/host',array('user'=>'boy','mid'=>'ny-01'));</pre><p>输出</p><p>http://boy.vt.com/look.me?mid=ny-01<br/>http://localhost/test/index.php/looks/host/user/boy/mid/ny-01</p><p>1)controller/Update/id/23</p><pre>public function actionUpdate(){
  $id = Yii::app()->request->getQuery('id') ; 经过处理的$_GET['id']
}
//$id = Yii::app()->request->getPost('id'); 经过处理的$_POST['id']
//$id = Yii::app()->request->getParam('id'); //CHttpRequest更多</pre><p>2)public function actionUpdate($id)  这种不支持多主键,会检查一下到底GET里面有没有id,没有id就直接不允许访问</p><pre>'sayhello/<name>' => 'post/hello', name是PostController actionHello($name)的参数
'post/<alias:[-a-z]+>' => 'post/view',  domain/post/e文小写 其中:前面的alias是PostController actionView($alias)的参数
'(posts|archive)/<order:(DESC|ASC)>' => 'post/index', domain/posts/DESC或domain/posts/ASC
'(posts|archive)' => 'post/index', domain/posts或domain/archive
'tos' => array('website/page', 'defaultParams' => array('alias' =>'terms_of_service')),</pre><p>When the URL is /tos, pass terms_of_service as the alias parameter value.</p><p><strong>隐藏 index.php</strong></p><p>还有一点,我们可以做进一步清理我们的网址,即在URL中藏匿index.php  入口脚本。这就要求我们配置Web服务器,以及urlManager应用程序元件。</p><p>1.add showScriptName=>false</p><p>2.add project/.htaccess</p><pre>RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php</pre><p>3.开启rewrite</p><p>简单的说,在main.php中简单设置urlManager,然后讲了3条规则,基本都覆盖到了。最后是隐藏index.php,请记住.htaccess位于index.php同级目录 ,而不是protected/目录。其他就简单了。</p><p>关于“YII如何使用url组件美化管理”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。</p>            <br>
            本文题目:YII如何使用url组件美化管理-创新互联            <br>
            文章源于:<a href="http://whjierui.cn/article/dsicgp.html">http://whjierui.cn/article/dsicgp.html</a>
        </div>
    </div>
    <div class="other">
        <h3>其他资讯</h3>
        <ul>
            <li>
                    <a href="/article/dehiede.html">c语言trim函数guan
方 c语言setitimer函数</a>
                </li><li>
                    <a href="/article/dehiidc.html">菜单函数c语言代码 c语言制作菜单代码</a>
                </li><li>
                    <a href="/article/dehiehd.html">c语言预言函数 c语言预言函数怎么表示</a>
                </li><li>
                    <a href="/article/dehiide.html">c语言函数声明不写可以吗 c语言函数声明不写形参</a>
                </li><li>
                    <a href="/article/dehiehh.html">次函数拟合c语言 一次函数拟合</a>
                </li>        </ul>
    </div>
</div>
<footer>
    <div class="foot-top">
        <ul>
            <li>
                <div class="title">关于美图云海</div>
                <div class="tbox">
                    <div class="txt">
                        美图云海专注于网站建设、小程序开发,
                        <br /> 用心做好每一个网站,懂您所需、做您所想!
                        <br /> 我们比其他网络公司做的更好、做的更多,
                        <br /> 为客户创造更大的价值,让客户更省心!
                    </div>
                    <a rel="nofollow" href="javascript:;" class="more">MORE</a>
                </div>
            </li>
            <li>
                <div class="title">相关专题</div>
                <div class="tbox">
                    <a href="javascript:;" class="link">企业官网定制</a>
                    <a href="javascript:;" class="link">小程序开发</a>
                    <a href="javascript:;" class="link">品牌网站设计</a>
                    <a href="javascript:;" class="link">网站建设标签</a>
                    <a href="javascript:;" class="link">乐山网站建设</a>
                    <a href="javascript:;" class="link">高端网站设计</a>
                    <a href="javascript:;" class="link">公司做网站</a>
                </div>
            </li>
            <li>
                <div class="title">凭什么选择我们</div>
                <div class="tbox">
                    <a class="link">专业设计团队</a>
                    <a class="link">快速响应服务</a>
                    <a class="link">7个软件著作权</a>
                    <a class="link">已服务3000+客户</a>
                    <a class="link">项目检测具体全面</a>
                    <a class="link">技术研发能力强劲</a>
                    <a class="link">深度符合SEO优化</a>
                    <a class="link">15项设计奖项</a>
                    <a class="link">完善的制作流程</a>
                    <a class="link">售后服务让您省心</a>
                </div>
            </li>
            <li>
                <div class="title">网站设计案例</div>
                <div class="tbox">
                    <ul>
                        <li>
                            <a href="javascript:;" target="_blank">
                                <div class="img"><img src="/Public/Home/images/gebaili.jpg" alt="哥百利" />
                                </div>
                                <div class="tboxs">
                                    <div class="t1">哥百利</div>
                                    <div class="t2">家具研发、设计、生产、服务为一体的专业实木家具订做企业</div>
                                </div>
                            </a>
                        </li>
                        <li>
                            <a href="javascript:;" target="_blank">
                                <div class="img"><img src="/Public/Home/images/cdshujin.jpg" alt="蜀锦在线" /></div>
                                <div class="tboxs">
                                    <div class="t1">蜀锦在线</div>
                                    <div class="t2">汽车行业网站建设</div>
                                </div>
                            </a>
                        </li>
                    </ul>
                </div>
            </li>
        </ul>
    </div>
    <div class="foot-center">
        <ul>
            <li>
                <div class="f-ewm"><img alt="美图云海微信公众号" src="/Public/Home/images/ewm.jpg" /></div>
                <div class="tbox ewm">
                    <div class="t1">扫一扫关注</div>
                    <div class="t2">专业团队为您解答</div>
                </div>
            </li>
            <li>
                <div class="tbox tel">
                    <div class="t1">电话/邮箱</div>
                    <div class="t2">400-028-6601 / 028-86922220<br>631063699@qq.com</div>
                </div>
            </li>
            <li>
                <div class="tbox sz">
                    <div class="t1">成都(总部)</div>
                    <div class="t2">成华区 双林路22号仁禾商务楼5F<br> 大客户专线:13518219792
                    </div>
                </div>
            </li>
            <li>
                <div class="tbox gz">
                    <div class="t1">网站建设(乐山站)</div>
                    <div class="t2">
                        乐山市市中区瑞祥路一段1507号
                        <br /> 028-86922220
                    </div>
                </div>
            </li>
        </ul>
    </div>
    <div class="foot-button">
        <div class="link-box" style="width:100%;float:none;">
            <div class="a-box"></div>
            <div style="border-top:1px solid #ebebeb;font-size:12px;color:#666666;line-height:2;padding-top:20px;margin-top:20px;">
                业务范围包括企业网站建设、商城系统开发、品牌网站设计、旅游网站制作、英文外贸网站、教育培训门户网站开发、微信手机移动端开发、响应式网站建设、微信小程序开发、APP定制和其他类型网站定制等。
                <br>服务区域包括成都市锦江区、青羊区、武侯区、金牛区、成华区、龙泉驿、温江、新都、高新区、成都市以及全国各地接受异地服务商的公司企业或者机构。
                <br>
                <div class="a-box"><span><b>友情链接</b></span>
                    <a href="http://m.cdcxhl.cn/dingzhi/
" title="定制网站设计" target="_blank">定制网站设计</a><a href="https://www.cdcxhl.com/" title="成都网站制作公司" target="_blank">成都网站制作公司</a><a href="http://www.cdhuace.com/faguangzi/wbfgz.html" title="无边发光字制作" target="_blank">无边发光字制作</a><a href="https://www.hayoumeiju.com/" title="深圳纱窗安装" target="_blank">深圳纱窗安装</a><a href="http://www.chdeyu.com/" title="佑馨产后护理" target="_blank">佑馨产后护理</a><a href="http://www.hkccoic.com/" title="四川國際商會" target="_blank">四川國際商會</a><a href="http://www.czfdjwx.com/" title="崇州威斯达宇" target="_blank">崇州威斯达宇</a><a href="http://www.kswcd.com/solution/" title="网站方案" target="_blank">网站方案</a><a href="http://www.shganxi.cn/" title="簇桥薇薇新娘" target="_blank">簇桥薇薇新娘</a><a href="http://www.scjxjsjy.com/" title="开元建筑学校" target="_blank">开元建筑学校</a>                </div>
            </div>
            <div class="copyright">©2025 青羊区美图云海设计工作室(个体工商户)乐山站   蜀ICP备19037934号</div>
        </div>
    </div>
</footer>
<div class="fixed-contact-wrap show">
    <ul class="item-list clearfix">
        <li class="phone">
            <a rel="nofollow" target="_blank" href="tel:028-86922220"><i
                    class="icon"></i><strong>028-86922220</strong></a>
        </li>
        <li class="qq">
            <a rel="nofollow" target="_blank" href="http://wpa.qq.com/msgrd?v=3&uin=244261566&site=qq&menu=yes"><i
                    class="icon"></i><strong> 244261566</strong></a>
        </li>
        <li class="back-top">
            <a href="#" rel="nofollow" class="back-to-top"><i class="icon"></i><strong> 回到顶部</strong></a>
        </li>
    </ul>
</div>
<script type="text/javascript">
    //右侧联系我们悬浮窗
    $(".fixed-contact-wrap").hover(function () {
        $(this).addClass("active");
    }, function () {
        $(this).removeClass("active");
    })
    function show_phone_menu() {
        $(".right-side ul").toggle();
    }
</script>

</body>
</html>

<script>
    $(".con img").each(function(){
        var src = $(this).attr("src");    //获取图片地址
        var str=new RegExp("http");
        var result=str.test(src);
        if(result==false){
            var url = "https://www.cdcxhl.com"+src;    //绝对路径
            $(this).attr("src",url);
        }
    });
    window.onload=function(){
        document.oncontextmenu=function(){
            return false;
        }
    }
</script>