gpt4 book ai didi

php - 使用 get 方法自定义 URL Helper 重定向

转载 作者:搜寻专家 更新时间:2023-10-31 21:59:11 24 4
gpt4 key购买 nike

在我的 codeigniter application/helper/MY_url_helper 上,我希望能够添加 '?&route=' 。 $uri 我希望能够在 index.php 之后但在第一个文件夹/函数之前使用我的 '?&route='

但是每次我点击我的链接时,url 都会改变但页面保持不变?

问题:如何在我的助手上添加 '?&route=' 。 $uri 但仍然重定向到页面目前每次即使我点击链接时 url 都会更改但页面保持不变?

redirect('common/dashboard');

网址 http://localhost/project/admin/?&route=common/dashboard

我已经尝试过路由和同样的问题。

<?php

if ( ! function_exists('redirect'))
{
function redirect($uri = '', $method = 'auto', $code = NULL)
{
//if ( ! preg_match('#^(\w+:)?//#i', $uri))
//{
$uri = site_url('?&route=' . $uri);
//}

// IIS environment likely? Use 'refresh' for better compatibility
if ($method === 'auto' && isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== FALSE)
{
$method = 'refresh';
}
elseif ($method !== 'refresh' && (empty($code) OR ! is_numeric($code)))
{
if (isset($_SERVER['SERVER_PROTOCOL'], $_SERVER['REQUEST_METHOD']) && $_SERVER['SERVER_PROTOCOL'] === 'HTTP/1.1')
{
$code = ($_SERVER['REQUEST_METHOD'] !== 'GET')
? 303 // reference: http://en.wikipedia.org/wiki/Post/Redirect/Get
: 307;
}
else
{
$code = 302;
}
}

switch ($method)
{
case 'refresh':
header('Refresh:0;url='.$uri);
break;
default:
header('Location: '.$uri, TRUE, $code);
break;
}
exit;
}
}

.htaccess

Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

更新:

使用 3 的 Codeigniter 版本

在我的配置中我现在使用

尝试过

$config['uri_protocol'] = 'REQUEST_URI';

$config['uri_protocol'] = 'QUERY_STRING';

但是现在说找不到页面?

虽然页面在那里。

"common" 也是文件夹

“仪表板”将成为 Controller

所有 Controller 首字母大写 Dashboard.php

注意:我已经尝试在 config.php 上启用查询字符串,但没有按照我想要的方式工作。

最佳答案

我必须做的第一步是解决它

在 routes.php 中

$get_route_method = 'route=';
$route[$get_route_method . 'common/dashboard'] = "common/dashboard/index";

当我在 application/config/route.php 中手动添加路由时,现在似乎工作正常

然后在 application/helper.php 中的 MY_url_helper $uri = site_url('index.php?route=' . $uri);

<?php

if ( ! function_exists('redirect'))
{
function redirect($uri = '', $method = 'auto', $code = NULL)
{
if ( ! preg_match('#^(\w+:)?//#i', $uri))
{
$uri = site_url('index.php?route=' . $uri);
}

// IIS environment likely? Use 'refresh' for better compatibility
if ($method === 'auto' && isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== FALSE)
{
$method = 'refresh';
}
elseif ($method !== 'refresh' && (empty($code) OR ! is_numeric($code)))
{
if (isset($_SERVER['SERVER_PROTOCOL'], $_SERVER['REQUEST_METHOD']) && $_SERVER['SERVER_PROTOCOL'] === 'HTTP/1.1')
{
$code = ($_SERVER['REQUEST_METHOD'] !== 'GET')
? 303 // reference: http://en.wikipedia.org/wiki/Post/Redirect/Get
: 307;
}
else
{
$code = 302;
}
}

switch ($method)
{
case 'refresh':
header('Refresh:0;url='.$uri);
break;
default:
header('Location: '.$uri, TRUE, $code);
break;
}
exit;
}
}

关于php - 使用 get 方法自定义 URL Helper 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30929820/

24 4 0
文章推荐: swift - 自定义 NSStoryboardSegue 未将 NSViewController 添加到响应链
文章推荐: html - 如何使用 CSS 或 HTML 将特定的 HTML 行和列加粗?
文章推荐: swift - 旋转 Swift 数组
文章推荐: javascript - 如何使