0

我正在从事 Code Igniter 项目。

我在视图文件夹中有一个 php 文件C:\xampp\htdocs\MSPN\APPLICATION\views

表格是这样写的:

<form action="<?php echo base_url() .'homeSignUp/main'; ?>" method="post" >

在浏览器中,文件位于localhost/mspn/index.php/signup/main

在 config.php 我有:

$config['base_url'] = 'localhost/mspn/';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';

'action' 形式用于指向具有方法homeSignUp.php的文件夹中的。controllermain

但是当我尝试运行它时,submit按钮指向localhost/mspn/homeSignUp/main. 它说:找不到对象!

我一直在尝试更改action属性中的 url,但它一直给我这个错误。我错过了什么?谢谢。

4

2 回答 2

0

首先,将index_page配置更改为:

$config['index_page'] = 'index.php';

然后site_url()像这样使用:

<form action="<?php echo site_url('homeSignUp/main'); ?>" method="post" >

注意:由于您似乎正在使用特定的route,您可能想要使用signup/main而不是homeSignUp/main.

因为站点 url 将包括两者base_url以及index_url如果有的话。所以你不需要单独提及index.php

于 2013-06-22T10:22:15.803 回答
0

首先index.php使用从您的网址中删除,.htaccess然后您的网址应如下所示

localhost/mspn/signup/main

//Remove index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# Removes access to the system folder by users.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

# Prevents user access to the application folder
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

config.php应该有这个配置

$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
$config['url_suffix'] = '';

那么你的表格应该是这样的

echo form_open(base_url()."homeSignUp/main");

希望有意义

于 2013-06-22T11:11:41.347 回答