syntax error, unexpected '(', expecting ',' or ';'
Permalinksyntax error, unexpected '(', expecting ',' or ';'
But I can't find anything wrong with the code, it's a one-to-one copy from the systems blocks.
use UserInfo; // Also tried Concrete\Core\User\UserInfo use Config; // Also tried Concrete\Core\Config ... public $site_name = Config::get('concrete.site'); or this: $adminUserInfo=UserInfo::getByID(USER_SUPER_ID); $this->email_to = $adminUserInfo->getUserEmail(); or this: $u = new User(); $ui = UserInfo::getByID($u->getUserID()); $this->email_to = $ui->getUserEmail();
If I use the same code in the view.php, it all works fine without errors.
What's wrong with the controller?
Thank you.
5.6.9
Could it be something to do with namespaces?
I'm using namespace Concrete\Package\MyPackage\Block\MyPackage;
use Config; use UserInfo; use User;
And this code:
$site_name = Config::get('concrete.site'); var_dump($site_name); $adminUserInfo=UserInfo::getByID(USER_SUPER_ID); $this->email_to = $adminUserInfo->getUserEmail(); var_dump($adminUserInfo); var_dump($this->email_to); $u = new User(); $ui = UserInfo::getByID($u->getUserID()); $this->email_to = $ui->getUserEmail(); var_dump($u); var_dump($ui); var_dump($this->email_to); exit;
You see values being dumped? If so, remove all var dumps and exits and use to your liking! :) I do assume you're on Concrete5 5.7 as this will not work in 5.6.
I made a simple test:
controller.php:
<?php namespace Concrete\Package\MyPackage\Block\MyPackage; use \Concrete\Core\Block\BlockController; use Config; class Controller extends BlockController { public $site = Config::get('concrete.site'); public function view() { $this->set('site', $this->site); } }
view.php:
Still the same error:
Whoops \ Exception \ ErrorException (E_PARSE) syntax error, unexpected '(', expecting ',' or ';' /srv/www/htdocs/test/packages/my_package/blocks/my_package/controller.php12
If I change the controller to
namespace Concrete\Package\MyPackage\Block\MyPackage; use \Concrete\Core\Block\BlockController; use Config; class Controller extends BlockController { public function view() { $this->set('site', "My Site"); }
It works fine. Same problem with the user and email. Same error if I use use 'namespace \Concrete\Core\Config;' How come? How do you get all that stuff in controllers of your own packages?
<?php namespace Concrete\Package\MyPackage\Block\MyPackage; use \Concrete\Core\Block\BlockController; use Config; class Controller extends BlockController { public function view() { $site = Config::get('concrete.site'); $this->set('site', $site); } }
But how do I get it to work within my class, not just within the view function?
public function on_start(){ $this->site = Config::get('concrete.site'); $this->set('site', $this->site) }
You can also on set the site in your view function if you'd like, as you probably do not need this variable in every function of your controller?
Does this make sense to you? :)
Anyway, I'm setting all my variables in the view function now and it works.
Thank you.
Which PHP version are you using?