Stuck On Reading The Database From Yiiframework Tutorial

Hello,

I’m somewhat new to Yiiframework and not even sure how to enter a proper topic title. sorry about that.

Anyways, I did a tour of the yiiframework screencast and everything worked including reading and writing to the database. The last part of the tutorial was to display parts of the database content and thats where i got stuck.

Error message received:

Parse error: syntax error, unexpected ‘->’ (T_OBJECT_OPERATOR) in G:\xampp\htdocs\yiitestdrive\protected\controllers\GreetingController.php on line [color="#FF0000"]11[/color]

The line highlighted in bold/red is line [color="#FF0000"]11[/color]

[color="#FF0000"]$this->render(‘index’, array(‘content’=>$this->message));[/color]




<?php


class GreetingController extends Controller

{	

	public $message = '';

	public function actionIndex()

	{			

		$message = User::model()->findByPk(5);

		$this->message = $message->content;	

		

		$this->render('index', array('content'=>$this->message));

	}



Any thoughts on what I could have done?

Hi actually this is not a matter in yii…it’s a syntax error…


$this->message = $message->content

is the matter in here…jst change it to


$msg = $message->content

and see… also in


$this->render('index', array('content'=>$msg));

find anything usefull…jst click reputation… :)

I can’t see any syntax errors in that, other than the missing closing brace at the end of the class. It’s slightly confusing using the same name to hold completely different objects in an instance and local variable, but not syntactically wrong as far as I know. Is the posted code an exact copy of the class?

As CPzee posted, there’s no real need to store the message as an instance variable if you’re going to pass it through to the view in the render call, so making a local variable (as suggested) makes more sense.

Hello,

After the posting the message I when back to review the screencast and the script. It had something to do with the database. I used an existing database rather then re-create a new database to save time and for all intensive purpose I was able to complete majority of the tutorial with the database. I was able to read/write to the database but for some reason the changes to the script (code below) wouldn’t work. I figured database is a database and couldn’t see a reason why it wouldn’t work.

Anyways, i when back and recreated the database as per the tutorial and it seem to working. I’m new to Yii so I couldn’t really pin point the challenge maybe the table i was working with had multiple col. vs. the tutorial only had 2 cols(id, content).