Phalcon-asset-management

提供:Dev Guides
移動先:案内検索

ファルコン-資産管理

資産は、Phalconの既存のフレームワークとは別の追加コンポーネントに関するものです。 Phalconには、CSSやJSファイルなどのすべてのアセットコンポーネントの管理に役立つアセットマネージャーがあります。

使用される一般的な方法は-

Method Importance
__construct(variable $options) Initializes the component Phalcon\Assets\Manager
addCss(string $path, variable $local, variable $filter, variable $attributes) Adds a CSS resource from the 'css' collection to a particular view
addJs(string $path, variable $local, variable $filter, variable $attributes) Adds a JavaScript resource to the 'js' collection

*css* ファイルを追加するための最良の例であるPhalcon *“ vokuro” *のサンプルプロジェクトを検討してください。 すべての *css* ファイルを呼び出すためのasset/Managerが含まれます。

プロジェクトのデフォルトのコントローラーは、すべての css ファイルを呼び出します。

<?php

namespace Vokuro\Controllers;
use Phalcon\Assets\Manager;

/* *
  * Display the default index page.
*/

class IndexController extends ControllerBase {
  /* *
     * Default action. Set the public layout (layouts/public.volt)
   */
   public function indexAction() {
      $this->assets->addCss("public/style.css");
      $this->view->setVar('logged_in', is_array($this->auth->getIdentity()));
      $this->view->setTemplateBefore('public');
   }
}

Style.css

div.remember {
   margin-top: 7px;
   color: #969696;
}
div.remember label {
   padding-top: 15px;
}
div.forgot {
   margin-top: 7px;
   color: #dadada;
}
footer {
   background: url("../img/feature-gradient.png") no-repeat scroll center 100% white;
   color: #B7B7B7;
   font-size: 12px;
   padding: 30px 0;
   text-align: center;
}
footer a {
   margin-left: 10px;
   margin-right: 10px;
}
table.signup td {
   padding: 10px;
}
table.signup .alert {
   margin-bottom: 0;
   margin-top: 3px;
}
table.perms select {
   margin-top: 5px;
   margin-right: 10px;
}
table.perms label {
   margin-right: 10px;
}
div.main-container {
   min-height: 450px;
}

アセットはビュー内で管理され、CSSファイルが出力として表示されます。

Index.volt

{{ content() }}
{{ assets.outputCss() }}

<header class = "jumbotron subhead" id = "overview">
   <div class = "hero-unit">
      <h1>Welcome!</h1>
      <p class = "lead">This is a website secured by Phalcon Framework</p>
      <div align = "right">
         {{ link_to('session/signup', '<i class="icon-ok icon-white">
            </i> Create an Account', 'class': 'btn btn-primary btn-large') }}
      </div>
   </div>
</header>

出力

それは次の出力を生成します-

生成された出力