【问题标题】:Stuck on parse error in PHP卡在 PHP 中的解析错误
【发布时间】:2015-03-17 13:42:21
【问题描述】:

以下是我在解析代码时收到的错误。请,请帮助我解决它。连默认的控制器页面都没有渲染。

( ! ) Parse error: syntax error, unexpected '(', expecting T_STRING or T_VARIABLE or '{' or '$' in C:\wamp\www\Test\application\models\site_mod.php o`enter code here`n line 18
Call Stack
#   Time    Memory  Function    Location
1   0.0004  385288  {main}( )   ..\index.php:0
2   0.0012  458288  require_once( 'C:\wamp\www\Test\system\core\CodeIgniter.php' )  ..\index.php:202
3   0.0137  1362696 Site->__construct( )    ..\CodeIgniter.php:308
4   0.0137  1362696 CI_Controller->__construct( )   ..\site.php:7
5   0.0155  1626240 CI_Loader->initialize( )    ..\Controller.php:51
6   0.0156  1627392 CI_Loader->_ci_autoloader( )    ..\Loader.php:152
7   0.0261  2834120 CI_Loader->model( ) ..\Loader.php:1185
8   0.0261  2834368 CI_Loader->model( ) ..\Loader.php:237

site.php -- 这是我的控制器--

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Site extends CI_Controller {

     public function __construct()
         {
           parent::__construct();
         }
    public function index()
        {
           $this->load->view('option_view');
        }
    function create()
        {
           $this->site_mod->add_record($data);
           $this->index();
        }
}

option_view.php -- 这是我的观点 ---

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Welcome to CodeIgniter</title>

    <style type="text/css">

    ::selection{ background-color: #E13300; color: white; }
    ::moz-selection{ background-color: #E13300; color: white; }
    ::webkit-selection{ background-color: #E13300; color: white; }

    body {
        background-color: #fff;
        margin: 40px;
        font: 13px/20px normal Helvetica, Arial, sans-serif;
        color: #4F5155;
    }

    a {
        color: #003399;
        background-color: transparent;
        font-weight: normal;
    }

    h1 {
        color: #444;
        background-color: transparent;
        border-bottom: 1px solid #D0D0D0;
        font-size: 19px;
        font-weight: normal;
        margin: 0 0 14px 0;
        padding: 14px 15px 10px 15px;
    }

    code {
        font-family: Consolas, Monaco, Courier New, Courier, monospace;
        font-size: 12px;
        background-color: #f9f9f9;
        border: 1px solid #D0D0D0;
        color: #002166;
        display: block;
        margin: 14px 0 14px 0;
        padding: 12px 10px 12px 10px;
    }

    #body{
        margin: 0 15px 0 15px;
    }

    p.footer{
        text-align: right;
        font-size: 11px;
        border-top: 1px solid #D0D0D0;
        line-height: 32px;
        padding: 0 10px 0 10px;
        margin: 20px 0 0 0;
    }

    #container{
        margin: 10px;
        border: 1px solid #D0D0D0;
        -webkit-box-shadow: 0 0 8px #D0D0D0;
    }
    </style>
</head>
<body>

<div id="container">
    <h1>Create</h1>
    <?php echo form_open('site/create'); ?>

    <p><label for="title">Title</label>:
    <input type="text" name="title" id="" value="" /></p>

    <p><lable for="content">Content</lable>:
    <input type="text" name="content" id="" value="" /></p>

    <p><input type="submit" value="Create"/></p>



    <?php echo form_close(); ?>


</div>

</body>
</html>

site_mod.php -- 这是我的模型---

<?php

class Site_mod extends CI_Model {

  function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }

    function get_records(){
        $query=$this->db->get('test');
        return $query->result();
    }

    function add_record($data)
    {
        $this->db->insert->('test',$data);
        return;
    }

    function update_record($data){
        $this->db->where('id',14);
        $this->db->update('test',$data);  
    }

    function delete_row(){
     $this->db->where('id',$this->uri->segment(3));
     $this->db->delete('test');
    }
}

【问题讨论】:

  • 第 18 行被认为是错误的地方在哪里?

标签: php codeigniter


【解决方案1】:

我在 site_mod.php 中数了 18 行,就在那里

$this->db->insert->('test',$data);

在“插入”之后有一个额外的 ->。

【讨论】:

  • 优秀的马克......谢谢我无法从我的最终识别出这样一个愚蠢的错误......非常感谢马克并感谢所有其他打算提供帮助的人......跨度>
  • FILE); 设置 Web 根目录和服务器根目录$docRoot = $_SERVER['DOCUMENT_ROOT']; $webRoot = str_replace(array($docRoot, 'library/config.php'), '', $thisFile); $srvRoot = str_replace('library/config.php', '', $thisFile);定义('WEB_ROOT',$webRoot);定义('SRV_ROOT',$srvRoot); ?> 在上面的代码中,web_root 导致了路径错误,链接被转发了 2 次,像这样“localhost/Pcart/admin/Pcart/admin/category”任何人都可以帮助它进行错误路径配置
猜你喜欢
  • 1970-01-01
  • 2011-04-04
  • 2014-07-18
  • 1970-01-01
  • 1970-01-01
  • 2014-09-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多