本文整理匯總了PHP中Index::index方法的典型用法代碼示例。如果您正苦於以下問題:PHP Index::index方法的具體用法?PHP Index::index怎麽用?PHP Index::index使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Index
的用法示例。
在下文中一共展示了Index::index方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: rtrim
function __construct()
{
$url = filter_input(INPUT_GET, 'url');
$url = rtrim($url, '/');
$url = explode('/', $url);
if (empty($url[0])) {
require 'controllers/controllerIndex.php';
$controller = new Index();
$controller->index();
return false;
}
$file = 'controllers/controller' . $url[0] . '.php';
if (file_exists($file)) {
require $file;
} else {
require 'controllers/controllerError.php';
$controller = new Error();
$controller->index($url[0]);
return false;
}
$controller = new $url[0]();
if (isset($url[1])) {
if (method_exists($controller, $url[1])) {
if (isset($url[2])) {
$controller->{$url[1]}($url[2]);
} else {
$controller->{$url[1]}();
}
} else {
$controller->index();
}
} else {
$controller->index();
}
}
示例2: rtrim
function __construct()
{
$urlll = '';
//$url = isset($_GET['url']) ? $_GET['url']: null;
if (isset($_GET['url']) && is_string($_GET['url'])) {
$url = $_GET['url'];
// name in $_GET['url'] is ok, so you can set it
$url = filter_var($url, FILTER_SANITIZE_URL);
$urll = rtrim($url, '/');
//right trim if there are more than on /
$urlll = explode('/', $urll);
}
/*
*print_r($urlll);//for debugging
*echo '<br/>';
*/
//when there is empty url
if (empty($urlll[0])) {
//echo 'bootstrap initiating Main Index page, \'controllers/Index.php\'</br>';
require 'controllers/index.php';
$controller = new Index();
$controller->index();
return false;
//the remaining below code is not executed
}
$file = 'controllers/' . $urlll[0] . '.php';
//never user controllers, instead use config.ini
if (file_exists($file)) {
//checking if url exists
//incude the file
require $file;
} else {
$this->error();
return false;
//stops the execution of code and returns
}
//initializes the class of the 'included' controller
$controller = new $urlll[0]();
//redirecting to the controller's php file
$controller->loadModel($urlll[0]);
if (isset($urlll[2])) {
if (method_exists($controller, $urlll[1])) {
$controller->{$urlll[1]}($urlll[2]);
//function(param)
} else {
$this->error();
}
} else {
if (isset($urlll[1])) {
if (method_exists($controller, $urlll[1])) {
$controller->{$urlll[1]}();
//function()
} else {
$this->error();
}
} else {
$controller->index();
}
}
}
示例3: isset
function __construct()
{
$url = isset($_GET['url']) ? $_GET['url'] : null;
$url = rtrim($url, '/');
$url = explode('/', $url);
if (empty($url[0])) {
require 'controllers/index.php';
$controller = new Index();
$controller->index();
return false;
}
$file = 'controllers/' . $url[0] . '.php';
if (file_exists($file)) {
require $file;
} else {
throw new Exception("file doesnt exits");
}
$controller = new $url[0]();
$controller->loadModel($url[0]);
if (isset($url[2])) {
$controller->{$url[1]}($url[2]);
} else {
if (isset($url[1])) {
$controller->{$url[1]}();
} else {
$controller->index();
}
}
}
示例4: redirect
public function redirect()
{
require 'app/controllers/indexcontroller.php';
$controller = new Index();
$controller->index();
return false;
}
示例5: isset
function __construct()
{
$url = isset($_GET['url']) ? $_GET['url'] : null;
$url = rtrim($url, '/');
$url = explode('/', $url);
//print_r($url);
if (empty($url[0])) {
require 'controllers/index.php';
$controller = new Index();
$controller->index();
return false;
}
$file = 'controllers/' . $url[0] . '.php';
if (file_exists($file)) {
require $file;
} else {
$this->error();
}
$controller = new $url[0]();
$controller->loadModel($url[0]);
// calling methods
if (isset($url[1])) {
if (method_exists($controller, $url[1])) {
if (isset($url[2])) {
$controller->{$url[1]}($url[2]);
} else {
$controller->{$url[1]}();
}
} else {
$this->error();
}
} else {
$controller->index();
}
}
示例6: __construct
public function __construct()
{
$url = isset($_GET["url"]) ? $_GET["url"] : null;
$url = rtrim($url, "/");
$url = explode("/", $url);
if (empty($url[0])) {
require "controllers/index.php";
$controller = new Index();
$controller->index();
return false;
}
$file = "controllers/" . $url[0] . ".php";
if (file_exists($file)) {
require $file;
} else {
require "controllers/error.php";
$controller = new Error();
return false;
}
$controller = new $url[0]();
$controller->LoadModel($url[0]);
if (isset($url[2])) {
if (method_exists($controller, $url[1])) {
$controller->{$url[1]}($url[2]);
} else {
echo "Error ошибка";
}
} else {
if (isset($url[1])) {
$controller->{$url[1]}();
} else {
$controller->index();
}
}
}
示例7: isset
function __construct($http, $url, $controller, $method, $params)
{
if ($http == "GET") {
if ($params = null) {
return true;
}
$burl = isset($_GET['url']) ? $_GET['url'] : null;
$burl = rtrim($burl, '/');
$burl = explode('/', $burl);
$url = rtrim($url, '/');
$url = explode('/', $url);
if (empty($burl[0])) {
require 'app/controllers/indexcontroller.php';
$controller = new Index();
$controller->index();
return false;
} elseif ($burl[0] == 'index' || $burl[0] == "Index") {
require 'app/controllers/indexcontroller.php';
$controller = new Index();
$controller->index();
return false;
}
/////////////////////////////////////////////////////////////////////////////////////////////
if ($burl == $url) {
$file = 'app/controllers/' . $controller . '.php';
if (file_exists($file)) {
require $file;
} else {
$this->error();
return false;
}
$findcont = $controller;
$class = rtrim($controller, 'controller');
$classname = $class;
$class = new $class();
if (isset($params)) {
if (method_exists($findcont, $method)) {
$findcont->{$method}($params);
} else {
$this->methoderror();
return false;
}
} else {
if (isset($controller)) {
if (method_exists($classname, $method)) {
$class->{$method}();
} else {
$this->methoderror();
return false;
}
}
}
}
///////////end of if burl = url[0]
}
}
示例8: Index
public function Index()
{
$Index = new Index();
$data = array();
$data['html'] = $Index->index();
$view = new View();
$view->setData($data);
$view->setTemplate('../view/_Index.php');
$view->setLayout('../template/Layout.php');
$view->render();
}
示例9: isset
function __construct()
{
$url = isset($_GET['url']) ? $_GET['url'] : null;
$url = rtrim($url, "/");
$url = explode("/", $url);
if (empty($url[0])) {
require '../controllers/index.php';
$controller = new Index();
$controller->index();
return false;
}
// CONTROLLER
// Only allow a controller name with dashes & alphanumeric characters
if (preg_match('/[^0-9a-z-]/i', $url[0])) {
require '../controllers/error.php';
$controller = new Error("Invalid Character In Controller Name.");
return false;
}
// For the script to read past this line, the controller must be alphanumeric w/ dash
$file = '../controllers/' . $url[0] . '.php';
if (file_exists($file)) {
require $file;
} else {
// controller file not found
// HOW CAN I LOG ERRORS HERE? PUT THEM INTO A DATABASE?
require '../controllers/error.php';
$controller = new Error("Controller not found: " . $url[0]);
return false;
//throw new Exception("The file '$file' does not exist!");
}
$controller = new $url[0]();
$controller->loadModule($url[0]);
// CALLING METHODS -------------------------------
if (isset($url[2])) {
// CHECK IF METHOD EXISTS
if (method_exists($controller, $url[1])) {
$controller->{$url[1]}($url[2]);
} else {
require '../controllers/error.php';
$controller = new Error("Method not found: " . $url[1]);
}
return false;
} elseif (isset($url[1])) {
if (method_exists($controller, $url[1])) {
$controller->{$url[1]}();
} else {
require '../controllers/error.php';
$controller = new Error("Method not found: " . $url[1]);
}
return false;
} else {
$controller->index();
}
}
示例10: __construct
public function __construct()
{
// метод, который вызовется автоматом при создании класса
if (isset($_GET[url])) {
$url = $_GET[url];
} else {
$url = NULL;
}
$url = rtrim($url, "/");
// убираем слеш в конце строки
$url = explode("/", $url);
// разбиваем строку в массив, что потом делать запросы
if (empty($url[0])) {
require "controllers/index.php";
// если $url[0] не передается, то мы подклюаем индекс
$controller = new Index();
$controller->index();
return false;
}
Cookie::set('basket');
$file = "controllers/" . $url[0] . ".php";
if (file_exists($file)) {
// проверяем существование файла
require $file;
// подключаем файл, если он сущесвует
} else {
require "controllers/error.php";
// если файла "controllers/".$url[0].".php" нету, то выдаем ошибку
$controller = new Error();
return false;
}
$controller = new $url[0]();
$controller->LoadModel($url[0]);
// загружаем модель и передаем в нее параметр
if (isset($url[2])) {
// проверяем наличие параметра метода
if (method_exists($controller, $url[1])) {
// проверяем наличие метода, и если он есть то передаем в него параметр, если нет, то выдаем ошибку
$controller->{$url[1]}($url[2]);
} else {
echo "Ошибка при вызове метода";
}
} else {
// если второго параметра нет, то запускаем просто метод на выполнение
if (method_exists($controller, $url[1])) {
$controller->{$url[1]}();
} else {
$controller->index();
// если и метода нет, то запускаем индексовый метод
}
}
}
示例11: isset
/**
* Create url: get url and make from it an array
*/
function __construct()
{
$url = isset($_GET['url']) ? $_GET['url'] : null;
$url = rtrim($url, '/');
$url = explode('/', $url);
//check if site.ru/index or just site.ru
if (empty($url[0])) {
require 'controllers/index.php';
$controller = new Index();
$controller->index();
return false;
}
/**
* Service function to check if the array was constructed properly
*/
//print_r($url);
//require 'controllers/' . $url[0] . '.php';
$file = 'controllers/' . $url[0] . '.php';
if (file_exists($file)) {
require $file;
} else {
$this->error();
}
$controller = new $url[0]();
$controller->loadModel($url[0]);
/**
* С помощью данной магии мы из массива с url
* вызываем необходимую функцию, например,
* mvc.example/help/other where help is a controller
* and other is a function
* calling methods
*/
if (isset($url[2])) {
if (method_exists($controller, $url[1])) {
$controller->{$url[1]}($url[2]);
} else {
$this->error();
}
} else {
if (isset($url[1])) {
if (method_exists($controller, $url[1])) {
$controller->{$url[1]}();
} else {
$this->error();
}
} else {
$controller->index();
}
}
}
示例12: isset
function __construct()
{
$url = isset($_GET['url']) ? $_GET['url'] : null;
$url = explode('/', $url);
//print_r($url);
//if empty redirect to index
if (empty($url[0])) {
require 'controllers/index.php';
$controller = new Index();
$controller->index();
return false;
}
$file = 'controllers/' . $url[0] . '.php';
if (file_exists($file)) {
require $file;
$controller = new $url[0]();
if (isset($url[1])) {
if ($url[1] == "") {
$controller->index();
} else {
if (isset($url[2])) {
if ($url[2] == "") {
$controller->{$url}[1]();
} else {
$controller->{$url}[1]($url[2]);
}
} else {
if (method_exists($controller, $url[1])) {
// $controller->index();
$controller->{$url}[1]();
} else {
require 'controllers/error.php';
$controller = new Error();
$controller->index();
return false;
}
}
}
}
if (!isset($url[1])) {
$controller->index();
}
} else {
require 'controllers/error.php';
$controller = new Error();
$controller->index();
return false;
}
}
示例13: isset
function __construct()
{
$url = isset($_GET['url']) ? $_GET['url'] : null;
$url = rtrim($url, '/');
$url = filter_var($url, FILTER_SANITIZE_URL);
$url = explode('/', $url);
// no url, then direct to index page
if (empty($url[0])) {
require 'controllers/index.php';
$controller = new Index();
$controller->index();
return false;
}
$this->direct($url);
}
示例14: isset
function __construct()
{
$url = isset($_GET['url']) ? $_GET['url'] : "index";
$url = rtrim($url, '/');
$url = explode('/', $url);
if (empty($url[0])) {
require 'controllers/index.php';
$controller = new Index();
$controller->index();
return false;
}
$file = 'controllers/' . $url[0] . '.php';
if (file_exists($file)) {
require 'controllers/' . $url[0] . '.php';
} else {
$this->error("Bunday File topilmadi");
return false;
}
$controller = new $url[0]();
$path = './models/' . $url[0] . '_model.php';
if (file_exists($path)) {
$controller->loadModel($url[0]);
}
if (isset($url[2]) != null) {
if (method_exists($controller, $url[1])) {
if (isset($url[3])) {
$controller->{$url[1]}($url[2], $url[3]);
} else {
$controller->{$url[1]}($url[2]);
}
} else {
$this->error("Bunday Method mavjud emas");
return false;
}
} else {
if (isset($url[1])) {
if (method_exists($controller, $url[1])) {
$controller->{$url[1]}();
} else {
$this->error("Bunday Method mavjud emas");
return false;
}
} else {
$controller->index();
}
}
}
示例15: isset
function __construct()
{
$url = isset($_GET['url']) ? $_GET['url'] : null;
$url = rtrim($url, '/');
$url = explode('/', $url);
if (empty($url[0])) {
require 'controllers/index.php';
$controller = new Index();
$controller->index();
return false;
//return false to ensure conditionals below does not execute
}
$file = 'controllers/' . $url[0] . '.php';
if (file_exists($file)) {
require $file;
} else {
$this->error();
}
$controller = new $url[0]();
$controller->loadModel($url[0]);
//calling methods
if (isset($url[2])) {
if (method_exists($controller, $url[1])) {
$controller->{$url}[1]($url[2]);
} else {
$this->error();
}
} else {
if (isset($url[1])) {
if (method_exists($controller, $url[1])) {
$controller->{$url[1]}();
} else {
$this->error();
}
} else {
$controller->index();
}
}
function error()
{
require 'controllers/error.php';
$controller = new Errors();
$controller->index();
return false;
}
}