We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Asset Manager set target path

I have a path in a private directory that I want to recreate in a public path. Here is an example of what I mean:

/application
        /public
                /assets
                index.php
        /themes
                /default
                        /css
                            style.css

I want to be able to create/publish, style.css in /public/assets/themes/default/css/style.css for public access. How can I achieve that with Asset Manager?

I have tried the following with no luck:

$di->set('assets', function() {
     $assets = new Phalcon\Assets\Manager([
          'output'=>realpath(__DIR__.'/assets/'),
          'compileAlways'=>false,
          'stat'=>true
      ]);
      return $assets;
});

  // controller
$css = new \Phalcon\Assets\Resource\Css('/assets/style.css');
$css->setSourcePath(realpath($this->view->getViewsDir().'/../../assets/style.css'));
$css->setTargetPath(APP_PATH.'/assets/style.css');
$css->setLocal(false);
$this->assets->addResourceByType('css', $css);

// view
$this->assets->outputCss();


8.7k

I have tried adding the \Phalcon\Assets\Filters\None to the collection but it still does not create the files in the target path and keeps telling me "Target path in invalid", the permissions and everything is correct, so I really don't know what I can do to fix this issue.