The Slim Framework support forum has moved to http://discourse.slimframework.com. This Tender forum is no longer maintained or monitored.

The "right way" to autoload Slim with Twig

Gavin Davies's Avatar

Gavin Davies

01 Aug, 2012 11:14 AM

Hi,

I'm building a simple app that does some sorting and unpacking of zip files. My configuration in index.php seems to be a bit of a mish-mash of autoloaders and requires:

<?php
require '../app/vendor/autoload.php';
require '../app/Filing.class.php';
Twig_Autoloader::register();
Slim::autoload('View_Twig'); // TODO neater way?
require '../app/vendor/slim/extras/View/Twig.php'; // TODO neater way?
require '../app/vendor/slim/extras/LogWriter/TimestampLogFileWriter.php'; // TODO neater way?
$app = new Slim(array(
    'log.enabled' => false,
    'log.writer' => new TimestampLogFileWriter(array('path' => '{my path}/src/app/logs')), // TODO from configuration
    'log.level' => 4,
    'debug' => true, // set to "true" to debug errors
    'view' => new View_Twig
));

$filing = new Filing($app, 'files');

...

I'm using the slim extras - including LogWriter and the Twig template view. Can this be made any more elegant? I'd prefer to get rid of the requires and run it from autoloaders.

I'd appreciate any advice!

Thanks,
- Gavin

  1. Support Staff 1 Posted by Andrew Smith on 01 Aug, 2012 11:20 AM

    Andrew Smith's Avatar

    All extras are now autoloaded with composer except for the LogWriters, I am still working on a few ideas with the autoloader at the moment. Check out Josh's Slim skeleton project to get up and running easily.

    http://www.slimframework.com/read/skeleton-application
    https://github.com/codeguy/Slim-Skeleton

  2. 2 Posted by Gavin Davies on 01 Aug, 2012 12:43 PM

    Gavin Davies's Avatar

    Thanks Andrew, I've followed that and my project looks a great deal neater now!

    Once again, a fast and helpful response from the Slim community!

  3. Andrew Smith closed this discussion on 01 Aug, 2012 12:48 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac