成都创新互联网站制作重庆分公司

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://cxhlcq.cn/article/dsicgp.html">http://cxhlcq.cn/article/dsicgp.html</a>
        </div>
    </div>
</div>
<div class="other container">
    <h3>其他资讯</h3>
    <ul>
        <li>
                <a href="/article/schopp.html">德阳抖音代运营介绍</a>
            </li><li>
                <a href="/article/schoee.html">抖音账号剪辑短视频制作灵感,抖音账号短视频剪辑制作教程</a>
            </li><li>
                <a href="/article/schoes.html">李子柒短视频营销,李子柒短视频营销</a>
            </li><li>
                <a href="/article/schoec.html">南开抖音代运营公司</a>
            </li><li>
                <a href="/article/schohe.html">自媒体代运营的好处有哪些,如何选择靠谱的自媒体代运营公司</a>
            </li>    </ul>
</div>
<div class="footer">
    <div class="foota container">
        <div class="foot_nav fl col-lg-8 col-md-8 col-sm-12 col-xs-12">
            <ul>
                <li class="col-lg-3 col-md-3 col-sm-3 col-xs-6">
                    <h3>网站制作</h3>
                    <a href="http://www.myzwz.com/" target="_blank">绵阳网站制作</a><a href="http://chengdu.cdcxhl.com/" target="_blank">成都营销网站制作</a><a href="http://chengdu.kswjz.com/" target="_blank">成都网站制作</a><a href="http://www.wjwzjz.com/" target="_blank">温江网站制作</a><a href="http://chengdu.xwcx.net/mobile/" target="_blank">移动手机网站制作</a><a href="http://www.cdxwcx.cn/" target="_blank">成都网站制作公司</a>                </li>
                <li class="col-lg-3 col-md-3 col-sm-3 col-xs-6">
                    <h3>企业服务</h3>
                    <a href="https://www.cdcxhl.com/service/guangdianxuke.html" target="_blank">广播电视节目制作许可证</a><a href="https://www.cdcxhl.com/service/licence.html" target="_blank">药房许可证</a><a href="https://www.cdcxhl.com/service/icpbeian.html" target="_blank">ICP经营性备案</a><a href="https://www.cdcxhl.com/service/shipinxuke.html" target="_blank">食品经营许可证</a><a href="https://www.cdcxhl.com/ruanwen/yingxiao/" target="_blank">软文发布平台</a><a href="https://www.cdcxhl.com/service/beian.html" target="_blank">网站备案</a>                </li>
                <li class="col-lg-3 col-md-3 col-sm-3 col-xs-6">
                    <h3>网站建设</h3>
                    <a href="http://www.cdkjz.cn/" target="_blank">网站建设</a><a href="http://www.wjzwz.com/" target="_blank">温江网站建设</a><a href="http://www.cdkjz.cn/fangan/finance/" target="_blank">金融行业网站建设方案</a><a href="http://www.ncwzjz.com/" target="_blank">南充网站建设</a><a href="https://www.cdcxhl.com/xiangyingshi.html" target="_blank">成都响应式网站建设公司</a><a href="http://seo.cdkjz.cn/mobile/" target="_blank">营销型网站建设</a>                </li>
                <li class="col-lg-3 col-md-3 col-sm-3 col-xs-6">
                    <h3>服务器托管</h3>
                    <a href="https://www.cdcxhl.com/tuoguan.html" target="_blank">成都服务器托管</a><a href="http://www.cdfuwuqi.com/" target="_blank">服务器托管机房</a><a href="https://www.cdcxhl.com/idc/cqyd.html" target="_blank">重庆移动机房托管</a><a href="https://www.cdcxhl.com/idc/ziyang.html" target="_blank">资阳天府云计算中心</a><a href="https://www.cdcxhl.com/idc/cqwld.html" target="_blank">重庆电信五里店机房托管</a><a href="https://www.cdcxhl.com/tuoguan/" target="_blank">IDC机房托管</a>                </li>
            </ul>
        </div>
        <div class="footar fl col-lg-4 col-md-4 col-sm-12 col-xs-12">
            <p>全国免费咨询:</p>
            <b>400-028-6601</b>
            <p>业务咨询:028-86922220 / 13518219792</p>
            <p>节假值班:18980820575 / 13518219792</p>
            <p>联系地址:成都市太升南路288号锦天国际A幢1002号</p>
        </div>
    </div>
    <div class="footb">
        <div class="copy container">
            <div class="fl">Copyright © 成都创新互联科技有限公司重庆分公司  <a href="https://beian.miit.gov.cn/" target="_blank">渝ICP备2021005571号</a></div>
            <!--<div class="fr"><a href="https://www.cdxwcx.com/" target="_blank">成都网站建设</a>:<a href="https://www.cdcxhl.com/" target="_blank">创新互联</a></div>-->
        </div>
    </div>
    <div class="link">
        <div class="container">
            友情链接::
            <a href="https://www.cdcxhl.com/" target="_blank">成都网站建设</a>
            <a href="https://www.cdcxhl.com/city/chongqing.html" target="_blank">重庆网站建设</a>
            <a href="">四川网站建设</a>
            <a href="">重庆建设网站</a>
            <a href="https://www.cdxwcx.com/jifang/xiyun.html" target="_blank">移动服务器托管</a>
            <a href="http://www.cdfuwuqi.com/" target="_blank">成都服务器托管</a>
            <a href="https://www.cdcxhl.cn/" target="_blank">云服务器</a>
            <a href="http://www.cdhuace.com/" target="_blank">广告设计制作</a>
            <a href="https://www.cdcxhl.com/sheji/chongqing.html" target="_blank">重庆网页设计</a>
            <a href="https://www.cdcxhl.com/zuo/chongqing.html" target="_blank">重庆做网站</a>
            <a href="https://www.cdcxhl.com/zhizuo/chongqing.html" target="_blank">重庆网站制作</a>
            <a href="">重庆网站建设</a>
            <a href="">重庆网站公司</a>
            <a href="">渝中网站制作</a>
            <a href="">重庆网站设计</a>
        </div>
    </div>
