i'm new in codeigniter programming and i'm having some problems with a link to another controller.

i've got an Homepage (home.php) from wich i've to go to another page.

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 (controller to the other page)

<?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);
    }
}

If i try my link i have the error below:

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:

Now if i try to change the class name in my Singoff.php file i have a 404 error.

Please help me.....i'm going crazy!!

share|improve this question
    
Single-offerta is not a valid class name. programmers.stackexchange.com/questions/149303/… – Shaiful Islam May 28 '16 at 17:34
    
It's clear you need to carefully study the CodeIgniter documentation from start to finish, and do not forget to follow the enclosed tutorial. – Sparky May 31 '16 at 14:39

Just read the error. It is line 4 and invalid character - - hyphen. Dashes or hyphens are NOT allowed in class names. Class name should follow file name, meaning those two need to be exact the same. Warm advice would be to read full CI documentation. Pay attention on file naming and class and method naming. Also, it could be very helpful to read PHP OOP basics.

A valid class name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thus: ^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$.

In your example file should be Single_offerta.php and line 4 should be accordingly

class Single_offerta extends CI_Controller {

If you want to access your URL with example.com/single-offerta most efficient way would be to translate uri dashes in APPPATH.'config/routes.php' file setting it to TRUE:

$route['translate_uri_dashes'] = TRUE;
share|improve this answer
    
I already tried this :( but nothing – Sinapsi Labs May 28 '16 at 18:52
    
How do you mean? You shouldn't have the same error. – Tpojka May 28 '16 at 19:55
    
I tryed changing class name in Single_offerta and changing $route['translate_uri_dashes'] to TRUE...nothing happens – Sinapsi Labs May 28 '16 at 20:05
    
Try one at a time. First change file and class name as I proposed, with $route['translate_uri_dashes'] = FALSE and go to example.com/index.php/single_offerta and describe here what happened. – Tpojka May 28 '16 at 20:15
    
it doesn't work :( – Sinapsi Labs May 30 '16 at 21:31

rename your class name Single-offerta to something else. avoid using - in your class name

share|improve this answer
    
If i try to change the class name i have a 404 error – Sinapsi Labs May 28 '16 at 18:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.