Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

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.

share|improve this question
    
Can you show the liine 36? maybe ther is a ; missing? – Jens Sep 5 '14 at 10:59
    
This question appears to be off-topic, as it's about a "simple typographical error". Debugging is your job. If you want to write code, you'll have to accept the simple fact that debugging is part of your job – Elias Van Ootegem Sep 5 '14 at 11:01
    
line 36 is "{" the opening curly paranthesis for function view()... 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); } – iteyran Sep 5 '14 at 11:10
    
@EliasVanOotegem of course i know it is my job to debug... but there is something nonsense, why it would work with other controller and not this one... obviously there is something wrong, either because of my mistake or maybe by no mistake.. if this is "simple typographical error" then be a good guy and tell me where is the typo in line 37? – iteyran Sep 5 '14 at 11:13
    
@iteyran: I put that simple typographical error bit in quotes, because that's what it is: a quote. Either way, you're not showing all of the code. Saying line 36 is { doesn't help: show the entire method definition, or even the entire class. If you do that, I'm pretty sure the error will be easy to spot – Elias Van Ootegem Sep 5 '14 at 11:36
up vote 1 down vote accepted

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

share|improve this answer
    
I will take a look at that.. thank you. – iteyran Sep 5 '14 at 12:18

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...

share|improve this answer

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.