Codeigniter - 解析错误:语法错误,意外' - ',期待'{'

时间:2016-05-28 14:38:17

标签: codeigniter codeigniter-3

我是codeigniter编程的新手,我在链接到另一个控制器方面遇到了一些问题。

我有一个主页(home.php),我将去另一页。

home.php

<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
<!-- This is the default home page -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Animania Manager</title>
    <link rel="stylesheet" href="application/styles/foundation.css">
    <link rel="stylesheet" href="application/styles/app.css">
    <link rel="stylesheet" href="https://cdn.datatables.net/1.10.11/css/jquery.dataTables.min.css" />
    <link rel="stylesheet" href="application/styles/reset.css"> <!-- CSS reset -->
    <link rel="stylesheet" href="application/styles/style.css"> <!-- Gem style -->
    <script src="application/js/modernizr.js"></script> <!-- Modernizr -->
    <script src="http://code.jquery.com/jquery-1.12.0.min.js"></script>
    <!--script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script-->
    <script src="https://cdn.datatables.net/1.10.11/js/jquery.dataTables.min.js"></script>
    <script> 
        $(document).ready(function() {
        $('#offerte').DataTable();
        } );

        $(document).ready(function() {
        $('#curriculum').DataTable();
        } );
    </script>
    <script>        
        $(document).ready(function() {
        // Setup - add a text input to each footer cell
        $('#offerte tfoot th').each( function () {
            var title = $(this).text();
            $(this).html( '<input type="text" placeholder="Cerca '+title+'" /> ');
        } );

        // DataTable
        var table = $('#offerte').DataTable();

        // Apply the search
        table.columns().every( function () {
            var that = this;

            $( 'input', this.footer() ).on( 'keyup change', function () {
                if ( that.search() !== this.value ) {
                    that
                        .search( this.value )
                        .draw();
                }
            } );
        } );
    } );

    $(document).ready(function() {
        // Setup - add a text input to each footer cell
        $('#curriculum tfoot th').each( function () {
            var title = $(this).text();
            $(this).html( '<input type="text" placeholder="Cerca '+title+'" /> ');
        } );

        // DataTable
        var table = $('#curriculum').DataTable();

        // Apply the search
        table.columns().every( function () {
            var that = this;

            $( 'input', this.footer() ).on( 'keyup change', function () {
                if ( that.search() !== this.value ) {
                    that
                        .search( this.value )
                        .draw();
                }
            } );
        } );
    } );
    </script>

