iteyran
iteyran

Reputation: 135

Codeigniter 2.2 Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING

I am using CodeIgniter 2.2;

a while ago i created a site with codeigniter (following the codeigniter dynamic data tutorial) and made two controllers (along with their models of course) namely, suggestions and reports. And as for the first need i made the create functions for both of these controllers. However, yesterday, i tried to add the view functions and listing the values in my database too. I added the simple view functions

$data['suggestions'] = $this->suggestions_model->get_suggestions();
$this->load->view('suggestions/view',$data);

and for reports the same

$data['reports'] = $this->reports_model->get_reports();
$this->load->view('reports/view',$data);

This works fine at my local and i can see the results for both of them. However, when i put it to the production (remote) suggestions controller works with its create and view functions but reports controller doesnt return anything except the error message below

syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /my_site/application/controllers/reports.php on line 37

and line 37 is : $data['reports'] = $this->reports_model->get_reports();

and here is the first 40+ lines of the code..

    <?php

        class reports extends CI_Controller {

    public function __construct()
    {


        parent::__construct();
        //parent::CI_Controller();
        echo "Success";


        $this->load->model('reports_model');
        $this->load->library("session");
        $this->load->helper('url');
        session_start();


echo "Başarı ile oluşturuldu";

    }

    public function index()
    {
        $data['reports'] = $this->reports_model->get_reports();
var_dump($data['reports']);
        exit;

        $data['title'] = 'Suggestions archive';

        $this->load->view(reports/view', $data);
    }

    public function view()
    {
        $data['reports'] = $this->reports_model->get_reports();

        var_dump($data['reports']);
        exit;

        $data['title'] = 'Suggestions archive';

        $this->load->view('reports/view', $data);
    }

It looks all fine, but what is the problem? And for those who ask about it, yes i load the model in constructor... Thanks in advance.

Upvotes: 0

Views: 3758

Answers (2)

Elias Van Ootegem
Elias Van Ootegem

Reputation: 76413

The last statement in your index method is missing a quote:

$this->load->view(reports/view', $data);
//               /\HERE

That should be:

$this->load->view('reports/view', $data);

ATM, PHP is treating the declaration, and statements in the view method as strings:

$data['reports'] = $this->reports_model->get_reports();

Is what you see, but PHP sees this as:

//string  CONSTANT  STRING...
'$data['   reports  '] = $this->reports_model->get_reports();'

That's why I always say:
Syntax highlighting saves lives!

Remarks:
There are some other, un-related, issues in your code: your constructor echo-es, methods containing exit statements etc... I suspect this is for debugging only. Even so: look into using Xdebug.
Without wanting to do too much self-promoting see this code-review of mine, where I explain why methods should never call exit or echo things. If you want, you can post some code of yours on CR, and I'll be happy to take a look at it

Upvotes: 1

iteyran
iteyran

Reputation: 135

it is all the lack of ' in the last line of index function... Such errors are hard to spot especially when not using a colorful editor...

Upvotes: 0

Related Questions