link typu: localhost/index.php/moduł/metoda/parametr/parametr.html
Pisane z palca, może zawierać błedy.
<?php
define('MAIN_MODULE', 'news'); define('MAIN_METHOD', 'display'); define('ADDRESS', 'http://localhost/index.php/'); class URL {
/*
* Module
* @access public
* @var string
*/
public $module;
/*
* Method
* @access public
* @var string
*/
public $method;
/*
* Values
* @access public
* @var array
*/
/*
* Dot
* @access private
* @var string
*/
private $dot;
/*
* Using GET ?
* @access private
* @var bool
*/
private $uGET;
/*
* link end
* @access private
* @var string
*/
private $end;
/**
* Construct
* @param string $dot
* @param string $end
* @param bool $user_get
* @access public
* @return void
*/
public function __construct($dot, $end, $use_get = false) {
$this->dot = $dot;
$this->end = $end
$this->uGET = false;
$this->setParams();
}
/**
* Set params
* @param void
* @access private
* @return void
*/
private function setParams()
{
if(!$this->uGET) {
$s = isset( $_SERVER['PATH_INFO'] ) ?
$_SERVER['PATH_INFO'] : ''; foreach ( $arrParams as $wartosc ) {
$this->vars[] = $wartosc;
}
} else {
foreach($_GET AS $value) {
$this->vars[] = $value;
}
}
$this->setModule();
$this->setMethod();
$this->setValues();
}
/**
* Set module
* @param void
* @access public
* @return void
*/
public function setModule() {
$this->module = (isset($this->vars[0
])) ?
$this->vars[0
] : MAIN_MODULE
; }
/**
* get module
* @param void
* @access public
* @return void
*/
public function getModule() {
return $this->module;
}
/**
* Set method
* @param void
* @access public
* @return void
*/
public function setMethod() {
$this->method = (isset($this->vars[1
])) ?
$this->vars[1
] : TMAIN_METHOD
; }
/**
* get method
* @param void
* @access public
* @return void
*/
public function getMethod() {
return $this->method;
}
/**
* Set values
* @param void
* @access public
* @return void
*/
private function setValues() {
sort($this->vars); # mozna uzyc array_values
}
/**
* get all values
* @param void
* @access public
* @return array
*/
public function getValues() {
return $this->vars;
}
/**
* Construct
* @param int $VNumber
* @access public
* @return string
*/
public function getValue( $VNumber ) {
return $this->vars[$VNumber];
}
/**
* Count values
* @param void
* @access public
* @return int
*/
public function getCValues() {
return count($this->vars); }
/**
* Make url
* @param array $urlArg
* @access public
* @return void
*/
public function makeUrl( $urlArg ) {
if($this->uGET == FALSE) {
$url = ADDRESS
. join($this->dot, $urlArg) .'.html'; }else {
foreach($urlArg AS $name => $value) {
$aURL[] = '?' . $name .'='. $value;
}
$url= ADDRESS
. substr(join($this->dot, $urlArg), 0
, 1
); }
}
}
?>
Użycie:
<?php
$url = new URL('/', '.html');
$url->makeUrl(array('comments', 'display', 'blog', 'id', '47')); ?>
pozdrawiam
Ten post edytował Ociu 27.11.2005, 11:33:51