1

I’m trying to bootstrap Craft as a service inside of another framework (lumen). I’m requiring the bootstrap file which seems to get me up and running except that plugins and assets aren’t included in the EntryModel results.

I’m requiring Craft like this:

$craft = require_once base_path().'/../craft/app/bootstrap.php';
 $this->app->singleton('Craft', function() use ($craft)
{

return $craft; 
});

and then getting my EntryModel like this:

$criteria = app()->make('Craft')->elements->getCriteria(ElementType::Entry); 
$criteria->section = 'emails';
 $criteria->slug = 'tuition-agreement-link';
 $email = $criteria->first();

Text content returns perfectly, but asset fields return null. The one thing I can see that craft/app/index.php does differently than me is calling $app->run() (since I'm not actually trying to run the full blown app with request routing). Anyone know if there is an additional step I can take to bootstrap assets and plugins without running the full blown app? Am I trying to do the impossible?

1 Answer 1

1

Craig, I really don't know much directly about this, but it occurred to me to look at the ConsoleApp, which is used in one normal way to run Craft headless (from yiic on command line). It's in app/etc/console/ConsoleApp.php.

A little hunting around with PhpStorm, excellent for this sort of thing as others, turns up that ConsoleApp is loading plugins, and I think it will be loading things like Assets through the loadEditionComponents call -- edition checks out to mean Craft Edition, as Personal, Client, Pro, etc. by your license -- so that S3 might be available for Assets, and so forth.

Just what you would need to do, haven't time to go further on. You might find just calling ConsoleApp->run() would do, or may have to make a modified version of ConsoleApp, but seems it might make a good scaffold in that case.

Good fortune on this; interested to know what you work out.

3
  • Thanks so much! I'll check into this! That sounds like a good place to start! Commented Jun 15, 2016 at 14:04
  • I did a little bit of playing around. I can't simply run the console application because it checks to make sure it's a console app and fails. I think I would have to actually crete a new application class that extends CApplication that doesn't include request handling. I'm not sure exactly how to do that yet, but hopefully I can find something in ConsoleApp that will tell me. Commented Jun 15, 2016 at 15:53
  • Actuallly, I had a look at the 'Related' SEs over on the right, and the first one looks like it has what you need, per Craft CEO/co-creator Brandon Kelley.: craftcms.stackexchange.com/questions/608/…. You can see if this gets you there... Commented Jun 17, 2016 at 6:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.