1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PhalconのVoltでfor文を使う方法

Posted at

最近Phalconに触る機会があり、Voltテンプレートエンジンでfor文を書きたいときに苦戦したので、備忘録としてメモ( ..)φ。

環境

  • PHP 7.2
  • Phalcon 3.4

概要

PhalconではVoltというテンプレートエンジンが採用されており、いくつかの制御構文を使用できます。
その中にループ処理のためのfor文があるのですが、これはPHPのforeach文のような動作をします。

{% for user in users %}
    * Name: {{ user.name }}
{% endfor  %}

今回はPHPのfor文に該当するループ処理をするための方法を記載します。

結論

voltでは、..という演算子があり、PHPのrange関数のようなことができます。
これとVoltのfor文を組み合わせて、下記のような処理を書くことでPHPのfor文のようなループ処理を実現できます。

<select>
{% for year in 1950..2020 %}
    <option>{{ year }}</option>
{% endfor  %}
</select>

参考

Volt: テンプレートエンジン — Phalcon 2.0.8 ドキュメント

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?