@Deman1

Как изменить путь определения юзера в юрле?

Здравствуйте, извиняюсь что не смог придумать названия темы так как хз даже как назвать, к сути
есть сайт который купил в нем есть косяк который мне не нравится, в юрле например когда я перехожу в пользователя у меня выходит ссылка такая site/u/index/index/2
Как мне это поменять чтобы был 1 index? (site/u/index/2)

Код с файла index.php вот
class indexController extends Controller {
    public function index($uid = null) {


Это с контролера

abstract class Controller {
    private $registry;
    protected $data = array();

    public function __construct($registry) {
        $this->registry = $registry;
    }
    public function __get($key) {
        return $this->registry->$key;
    }
    public function __set($key, $value) {
        $this->registry->$key = $value;
    }
    public function getChild($child = array()) {
        foreach($child as $item) {
            $this->action->make($item);
            $this->data[basename($item)] = $this->action->go(true);
        }
    }
}


И вот ещё с какова то обработчика

class Action {
	private $registry;

	private $folder;
	private $controller;
	private $method;
	private $args;
	
	public function __construct($registry)
	{
		$this->registry = $registry;
	}
	public function make($action) {
		$this->folder = null;
		$this->controller = null;
		$this->method = null;
		$this->args = null;
		$action = preg_replace("/[^\w\d\s\/]/", '', $action);
		$parts = explode('/', $action);
		$parts = array_filter($parts);
		foreach($parts as $item) {
			$fullpath = AP_DIR . 'controllers' . $this->folder . '/' . $item;
			if(is_dir($fullpath)) {
				$this->folder .= '/' . $item;
				array_shift($parts);
				continue;
			}
			elseif(is_file($fullpath . '.php')) {
				$this->controller = $item;
				array_shift($parts);
				break;
			} else break;
		}
		if(empty($this->folder)) {
			$this->folder = 'errore';
		}
		if(empty($this->controller)) {
			$this->controller = 'index';
		}
		if($c = array_shift($parts)) {
			$this->method = $c;
		} else {
			$this->method = 'index';
		}
		if(isset($parts[0])) {
			$this->args = $parts;
		}
	}
	
	public function go($commonEnable = false) {
		$controllerFile = AP_DIR . 'controllers/' . $this->folder . '/' . $this->controller . '.php';
		$controllerClass = $this->controller . 'Controller';
		if($this->folder != "home" || $commonEnable == true) {
			if(is_readable($controllerFile)) {
				require_once($controllerFile);
				$controller = new $controllerClass($this->registry);
				
				if(is_callable(array($controller, $this->method))) {
					$this->method = $this->method;
				} else {
					$this->method = 'index';
				}
				
				if(empty($this->args)) {
					return call_user_func(array($controller, $this->method));
				} else {
					return call_user_func_array(array($controller, $this->method), $this->args);
				}
			}
		}
		return error('ErRoR: PF1022 -> ' . $this->controller );
	}
}
  • Вопрос задан
  • 69 просмотров
Пригласить эксперта
Ответы на вопрос 1
anton_reut
@anton_reut
Начинающий веб-разработчик
.htaccess
URL rewriting with PHP

А сам код не трогай.
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы