Last active
June 20, 2017 12:02
-
-
Save ninjapanzer/fb0f897d74d34bb667d35d454bb7d370 to your computer and use it in GitHub Desktop.
Phalcon Registering Namespace
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Assets\JS; | |
class ApplicationManifest | |
{ | |
protected $assets; | |
public function __construct($assets) | |
{ | |
$assets->collection('fullcalendarCSS') | |
->addCss('node_modules/fullcalendar/dist/fullcalendar.min.css') | |
->join(true) | |
->addFilter( | |
new Phalcon\Assets\Filters\Jsmin() | |
) | |
->setTargetPath('public/application.css'); | |
$assets->collection('fullcalendarJS') | |
->addJs('node_modules/jquery/dist/jquery.min.js') | |
->addJs('node_modules/moment/min/moment.min.js') | |
->addJs('node_modules/fullcalendar/dist/fullcalendar.min.js') | |
->addJs('js/fullcalendarImpl.js') | |
->join(true) | |
->setTargetPath('public/application.js'); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Phalcon\Loader; | |
use Phalcon\Tag; | |
use Phalcon\Mvc\Url; | |
use Phalcon\Mvc\View; | |
use Phalcon\Mvc\Application; | |
use Phalcon\Mvc\View\Engine\Volt as PhVolt; | |
use Phalcon\DI\FactoryDefault; | |
use Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter; | |
try { | |
// Register an autoloader | |
$loader = new Loader(); | |
$loader->registerNamespaces( | |
[ | |
'App\Assets\JS' => '../app/assets/js/' | |
] | |
); | |
$loader->registerDirs( | |
array( | |
'../app/controllers/', | |
'../app/models/' | |
) | |
); | |
$loader->register(); | |
// Create a DI | |
$di = new FactoryDefault(); | |
$di->set( | |
'assetPipeline', | |
[ | |
'className' => 'App\Assets\JS\ApplicationManifest', | |
'arguments' => [[ | |
'type' => 'service', | |
'name' => 'assets', | |
]] | |
] | |
); | |
new App\Assets\JS\ApplicationManifest(); | |
echo $di['assetPipeline']; | |
// Set the database service | |
$di['db'] = function() { | |
return new DbAdapter(array( | |
"host" => "localhost", | |
"username" => "root", | |
"password" => "secret", | |
"dbname" => "tutorial" | |
)); | |
}; | |
// Setting up the view component | |
$di['view'] = function() use ($di) { | |
$options = [ | |
'compiledPath' => '../storage/cache/volt/', //path of where your templates will be compiled | |
'compiledSeparator' => '_', | |
'compiledExtension' => '.php', | |
'compileAlways' => true, | |
'stat' => true, | |
]; | |
$view = new View(); | |
$view->setViewsDir('../app/views/'); | |
$view->registerEngines( | |
[ | |
'.volt' => function ($view) use ($options, $di) { | |
$volt = new PhVolt($view, $di); | |
$volt->setOptions($options); | |
return $volt; | |
}, | |
] | |
); | |
return $view; | |
}; | |
$di['url']->setBaseUri('/'); | |
// Handle the request | |
$application = new Application($di); | |
echo $application->handle()->getContent(); | |
} catch (Exception $e) { | |
echo "Exception: ", $e->getMessage(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment