问题
I'm working with ZF2 with MongoDB and Doctrine 2 ODM, I got the above mentioned error on New Relic (New relic is continuously checking the live environment and logging the errors). I got the following error:
syntax error, unexpected ''sidebar_bann' (T_ENCAPSED_AND_WHITESPACE), expecting ']'
TracedError reported from New Relic
Timestamp: 02/26/14 10:49:15
Exception Class: E_PARSE
Error Action: /index.php
Uri: /blog
Error message
E_PARSE: syntax error, unexpected ''sidebar_bann' (T_ENCAPSED_AND_WHITESPACE), expecting ']'
and the stack trace pointed to :
…dor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Hydrator/
HydratorFactory.php (144)
…dor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Hydrator/
in Doctrine\ODM\MongoDB\Hydrator\HydratorFactory::getHydratorFor called at /vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Hydrator/HydratorFactory.php
HydratorFactory.php (404)
/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/
UnitOfWork.php (2518)
/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/
Cursor.php (118)
in Doctrine\ODM\MongoDB\Cursor::current called at ?
…alled at /vendor/doctrine/mongodb/lib/Doctrine/MongoDB/
Cursor.php (371)
…alled at /vendor/doctrine/mongodb/lib/Doctrine/MongoDB/
Cursor.php (419)
…alled at /vendor/doctrine/mongodb/lib/Doctrine/MongoDB/
Cursor.php (372)
…alled at /vendor/doctrine/mongodb/lib/Doctrine/MongoDB/
Cursor.php (384)
… at /vendor/doctrine/mongodb/lib/Doctrine/MongoDB/Query/
Query.php (277)
…ult called at /module/Blog/src/Blog/Service/
BlogCustomization.php (552)
…ain called at /module/Blog/src/Blog/Controller/
BlogController.php (116)
…r/www/env2/vendor/ZF2/library/Zend/Mvc/Controller/
AbstractActionController.php (83)
in Zend\Mvc\Controller\AbstractActionController::onDispatch called at ? (?)
… called at /vendor/ZF2/library/Zend/EventManager/
EventManager.php (460)
… called at /vendor/ZF2/library/Zend/EventManager/
EventManager.php (204)
…at /vendor/ZF2/library/Zend/Mvc/Controller/
AbstractController.php (117)
…patch called at /vendor/ZF2/library/Zend/Mvc/
DispatchListener.php (114)
in Zend\Mvc\DispatchListener::onDispatch called at ? (?)
… called at /vendor/ZF2/library/Zend/EventManager/
EventManager.php (460)
Please help me to find the cause of this error.
I', calling a function from controller(BlogController.php (116)), the function is getUserIdByDomain($domain) which was written on BlogCustomization.php (552)
The parameter should always be a sub domain, eg: prodtest-05.xxx.com. It should be always a string value not an array as I'm taking it from $_SERVER['HTTP_HOST']. The code would be like this
In Controller
$hostname = $_SERVER['HTTP_HOST'];
$result = $model->getUserIdByDomain($hostname);
In Model
$dm = $this->getServiceLocator()->get('doctrine.documentmanager.odm_default');
$blog_query = $dm->createQueryBuilder('Blog\Document\Blog')
->field('subdomain')->equals($domain);
$blog_query = $blog_query->getQuery();
$blog = $blog_query->getSingleResult();
The error points to this line. Could you please light me something more on this?
回答1:
Did u try looking in index.php or blog/index.php or the controllers that call them? You have a simple php syntax error somewhere. Probably look for something that's an array and key value within a regular string like so
echo '$arrayVar['keyname']';
those single quotes will get you every time if you're not careful
来源:https://stackoverflow.com/questions/22813634/syntax-error-unexpected-sidebar-bann-t-encapsed-and-whitespace-expecting