</div>
<div class="foot">
    <ul class="public-celan">
        <li>
            <a href="https://p.qiao.baidu.com/cps3/chatIndex?siteToken=6ce441ff9e2d6bedbdfc2a4138de449e&speedLogId=162260383240185e3_1622603832401_02407&eid=6256368&reqParam=%7B%22from%22%3A1%2C%22sessionid%22%3A%22-100%22%2C%22siteId%22%3A%2211284691%22%2C%22tid%22%3A%22-1%22%2C%22userId%22%3A%226256368%22%2C%22ttype%22%3A1%2C%22pageId%22%3A0%7D" target="_blank" class="a1 db tc">
                <img src="/Public/Home/img/icon-23.png" alt="" class="db auto">
                <span class="span-txt">在线咨询</span>
            </a>
        </li>
        <li>
            <a href="tel:18980820575" class="a1 db tc">
                <img src="/Public/Home/img/icon-24.png" alt="" class="db auto">
                <span class="span-txt">电话咨询</span>
            </a>
        </li>
        <li>
            <a target="_blank" href="tencent://message/?uin=1683211881&Site=&Menu=yes" class="a1 db tc">
                <img src="/Public/Home/img/icon-25.png" alt="" class="db auto">
                <span class="span-txt">QQ咨询</span>
            </a>
        </li>
        <li>
            <a target="_blank" href="tencent://message/?uin=532337155&Site=&Menu=yes" class="a1 db tc public-yuyue-up">
                <img src="/Public/Home/img/icon-26.png" alt="" class="db auto">
                <span class="span-txt">预约顾问</span>
            </a>
        </li>
    </ul>
</div>
<div class="customer">
    <dl class="icon1">
        <dt>
            <a href="tencent://message/?uin=1683211881&Site=&Menu=yes">
                <i class="iconT"><img src="/Public/Home/img/QQ.png" alt=""></i>
                <p>在线咨询</p>
            </a>
        </dt>
    </dl>
    <dl class="icon2">
        <dt><i><img src="/Public/Home/img/weixin.png" alt=""></i><p>微信咨询</p></dt>
        <dd><img src="/Public/Home/img/ewm.png"></dd>
    </dl>
    <dl class="icon3">
        <dt><i><img src="/Public/Home/img/dianhua.png" alt=""></i><p>电话咨询</p></dt>
        <dd>
            <p>028-86922220(工作日)</p>
            <p>18980820575(7×24)</p>
        </dd>
    </dl>
    <dl class="icon4">
        <dt class="sShow">
            <a href="tencent://message/?uin=244261566&Site=&Menu=yes">
                <i><img src="/Public/Home/img/dengji.png" alt=""></i><p>提交需求</p>
            </a>
        </dt>
    </dl>
    <dl class="icon5">
        <dt class="gotop">
            <a href="#top">
                <i><img src="/Public/Home/img/top.png" alt=""></i><p>返回顶部</p>
            </a>
        </dt>
    </dl>
</div>
</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>