Синтаксис twig сходен с шаблонизатором в Django. Шаблоны компилируются в PHP классы.
Базовый синтаксис:
{{ сказать что-то }}
{% сделать что-то %}
Комментарий
{# A comment #}
Переменные, вывод
{{ sitename }}
{{ user.name }}
{{ foo['bar'] }}
{# A comment #}
{{ sitename }}
{{ user.name }}
{{ foo['bar'] }}
$object = (new SomeWhat(param))->setStyle(20)->setText('Hello')->load();
$a = [1, 2, 3];
$b = ['key' => 'value', 'key1' => 'value1', 'keyN' => 'valueN'];
core::timer('mysql_connect');
$connection = new mysqli(
'localhost',
$dbcfg['login'],
$dbcfg['password'],
$dbcfg['database']
);
core::dprint('time : ' . core::timer('mysql_connect'));
#time : 1.018641
if (md5($password) == $hash) {
print "OK!\n";
}
SELECT * FROM table ORDER BY rand() LIMIT 0,5 --0.014628
SELECT id FROM table ORDER BY rand() LIMIT 1; --0.000592
SELECT id FROM table ORDER BY rand() LIMIT 1; --0.000385
SELECT id FROM table ORDER BY rand() LIMIT 1; --0.000374
SELECT id FROM table ORDER BY rand() LIMIT 1; --0.000380
SELECT id FROM table ORDER BY rand() LIMIT 1; --0.000377
-- всего 0.002075
-- или так, быстрее
SELECT id FROM table ORDER BY rand() LIMIT 0,5 --0.000483
-- сама выборка
SELECT * FROM table WHERE id IN (80,413,81,127,113) --0.000464
$a = number_format(9.0E-5,6,'.','')
$b = sprintf('%f', 9.0E-5)
mysql> select * from ph_tags;
ERROR 1034 (HY000): Incorrect key file for table 'ph_tags'; try to repair it
find /var/db/mysql -type f -name 'ph_tags.MYI' -exec myisamchk --force -o -r -v {} \;
mysql> repair table ph_tags;
+------------------+--------+----------+----------------------------------------------------------+
| Table | Op | Msg_type | Msg_text |
+------------------+--------+----------+----------------------------------------------------------+
| titsgtfo.ph_tags | repair | Error | Incorrect key file for table 'ph_tags'; try to repair it |
| titsgtfo.ph_tags | repair | error | Corrupt |
+------------------+--------+----------+----------------------------------------------------------+