Yii Framework Forum: Newbie question - syntax error in Using Yii Events chapter? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Newbie question - syntax error in Using Yii Events chapter?

#1 User is offline   newbie74 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 04-March 12

Posted 04 March 2012 - 05:00 PM

Hi,
I was just trying code on the book and I got a syntax error from the following code:

Yii::app()->onBeginRequest = function($event)
{
	return ob_start("ob_gzhandler");
}


Could you please point me towards the solution? The full code is reproduced below.
<?php

// change the following paths if necessary
$yii=dirname(__FILE__).'/../yii/framework/yii.php';
$config=dirname(__FILE__).'/protected/config/main.php';

// remove the following lines when in production mode
defined('YII_DEBUG') or define('YII_DEBUG',true);
// specify how many levels of call stack should be shown in each log message
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);

require_once($yii);
$app = Yii::createWebApplication($config);

Yii::app()->onBeginRequest = function($event)
{
	return ob_start("ob_gzhandler");
}

Yii::app()->onEndRequest = function($event)
{
	return ob__end_flush();
}

$app->run();


My system:
PHP Version 5.3.6-13ubuntu3.6
Yii 1.1.9
0

#2 User is offline   artificial 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 96
  • Joined: 11-December 10
  • Location:Sydney, Australia

Posted 04 March 2012 - 11:57 PM

$foo = function bar($param) { /* .. */ }


You can't do that. It should give an error. Can you link me to where you were instructed to do that?

And are you sure you weren't instructed to use create_function() instead?
Alex Berriman
www.fishvision.com
0

#3 User is offline   StasuSS 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 60
  • Joined: 20-February 12
  • Location:Kaluga, Russia

Posted 05 March 2012 - 12:16 AM

this is attachment of event handler. it is correct.

Yii::app()->onBeginRequest = function($event){
    return ob_start("ob_gzhandler");
};// <<< semicolon


may be you are missing ; at the end? after curly brace ;)

and there are two underscores in second event handler
Things are very seldom what they seem. In my experience, they’re usually a damn sight worse. (Inquisitor Titus Drake)
1

#4 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,359
  • Joined: 12-October 09
  • Location:Croatia

Posted 05 March 2012 - 03:57 AM

NOTE: moved to proper section (General Discussion for Yii 1.1.x instead of Feature Requests)
Find more about me.... btw. Do you know your WAN IP?
0

#5 User is offline   newbie74 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 04-March 12

Posted 05 March 2012 - 03:22 PM

Thanks everybody! The code works with the added semicolons.

One problem - Eclipse 3.7.0 with PDT 2.2.1 still underlines the function declaration and lists it as an error.

Could you please point me to an Yii compliant IDE?

mdomba, sorry for the wrong placement.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users