Search

I have a couple of cases in my project where I need to read or update Symphony Sections from standalone PHP scripts. Prior to v2.6 I was using the following code to bootstrap Symphony:

require_once(DOCROOT . '/symphony/lib/boot/bundle.php');
require_once(CORE . '/class.frontend.php');

return Frontend::instance()->isLoggedIn();

After upgrading to 2.6 I started seeing this error:

Fatal error: Class 'Symphony' not found in /path/to/my/project/symphony/lib/boot/bundle.php on line 18

and had to insert the following line to fix it:

require_once(DOCROOT . '/vendor/autoload.php');

Everything seems to be working again but I'm wondering if there's a more robust way to do this. I just need to load enough of Symphony to use the EntryManager and FieldManager classes.

Are there any best practices for bootstrapping Symphony?

Are there any best practices for bootstrapping Symphony?

You are doing it right! Before 2.6, it was a nightmare and I always ended up with

define('DOCROOT', str_replace(RELROOT, '', rtrim(dirname(__FILE__), '\/') ));

require_once(DOCROOT . '/symphony/lib/boot/bundle.php');
require_once(DOCROOT . '/symphony/lib/core/class.cacheable.php');
require_once(DOCROOT . '/symphony/lib/core/class.symphony.php');
require_once(DOCROOT . '/symphony/lib/core/class.administration.php');
require_once(DOCROOT . '/symphony/lib/toolkit/class.general.php');
require_once(TOOLKIT . '/class.sectionmanager.php');
require_once(TOOLKIT . '/class.entrymanager.php');

Now requiring the autoload is enough :)

If you want your code to work with both 2.6 and earlier, you can check if the DOCROOT . '/vendor/autoload.php' file exists. If it does, require it, if not use the old code.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details