</head>
<body>
    <div class="container row">
        <header class="testata" role="banner">
            <nav class="menu">
                <ul>
                    <li>Inserimento offerta</li>
                    <li>Inserimento CV</li>
                    <li></li>
                </ul>   
            </nav>
            <nav class="main-nav">
                <ul>
                    <!-- inser more links here -->
                    <li><a class="cd-signin" href="#0">Login</a></li>
                    <li><a class="cd-signup" href="#0">Registrazione</a></li>
                </ul>
            </nav>

        </header>
    </div>  


    <div class="cd-user-modal"> <!-- this is the entire modal form, including the background -->
        <div class="cd-user-modal-container"> <!-- this is the container wrapper -->
            <ul class="cd-switcher">
                <li><a href="#0">Login</a></li>
                <li><a href="#0">Nuovo account</a></li>
            </ul>

            <div id="cd-login" action="validation.php" method=GET> <!-- log in form -->
                <form class="cd-form">
                    <p class="fieldset">
                        <label class="image-replace cd-email" for="signin-email">E-mail</label>
                        <input class="full-width has-padding has-border" id="signin-email" type="email" placeholder="E-mail" name="email">
                        <span class="cd-error-message">Errore</span>
                    </p>

                    <p class="fieldset">
                        <label class="image-replace cd-password" for="signin-password">Password</label>
                        <input class="full-width has-padding has-border" id="signin-password" type="text"  placeholder="Password" name="password">
                        <a href="#0" class="hide-password">Nascondi</a>
                        <span class="cd-error-message">Errore!</span>
                    </p>

                    <p class="fieldset">
                        <input type="checkbox" id="remember-me" checked>
                        <label for="remember-me">Ricordami</label>
                    </p>

                    <p class="fieldset">
                        <input class="full-width" type="submit" value="Login">
                    </p>
                </form>

                <p class="cd-form-bottom-message"><a href="#0">Hai dimenticato la password?</a></p>
                <!-- <a href="#0" class="cd-close-form">Close</a> -->
            </div> <!-- cd-login -->

            <div id="cd-signup"> <!-- sign up form -->
                <form class="cd-form">
                    <p class="fieldset">
                        <label class="image-replace cd-username" for="signup-username">Username</label>
                        <input class="full-width has-padding has-border" id="signup-username" type="text" placeholder="Username">
                        <span class="cd-error-message">Errore!</span>
                    </p>

                    <p class="fieldset">
                        <label class="image-replace cd-email" for="signup-email">E-mail</label>
                        <input class="full-width has-padding has-border" id="signup-email" type="email" placeholder="E-mail">
                        <span class="cd-error-message">Errore!</span>
                    </p>

                    <p class="fieldset">
                        <label class="image-replace cd-password" for="signup-password">Password</label>
                        <input class="full-width has-padding has-border" id="signup-password" type="text"  placeholder="Password">
                        <a href="#0" class="hide-password">Nascondi</a>
                        <span class="cd-error-message">Errore!</span>
                    </p>

                    <p class="fieldset">
                        <input type="checkbox" id="accept-terms">
                        <label for="accept-terms">Accetto i <a href="#0">Termini</a></label>
                    </p>

                    <p class="fieldset">
                        <input class="full-width has-padding" type="submit" value="Crea account">
                    </p>
                </form>

                <!-- <a href="#0" class="cd-close-form">Close</a> -->
            </div> <!-- cd-signup -->

            <div id="cd-reset-password"> <!-- reset password form -->
                <p class="cd-form-message">Hai perso la tua password? Inserisci il tuo indirizzo email. Riceverai un link per la creazione di una nuova password!</p>

                <form class="cd-form">
                    <p class="fieldset">
                        <label class="image-replace cd-email" for="reset-email">E-mail</label>
                        <input class="full-width has-padding has-border" id="reset-email" type="email" placeholder="E-mail">
                        <span class="cd-error-message">Errore!</span>
                    </p>

                    <p class="fieldset">
                        <input class="full-width has-padding" type="submit" value="Reset password">
                    </p>
                </form>

                <p class="cd-form-bottom-message"><a href="#0">Torna al log-in</a></p>
            </div> <!-- cd-reset-password -->
            <a href="#0" class="cd-close-form">Chiudi</a>
        </div> <!-- cd-user-modal-container -->
    </div> <!-- cd-user-modal -->
            <?php
            if ($offers !== FALSE) {
            print('<div>
    <table class="display" id="offerte" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>Titolo</th>
                <th>Descrizione</th>
                <th>Candidati</th>
            </tr>
        </thead>
        <tfoot>
            <tr>
                <th>Titolo</th>
                <th>Descrizione</th>
                <th>Candidati</th>
            </tr>
        </tfoot><tbody>');
            //for($i = 0; $i < count($offers); $i++){   
                foreach ($offers as $offer){
                    //echo base_url();
                    //$url=base_url('single-offerta')."?idannunci=".$offer->getId();

                    print("<tr>");
                    print("<td>".$offer->getTitolo()."</td>");
                    print("<td>".$offer->getDescrizione()."</td>");
                    //print('<td><a href="'.site_url('Singoff2').'">'.$offer->getPartecipanti().'</a></td>');
                    print('<td>'.anchor('Singoff2', 'Link Text').'</td>');
                    print("</tr>");
                }
                print("</tbody></table></div>");
            }
            else
            {
                echo 'nessuna offerta';
            } ?>

            <!--script src="js/vendor/jquery.js"></script-->
            <script src="application/js/vendor/what-input.js"></script>
            <script src="application/js/vendor/foundation.js"></script>
            <script src="application/js/app.js"></script>
            <script src="application/js/main.js"></script> <!-- Gem jQuery -->
    </div>
</body>
</html>

Singoff2.php(控制器到另一页)

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

class Single-offerta extends CI_Controller {

    public function index()
    {
        $this->load->library("SingOffFactory");
        //Create a data array so we can pass information to the view
        $data = array(
            "dettagli" => $this->singofffactory->getDettagli()
        );
        //Load the view and pass the data to it
        $this->load->view("Singoff2", $data);
    }
}

如果我尝试使用我的链接,则会出现以下错误:

Parse error: syntax error, unexpected '-', expecting '{' in D:\inetpub\webs\animaniait\manager\application\controllers\Singoff2.php on line 4
A PHP Error was encountered

Severity: Parsing Error

Message: syntax error, unexpected '-', expecting '{'

Filename: controllers/Singoff2.php

Line Number: 4

Backtrace:

现在,如果我尝试更改Singoff.php文件中的类名,则会出现404错误。

请帮帮我.....我疯了!!

2 个答案:

答案 0 :(得分:2)

只需阅读错误。它是第4行和无效字符- - 连字符。类名中不允许使用破折号或连字符。 类名应遵循文件名,这意味着两者必须完全相同。 热烈的建议是阅读完整的CI文档。请注意file namingclass and method naming。此外,阅读PHP OOP basics可能会非常有帮助。

  

有效的班级名称以字母或下划线开头,后跟任意数量的字母,数字或下划线。作为正则表达式,它将表示为:^ [a-zA-Z_ \ x7f- \ xff] [a-zA-Z0-9_ \ x7f- \ xff] * $。

在您的示例文件中应该是Single_offerta.php,第4行应该是

class Single_offerta extends CI_Controller {

如果您希望使用example.com/single-offerta访问您的网址,最有效的方法是在APPPATH.'config/routes.php' file中将uri破折号翻译为TRUE

$route['translate_uri_dashes'] = TRUE;

答案 1 :(得分:0)

将您的班级名称Single-offerta重命名为其他名称。避免在班级名称中使用-