提交表单不在CodeIgniter 3.0.3中工作

时间:2015-11-18 06:16:28

标签: codeigniter-3

我的任务是在CodeIgniter中编写一个简单的程序。我正在使用Symfony 2进行编码,因为Symfony 2通过CodeIgniter缺少的命令行提供了一个很好的CRUD,所以我可以轻松创建测试表单。所以我必须每次都手动创建我正在创建用于测试的表单。但是在chrome中,当提交按钮被点击时,表单什么都不做,并且在Mozilla中,以及类似

的错误消息
  

地址未被理解

     

Firefox不知道如何打开此地址,因为以下协议之一(localhost)与任何程序无关或在此上下文中不允许。

     

您可能需要安装其他软件才能打开此地址。

控制器

public function add_makers()
{
    $this->load->helper('form');
    $this->load->library('form_validation');

    $data['title'] = 'Add New Car Maker';
    $data['main_content'] = 'makers/add_makers';

    $this->form_validation->set_rules('name', 'Name', 'required');
    $this->form_validation->set_rules('description', 'Description', 'required');
    $this->form_validation->set_rules('nation_id', 'Nation_Id', 'required');

    if ($this->form_validation->run() == FALSE) {
        $this->load->view('templates/template', $data);
        //echo "ok";
    } 
    else 
    {
        $this->makers_model->new_makers();
        //$this->load->view('makers/success');
    }

表格

<h1><?php echo $title; ?></h1>


<?php echo form_open('makers/add_makers'); ?>

<label for="name">Name</label>
<?php
$data = array(
    'type' => 'text',
    'name' => 'name'    
);
echo form_input($data);
?>

<label for="description">Description</label>
<?php
$data = array(
    'type' => 'text',
    'name' => 'description'
);
echo form_textarea($data);
?>

<label for="nation_id">Country</label>

<?php 
$data = array(
    'name' => 'nation_id',
    'type' => 'text'
);
echo form_input($data);
?>
  

模板

<?php 
 /*
 *Load header contents, and footer
 *
 */
 $this->load->view('templates/header');
 $this->load->view($main_content);
 $this->load->view('templates/footer');

我在Windows中安装的vagrant(ubuntu trusty)中运行开发,我在Symfony2或Laravel项目中使用它没有问题。运行时都启用了<.p>

sudo a2enmod rewrite

在Apache内部,我以这种方式配置虚拟主机

 <VirtualHost *:80>
  #ServerAdmin admin@yourdomain.com
  DocumentRoot /var/www/CodeIgniter-3.0.3/
  #ServerName yourdomain.com
  #ServerAlias www.yourdomain.com
 <Directory /var/www/CodeIgniter-3.0.3/>
  Options Indexes FollowSymLinks MultiViews
  AllowOverride All
  Require all granted
 </Directory>
 #ErrorLog /var/www/CodeIgniter-3.0.3/logs/httpd/yourdomain.com-error_log
 #CustomLog /var/log/httpd/yourdomain.com-access_log common
 </VirtualHost>

在框中,我在

中预先配置了.ht访问权限
  Project
  /Application
   .htaccess


   <IfModule authz_core_module>
     Require all denied
   </IfModule>
   <IfModule !authz_core_module>
     Deny from all
   </IfModule>

最后路线

 $route['makers/add_makers'] = 'makers/add_makers';
//$route['news/(:any)'] = 'news/view/$1';
//$route['news'] = 'news';
//$route['(:any)'] = 'pages/view/$1';
$route['default_controller'] = 'services/index';

我已经在谷歌搜索了这个并找不到解决方案。我的文件中是否缺少某些东西?

2 个答案:

答案 0 :(得分:0)

您可以查看CI生成的html代码,并尝试在地址栏中输入完整的帖子URL,可能会发生一些事情,然后检查apache和php的日志文件,这可能有助于解决您的问题< / p>

答案 1 :(得分:0)

找到解决方案

我修改.htaccess并将其移到应用程序文件夹之外并放入根文件夹

RewriteEngine On
RewriteCond $1 !^(index\.php|styles|scripts|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1

#<IfModule mod_gzip.c>
#    mod_gzip_on       Yes
#    mod_gzip_dechunk  Yes
#    mod_gzip_item_include file      \.(html?|txt|css|js|php|pl)$
#    mod_gzip_item_include handler   ^cgi-script$
#    mod_gzip_item_include mime      ^text/.*
#    mod_gzip_item_include mime      ^application/x-javascript.*
#    mod_gzip_item_exclude mime      ^image/.*
#    mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
#</IfModule>  

重构apache 2.4

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    #ServerAdmin webmaster@localhost
    DocumentRoot /var/www/Codeigniter
    AcceptPathInfo On
    <Directory /var/www/Codeigniter>
      AllowOverride None
      Require all granted
    </Directory>

然后在config / config.php里面

 $config['base_url'] = '';//note the auto guessing.If I set this to localhost:8090/something, this form will not submitting


 $config['index_page'] = '';

我尝试了谷歌和其他建议中提供的许多解决方案,但都没有效果。只需花费很多时间尝试可能的解决方案就可以了。 我在开发中使用Vagrant和Ubuntu可靠。以前,我使用Wamp进行此项目,我提交表单没有问题。