एक नियंत्रक बनाने का प्रयास किया जो उन्हें सही ढंग से आउटपुट करता था। अगर उनमें से कोई भी बंद है तो मुझे बताएं।
class Controller_Info extends Controller
{
public function action_index()
{
$uris = array
(
'page' => array
(
'a' => Request::instance()->uri(),
'b' => URL::base(TRUE, FALSE).Request::instance()->uri(),
'c' => URL::site(Request::instance()->uri()),
'd' => URL::site(Request::instance()->uri(), TRUE),
),
'application' => array
(
'a' => URL::base(),
'b' => URL::base(TRUE, TRUE),
'c' => URL::site(),
'd' => URL::site(NULL, TRUE),
),
);
$this->request->headers['Content-Type'] = 'text/plain';
$this->request->response = print_r($uris, true);
}
public function action_version()
{
$this->request->response = 'Kohana version: '.Kohana::VERSION;
}
public function action_php()
{
phpinfo();
}
}
आउटपुट इस:
Array
(
[page] => Array
(
[a] => info/index
[b] => /kohana/info/index
[c] => /kohana/info/index
[d] => http://localhost/kohana/info/index
)
[application] => Array
(
[a] => /kohana/
[b] => http://localhost/kohana/
[c] => /kohana/
[d] => http://localhost/kohana/
)
)
तकनीकी रूप से, यह वास्तव में केवल प्रथम पृष्ठ यूआरएल कोई वास्तविक रिश्तेदार यूआरएल है कि, के बाद से सभी दूसरों को भी /
या http://
साथ शुरू करते हैं।
वर्तमान पृष्ठ के लिए यूआरएल प्राप्त करने की आवश्यकता है, इसलिए यूआरएल वर्ग का विस्तार करने का फैसला किया गया। सोचा था कि मैं इसे यहां साझा कर सकता हूं। Kohana_Request :: detect_uri(): मुझे पता है आप क्या सोचते हैं :)
/**
* Extension of the Kohana URL helper class.
*/
class URL extends Kohana_URL
{
/**
* Fetches the URL to the current request uri.
*
* @param bool make absolute url
* @param bool add protocol and domain (ignored if relative url)
* @return string
*/
public static function current($absolute = FALSE, $protocol = FALSE)
{
$url = Request::instance()->uri();
if($absolute === TRUE)
$url = self::site($url, $protocol);
return $url;
}
}
echo URL::current(); // controller/action
echo URL::current(TRUE); // /base_url/controller/action
echo URL::current(TRUE, TRUE); // http://domain/base_url/controller/action
आशा है कि 3.1+ आप ('एक स्ट्रिंग पारित करने के लिए की जरूरत है http ',' https ') या यूआरएल :: साइट में $ प्रोटोकॉल पैरामीटर के लिए अनुरोध ऑब्जेक्ट। और यदि आप क्वेरी स्ट्रिंग को संरक्षित करना चाहते हैं तो आप अंत में URL :: query() जोड़ सकते हैं। – Enrique