etroy 2011-11-05 08:18:54 3365次浏览 2条回复 0 0 0

我现在要写一个程序,其中有分城市的。那么我想把分城市的访问地址设置成:http://www....com/beijing http://www....com/guangzhou

怎么实现呢?

我用楼2的方法做,问题提示:

Internal Server Error
include(Memcache.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory
An internal error occurred while the Web server was processing your request. Please contact the webmaster to report this problem. 

Thank you. 怎么回事呢?

  • 回复于 2011-11-05 09:45 举报

    你在要main.php里面的urlManager里面设置。

    比如说,你有这样的controller和action,post/city,它接受name的参数。

    'urlManager'=>array(
        'class'=>'CUrlManager',
        'urlFormat'=>'path',
        'urlSuffix'=>'.html',
        'showScriptName'=>false,
        'rules'=>array(
            //它的路由规则。。。
            '<name:\w+>'=>'post/city',
            '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
        ),
    ),
    

    这样你在视图里面就可以这样来生成地址了。

    <?php 
    echo CHtml::link(
        '广州',
        Yii::app()->createUrl('post/city', array('name'=>'guangzhou'))
    );
    ?>
    

    生成的地址将会是 <a href="/guangzhou.html">广州</a>

  • 回复于 2011-11-05 10:15 举报

    嗯。。我试一下。。

您需要登录后才可以回复。登录 | 立即注册