【问题标题】:parse error in controller file解析控制器文件中的错误
【发布时间】:2014-01-14 17:35:21
【问题描述】:

我创建了 user.php 的控制器名称,我在本地主机上测试了完整的项目,它工作正常,但是当我在网站上在线上传时它显示错误,我提交表单,然后表单加载名为 user.php 的控制器并在第一个错误我检查了它称为解析错误的行,但您仍然会建议。

<?php 

class User extends CI_Controller {

                function __construct()
                {
                parent::__construct();
                $this->load->helper('form');
                $this->load->helper('url');
                }

public function create_user()
            {
            // field name, error message, validation rules
            $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
            $this->form_validation->set_rules('city', 'City', 'trim|required');     
            if($this->form_validation->run() == FALSE)
            {
            $this->load->view('ar_signup');
            }
            else
            {           
            $this->load->model('Users_model');
            if($this->input->post("language")=="ar")
            {
            $this->load->view('ar_thanks');
            }
            else
            {
            $this->load->view('en_thanks');
            }
            if($query = $this->Users_model->create_member())
            {
            $this->load->view('ar_thanks');         
            }
                }               
                        }

    }   

【问题讨论】:

  • 指定详细错误
  • 这个问题似乎是题外话,因为它是关于
  • @Formal 你需要提供错误发生的详细信息,Parse error 是错误的类型但你没有指定错误是什么。
  • Adarsh 我只是在这个文件中得到错误解析错误:语法错误,意外 $end in,这就是为什么我共享文件的完整代码,因为我结束了 php 和所有大括号,但仍然显示错误。
  • **解析错误:语法错误,意外 $end in ** 这个错误来自 web 我提交表单。

标签: php codeigniter


【解决方案1】:

请格式化您的代码并使用 IDE。你不会有这些错误。您的格式化代码:

<?php
class User extends CI_Controller {

    function __construct()
    {
        parent::__construct();
        $this->load->helper('form');
        $this->load->helper('url');
    }

    public function create_user()
    {
        // field name, error message, validation rules
        $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
        $this->form_validation->set_rules('city', 'City', 'trim|required');
        if($this->form_validation->run() == FALSE) {
            $this->load->view('ar_signup');
        } else {
            $this->load->model('Users_model');
            if($this->input->post("language")=="ar") {
                $this->load->view('ar_thanks');
            } else {
                $this->load->view('en_thanks');
            }
            if($query = $this->Users_model->create_member()) {
                $this->load->view('ar_thanks');
            }
        }
    }
}

【讨论】:

  • 正如你提到的代码,我使用相同但仍然相同的错误,我接收解析错误:语法错误,/home/gifto/public_html/landingpage/application/controllers/user.php 中的意外 T_STRING 在线1,但是当我为在线服务器上传文件时出现此错误,我在本地服务器上运行此文件它工作正常。
猜你喜欢
  • 2017-05-08
  • 1970-01-01
  • 2015-12-12
  • 1970-01-01
  • 2023-04-09
  • 1970-01-01
  • 1970-01-01
  • 2015-11-10
  • 1970-01-01
相关资源
最近更新 更多