CodeIgniter / MAMP Pro:将URI参数映射到默认控制器

编程入门 行业动态 更新时间:2024-10-22 10:39:47
本文介绍了CodeIgniter / MAMP Pro:将URI参数映射到默认控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个问题让我的重写规则工作。这是我得到的:

mysite:8888 / - 工作,但抛出错误的参数错误(预期) mysite:8888 / myvar - 404错误 mysite:8888 / index.php / test / index / myvar - 在页面上工作并显示myvar(预期) mysite:8888 / test / index / myvar - 404错误 mysite:8888 / test / myvar - 404错误

我的routes.php档案只包含:

$ route ['default_controller'] =test;

config.php:

$ config ['base_url'] ='http:// mysite:8888 /'; $ config ['index_page'] =''; $ config ['uri_protocol'] ='REQUEST_URI'; $ config ['url_suffix'] ='';

test.php(控制器):

public function index($ myVar){ $ data ['myVar'] = $ myVar; $ this-> load-> view('test',$ myVar); }

test.php(view):

< h1>测试页< / h1> < p>这是您的变量:<?= $ myVar?>。< / p>

这里是我的.htaccess文件(甚至不确定我需要一个):

RewriteEngine on RewriteCond%{REQUEST_FILENAME}!-f RewriteCond%{REQUEST_FILENAME}!-d RewriteRule ^ (。*)$ index.php / $ 1 [L]

目标是拥有此URL: mysite:8888 / hello

生成这个:这是你的变量:hello。

解决方案

好吧,我想出来了。原来,我有一切正确设置,但我的.htaccess文件的文件头告诉我的Mac,它是一个富文本文档。我从我的Web服务器下拉一个工作的.htaccess文件,粘贴重写规则到它,和宾果!它开始工作。感谢大家的建议。

I'm having an issue getting my rewrite rules to work. Here's what I get:

mysite:8888/ - works, but throws missing argument errors (expected) mysite:8888/myvar - 404 error mysite:8888/index.php/test/index/myvar - works and displays myvar on page (expected) mysite:8888/test/index/myvar - 404 error mysite:8888/test/myvar - 404 error

My routes.php file only contains:

$route['default_controller'] = "test";

config.php:

$config['base_url'] = 'mysite:8888/'; $config['index_page'] = ''; $config['uri_protocol'] = 'REQUEST_URI'; $config['url_suffix'] = '';

test.php (controller):

public function index($myVar){ $data['myVar'] = $myVar; $this->load->view('test', $myVar); }

test.php (view):

<h1>Test page</h1> <p>Here's your variable: <?=$myVar?>.</p>

and here's my .htaccess file (not even sure I need one):

RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L]

The goal is to have this URL: mysite:8888/hello

Generate this: "Here's your variable: hello."

What am I missing?

解决方案

Well, I figured it out. It turns out I had everything setup correctly, but the file headers on my .htaccess file were telling my Mac that it was a rich-text document. I pulled down a working .htaccess file from my web server, pasted the rewrite rules into it, and bingo! It started working. Thanks for the suggestion, everyone.

更多推荐

CodeIgniter / MAMP Pro:将URI参数映射到默认控制器

本文发布于:2023-11-01 02:17:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1547963.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控制器   参数   MAMP   CodeIgniter   URI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!