相关疑难解决方法(0)

如何在类似MVC的页面中基于漂亮的URL加载类?

我想问一些关于如何解决这个问题的提示.我正在尝试建立自己的MVC网站.我学习了URL的基础知识.

http://example.com/blog/cosplay/cosplayer-expo-today
Run Code Online (Sandbox Code Playgroud)

博客 - >控制器
cosplay - >控制器
cosplayer-expo-today中的方法 - >方法中的变量

如果我在博客控制器中动态扩展类别怎么办?我是否需要创建该方法,还是有一些技巧可以自动完成?我的意思是......我现在有这些类别:角色扮演,游戏,电影,系列.所以我需要在控制器中创建这些方法,但它们都做同样的事情,即从数据库中选择其他类别.

  • function cosplay()= example.com/blog/cosplay/
  • 功能游戏()= example.com/blog/game/
  • 功能电影()= example.com/blog/movie/
  • 功能系列()= example.com/blog/series/

关于如何编写我的控制器来自动执行此操作,是否有任何好的建议?我的意思是如果我在我的数据库中上传一个新类别,但我不想修改控制器.可能吗?谢谢您的帮助!

UPDATE

这是我的URL exploder类

class Autoload
{
    var $url;
    var $controller;
    function __construct()
    {
        $this->url = $_GET['url'];
        //HNEM ÜRES AZ URL
        if($this->url!='' && !empty($this->url))
        {
            require 'application/config/routes.php';
            //URL VIZSGÁLATA
            $this->rewrite_url($this->url);

            //URL SZÉTBONTÁSA
            $this->url = explode('/', $this->url);

            $file = 'application/controllers/'.$this->url[0].'.php';
            //LÉTEZIK A CONTROLLER?
            if(file_exists($file))
            {
                require $file;
                $this->controller = new $this->url[0];

                //KÉRELEM ALATT VAN AZ ALOLDAL?
                if(isset($this->url[1]))
                {
                    //LÉTEZIK A …
Run Code Online (Sandbox Code Playgroud)

php .htaccess url-routing

6
推荐指数
1
解决办法
4640
查看次数

标签 统计

.htaccess ×1

php ×1

url-routing ×1