在phalcon中使用Assetsmanager时,路径''不是有效的目标路径(1)

时间:2017-10-26 08:44:44

标签: controller assets phalcon phalcon-routing

我得到的错误:路径''不是有效的目标路径(1)

#0 [internal function]: Phalcon\Assets\Manager->output(Object(Phalcon      \Assets\Collection), Array, 'css')
#1 C:\xampp\htdocs\PVO\app\views\index.phtml(17): Phalcon\Assets\Manager->outputCss('header')
#2 [internal function]: unknown()
#3 [internal function]: Phalcon\Mvc\View\Engine\Php->render('C:\\xampp\\htdocs...', Array, true)
#4 [internal function]: Phalcon\Mvc\View->_engineRender(Array, 'index', true, true, NULL)
#5 [internal function]: Phalcon\Mvc\View->render('index', 'index', Array)
#6 C:\xampp\htdocs\PVO\public\index.php(42): Phalcon\Mvc\Application->handle()
#7 {main}

这是我到目前为止所做的。 这是我的controllerBase:

<?php

use Phalcon\Mvc\Controller;
use Phalcon\Assets\Filters\Jsmin;
use Phalcon\Assets\Filters\Cssmin;

class ControllerBase extends Controller {

public function onConstruct() {

    $this->assets
            ->useImplicitOutput(false)
            ->collection('footer')
            ->addJs('https://code.jquery.com/jquery-3.2.1.js', false, true)
            ->addFilter(new Jsmin());
    $this->assets
            ->useImplicitOutput(false)
            ->collection('header')
            ->addJs('https://code.jquery.com/jquery-3.2.1.js', false, true)
            ->addFilter(new Jsmin());
    $this->assets
            ->useImplicitOutput(false)
            ->collection('header')
            ->addCss('https://code.jquery.com/jquery-3.2.1.js', false, true)
            ->addFilter(new Cssmin());
}



}

然后我就是这样做的。

    <head>

    <!-- Basic -->
    <meta charset="UTF-8">


    <meta name="keywords" content="HTML5 Admin Template" />
    <meta name="description" content="Porto Admin - Responsive HTML5 Template">
    <meta name="author" content="okler.net">

    <!-- Mobile Metas -->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />

    <!-- Web Fonts  -->

    <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800|Shadows+Into+Light" rel="stylesheet" type="text/css">


       <!-- All the Header Css and JS -->
<?php $this->assets->outputCss('header'); ?>
        <?php $this->assets->outputJs('header'); ?>
    </head>

我还在我的assetsController中创建了两个函数,名为HeaderAction和footerAction,它执行此操作:

public function headerAction() {
     $headerCollection = $this->assets->collection('header');
    //Vendor CSS
    $headerCollection->addCss('assets/vendor/bootstrap/css/bootstrap.css');
    $headerCollection->addCss('assets/vendor/font-awesome/css/font-awesome.css');
    $headerCollection->addCss('assets/vendor/magnific-popup/magnific-popup.css');
    $headerCollection->addCss('assets/vendor/bootstrap-datepicker/css/bootstrap-datepicker3.css');
    //Specific Page Vendor CSS
    $headerCollection->addCss('assets/vendor/jquery-ui/jquery-ui.css');
    $headerCollection->addCss('assets/vendor/jquery-ui/jquery-ui.theme.css');
    $headerCollection->addCss('assets/vendor/bootstrap-multiselect/bootstrap-multiselect.css');
    $headerCollection->addCss('assets/vendor/morris.js/morris.css');
    //Theme
    $headerCollection->addCss('assets/stylesheets/theme.css');
    //Theme custom
    $headerCollection->addCss('assets/stylesheets/theme-custom.css');
    //Head libs
    $headerCollection->addJs('assets/vendor/modernizr/modernizr.js');
    $headerCollection->addJs('assets/vendor/style-switcher/style.switcher.localstorage.js');
    //Fullscreen fix
    $headerCollection->addCss('assets/assets/css/fullscreenIframe.css');
}

