0

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.

8
  • Can you show the liine 36? maybe ther is a ; missing? Commented Sep 5, 2014 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 Commented Sep 5, 2014 at 11:01
  • 1
    @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? Commented Sep 5, 2014 at 11:13
  • 1
    @iteyran: That's quite alright, I wasn't being too kind either. Anyway, I've posted an answer, for completeness sake Commented Sep 5, 2014 at 11:51
  • 1
    @iteyran: Added some remarks to my answer, well worth checking out. Xdebug is something that'll improve your skills dramatically if you learn how to use it. I've also added some more general notes on, what I believe, are vital OOP concepts, and suggested a StackExchange site you might want to look into Commented Sep 5, 2014 at 11:58

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.