0

大家好,我是 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 是一个带有 hello<h1>标签的 PHP 页面。我已经用谷歌搜索并搜索过类似的问题,但我没有得到任何解决方案

基本网址是 localhost/ci/index.php

错误

无法加载请求的文件:showmessage.php

.htaccess

RewriteEngine on
RewriteCond $1 !^(index\.php|js|css|img\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
4

3 回答 3

0

是直接来自EllisLab的教程。按照步骤操作,您的表单将正常工作。

最常见的错误,

  1. 不加载form助手
  2. htaccess.设置错误,或路径错误(大写字母等)。
  3. config.php未正确设置
  4. 不将数据传递给查看($this->load->view('some_view', $data);

因此,如果存在错误消息,则您没有向我们提供错误消息,社区没有可能的帮助。

有关更多调试信息,请打开 codeigniters profiler ( $this->output->enable_profiler(TRUE);),使用 PHPs native function var_dump($variable);

确保错误报告设置E_ALLindex.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>
于 2013-06-16T11:01:14.460 回答
0

我认为您的 RewriteRule 是错误的。尝试: RewriteRule ^(.*)$ /ci/index.php/$1 [L]

于 2013-06-17T01:51:38.743 回答
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 ;
    }
于 2013-06-16T12:39:22.637 回答