dzhax Posted September 6, 2011 Share Posted September 6, 2011 I am working on a widget for Social Engine 4 and Randomly get the following error Parse error: syntax error, unexpected '}' in /home/standth1/public_html/csr/application/widgets/fightsubmit/Controller.php(8) : runtime-created function on line 1Fatal error: Function name must be a string in /home/standth1/public_html/csr/application/widgets/fightsubmit/Controller.php on line 10 I was trying to change the variable "data" into something more descriptive when it started. So I did what I normally do... I put it all back to data. And I am still getting the same exact message.Controller.php: <?phpclass Widget_FightSubmitController extends Engine_Content_Widget_Abstract{ public function indexAction() { $scode = $this->_getParam('data'); $func = create_function (null, $scode ); ob_start(); $func(); $this->view->data = ob_get_contents(); ob_end_clean(); }}?> Manifest.php: <?phpreturn array( 'package' => array( 'type' => 'widget', 'name' => 'fightsubmit', 'version' => '1.0.0', 'path' => 'application/widgets/fightsubmit', 'repository' => '', 'meta' => array( 'title' => 'Fight Submit', 'description' => 'Submit fight data.', 'author' => 'garrett-innovations.com', ), 'directories' => array( 'application/widgets/fightsubmit', ), ), // Backwards compatibility 'type' => 'widget', 'name' => 'fightsubmit', 'version' => '1.0.0', 'title' => 'Fight Submit', 'description' => 'Submit fight data.', 'category' => 'Widgets', 'autoEdit' => true, 'adminForm' => array( 'elements' => array( array( 'Text', 'data', array( 'label' => 'Minimum CP Access Level:' ) ), ) ),) ?> index.tpl: <?php $currentDisplayName = Engine_Api::_()->user()->getViewer()->displayname; echo 'Welcome, ' . $currentDisplayName; $currentAuthLevel = Engine_Api::_()->user()->getViewer()->level_id; echo '<br/>Authorization Level: ' . $currentAuthLevel . '<br/><br/>'; echo 'Minimum Auth Level: '. $this->data . '<br/><br/>';?> Any help on this is much appreciated. Link to comment Share on other sites More sharing options...
Ingolme Posted September 6, 2011 Share Posted September 6, 2011 I can't see what is being put into $scode: $scode = $this->_getParam('data'); The error seems to be in there. Print it out and see what's wrong with it. Link to comment Share on other sites More sharing options...
dzhax Posted September 6, 2011 Author Share Posted September 6, 2011 $scode echos 3which is correct 3 should display on the index.tpl for the minimum auth level.is it maybe because its a number and not letters? I'm not sure exactly what is going on it is a take existing code and modify it to suite my needs type of thing. Link to comment Share on other sites More sharing options...
dzhax Posted September 6, 2011 Author Share Posted September 6, 2011 ok it has to be syntax... I cleared the field that was loading the number 3 (so its blank) and now it loads fine. Link to comment Share on other sites More sharing options...
Ingolme Posted September 6, 2011 Share Posted September 6, 2011 You're passing "3" to create_function()?That's equal to writing this: function f() {3} $scode should be the code that runs in the function. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 6, 2011 Share Posted September 6, 2011 If $scode is "3" then running create function tells it to do this: function temp(null){ 3} Obviously, that's not valid PHP syntax, which is why you get the parse error. At a minimum the 3 should have a semicolon after it, but even so that's not going to create a useful function. This doesn't do anything: function temp(null){ 3;} Link to comment Share on other sites More sharing options...
dzhax Posted September 6, 2011 Author Share Posted September 6, 2011 ok its working now i ripped out all the ob connection garbage and just set $this->view->data = $scode;It loads fine now. Not sure what the ob connection thing does but it must need a specific syntax to work properly.Ingolme thanks for the idea of echoing $scode. at first i would navigate directly to controller.php and get 3 but when i naviagted to the index the 3 still showed on the page thats when I made the above changes. <?phpclass Widget_FightSubmitController extends Engine_Content_Widget_Abstract{ public function indexAction() { $scode = $this->_getParam('data'); $this->view->data = $scode; }}?> Link to comment Share on other sites More sharing options...
justsomeguy Posted September 6, 2011 Share Posted September 6, 2011 The original code was assuming that the data contained valid PHP code that needed to be executed, and it doesn't look like your data is PHP code. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.