public function footerAction() {
    $footerCollection = $this->assets->collection('footer');
    //Vendor
    $footerCollection->addJs('assets/vendor/jquery/jquery.js');
    $footerCollection->addJs('assets/vendor/jquery-browser-mobile/jquery.browser.mobile.js');
    $footerCollection->addJs('assets/vendor/jquery-cookie/jquery-cookie.js');
    $footerCollection->addJs('assets/vendor/style-switcher/style.switcher.js');
    $footerCollection->addJs('assets/vendor/bootstrap/js/bootstrap.js');
    $footerCollection->addJs('assets/vendor/nanoscroller/nanoscroller.js');
    $footerCollection->addJs('assets/vendor/bootstrap-datepicker/js/bootstrap-datepicker.js');
    $footerCollection->addJs('assets/vendor/magnific-popup/jquery.magnific-popup.js');
    $footerCollection->addJs('assets/vendor/jquery-placeholder/jquery-placeholder.js');
    //Specific Page Vendor
    $footerCollection->addJs('assets/vendor/jquery-ui/jquery-ui.js');
    $footerCollection->addJs('assets/vendor/jqueryui-touch-punch/jqueryui-touch-punch.js');
    $footerCollection->addJs('assets/vendor/jquery-appear/jquery-appear.js');
    $footerCollection->addJs('assets/vendor/bootstrap-multiselect/bootstrap-multiselect.js');
    $footerCollection->addJs('assets/vendor/jquery.easy-pie-chart/jquery.easy-pie-chart.js');
    $footerCollection->addJs('assets/vendor/flot/jquery.flot.js');
    $footerCollection->addJs('assets/vendor/flot.tooltip/flot.tooltip.js');
    $footerCollection->addJs('assets/vendor/flot/jquery.flot.pie.js');
    $footerCollection->addJs('assets/vendor/flot/jquery.flot.categories.js');
    $footerCollection->addJs('assets/vendor/flot/jquery.flot.resize.js');
    $footerCollection->addJs('assets/vendor/jquery-sparkline/jquery-sparkline.js');
    $footerCollection->addJs('assets/vendor/raphael/raphael.js');
    $footerCollection->addJs('assets/vendor/morris.js/morris.js');
    $footerCollection->addJs('assets/vendor/gauge/gauge.js');
    $footerCollection->addJs('assets/vendor/snap.svg/snap.svg.js');
    $footerCollection->addJs('assets/vendor/liquid-meter/liquid.meter.js');
    $footerCollection->addJs('assets/vendor/jqvmap/jquery.vmap.js');
    $footerCollection->addJs('assets/vendor/jqvmap/data/jquery.vmap.sampledata.js');
    $footerCollection->addJs('assets/vendor/jqvmap/maps/jquery.vmap.world.js');
    $footerCollection->addJs('assets/vendor/jqvmap/maps/continents/jquery.vmap.africa.js');
    $footerCollection->addJs('assets/vendor/jqvmap/maps/continents/jquery.vmap.asia.js');
    $footerCollection->addJs('assets/vendor/jqvmap/maps/continents/jquery.vmap.australia.js');
    $footerCollection->addJs('assets/vendor/jqvmap/maps/continents/jquery.vmap.europe.js');
    $footerCollection->addJs('assets/vendor/jqvmap/maps/continents/jquery.vmap.north-america.js');
    $footerCollection->addJs('assets/vendor/jqvmap/maps/continents/jquery.vmap.south-america.js');
    $footerCollection->addJs('assets/vendor/jquery-ui/jquery-ui.js');
    $footerCollection->addJs('assets/vendor/jqueryui-touch-punch/jqueryui-touch-punch.js');
    $footerCollection->addJs('assets/vendor/jquery-appear/jquery-appear.js');
    $footerCollection->addJs('assets/vendor/bootstrap-multiselect/bootstrap-multiselect.js');
    $footerCollection->addJs('assets/vendor/jquery.easy-pie-chart/jquery.easy-pie-chart.js');
    $footerCollection->addJs('assets/vendor/flot/jquery.flot.js');
    $footerCollection->addJs('assets/vendor/flot.tooltip/flot.tooltip.js');
    $footerCollection->addJs('assets/vendor/flot/jquery.flot.pie.js');
    $footerCollection->addJs('assets/vendor/flot/jquery.flot.resize.js');
    // Theme Base, Components and Settings 
    $footerCollection->addJs('assets/javascripts/theme.js');
    //Theme custom
    $footerCollection->addJs('assets/javascripts/theme.custom.js');
    //Page Head Name
    $footerCollection->addJs('assets/javascripts/page.head.js');
    //Theme Initialization Files
    $footerCollection->addJs('assets/javascripts/theme.init.js');
    // Examples
    $footerCollection->addJs('assets/javascripts/dashboard/examples.dashboard.js');

}

我不知道为什么说:Path''不是有效的目标路径(1)。

2 个答案:

答案 0 :(得分:0)

默认情况下,phalcon会加入所有资源。您需要为已加入的资源提供目标路径。您需要使用Collection::setTargetPath进行设置。

答案 1 :(得分:0)

正如Juri所说,你需要setTargetPath。在您的收藏中(例如。$footerCollection / $headerCollection),添加以下内容:

$footerCollection->setTargetPath("cache/assets/final.js")
                 ->setTargetUri("cache/assets/final.js")
                 ->join(true);