大家好我是CodeIgniter框架的新手。我试图开发一个包含表单的页面。
<?php echo form_open('Site/check');?>
User Name: <?php echo form_input(array('id'=>'Username' ,'name'=>'username' ,'class="input-medium " ')); ?>
Add User:<?php echo form_submit('submit','Add User','class="btn btn-primary"');?>
<?php echo form_close();?>
<?php class Site extends CI_Controller{
function login() {
$data['records']="BHOOM!!!";
$this->load->view('login',$data);
}
function check() {
$this->load->view('showmessage');
}
}
?>
showmessage是一个PHP页面,在<h1>
标签中有一个问候语。
我已经用谷歌搜索并搜索了类似的问题,但我没有得到任何解决方案
基本网址为localhost/ci/index.php
无法加载请求的文件:showmessage.php
RewriteEngine on
RewriteCond $1 !^(index\.php|js|css|img\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
答案 0 :(得分:0)
Here是直接来自EllisLab的教程。按照步骤操作,您将使表单正常工作。
最常见的错误,
form
帮助htaccess.
设置错误,或路径错误(大写字母等)。config.php
未正确设置$this->load->view('some_view', $data);
因此,如果存在错误消息,则您没有向我们提供错误消息,但社区没有任何可能的帮助。
有关更多调试信息,请启用codeigniters profiler($this->output->enable_profiler(TRUE);
),使用PHP本机函数var_dump($variable);
。
确保E_ALL
index.php
修改强>
确保您的/config/config.php
/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = "";
使您的.htaccess
此文件位于项目的根目录中,例如。 /ci/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ci/
# Reenable after getting ssl cert
# RewriteCond %{HTTPS} off
# RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
# Removes access to the system folder by users
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
# When your application folder isn't in the system folder This snippet 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>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's can be sent to index.php, and everything works as normal.
ErrorDocument 404 /index.php
</IfModule>
答案 1 :(得分:0)
只需使用此类代码进行试用
视图
<?php
echo form_open('controllet_name/method_name');
form_input(array('id'=>'Username' ,'name'=>'username' ,'class="input-medium " '));
form_close();
?>
控制器
()
{
$name=$this->input->post('username');
echo $name ;
}
答案 2 :(得分:0)
我觉得你的RewriteRule错了。 尝试: RewriteRule ^(。*)$ / ci/index.php/$1 [L]