пятница, 2 октября 2015 г.

Symfony2: fix error on dumping assets with using less, in Ubuntu 14.04

If you got an error on dumping assets
 
$ php app/console assetic:dump 
 
[Assetic\Exception\FilterException]         
  An error occurred while running:            
  '/usr/sbin/node' '/tmp/assetic_lessl9esGS
 
Check anf fix all paths for nodejs and less, or just try this configuration
 
assetic:
    debug:          "%kernel.debug%"
    use_controller: false
    bundles:        [ ]
    #java: /usr/bin/java
    filters:
        less:
            bin: /usr/local/bin/lessc
            node: /usr/bin/nodejs
            node_paths: ["/usr/local/lib/node_modules"]
            apply_to: "\.less$"

вторник, 15 января 2013 г.

Phalcon: Set output format for Phalcon-based RESTful API

1. edit .htaccess

AddDefaultCharset UTF-8

<ifmodule mod_rewrite.c="mod_rewrite.c">
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^.]+)$ index.php?_url=/$1&format=json [QSA,L]
    RewriteRule ^([^.]+)\.(\w+)$ index.php?_url=/$1&format=$2 [QSA,L]
</ifmodule>


2. edit index.php
  ...
  $app = new \Phalcon\Mvc\Micro();
  ...
  $app->finish(function () use ($app) {
    // check format
    $format = $app->request->getQuery('format', 'string', 'json');
    switch ($format) {
      case 'json': 
        print(json_encode($app->result->data));
        break;
      case 'xml':
        $xml = new SimpleXMLElement('');
        array_walk_recursive($app->result->data, array ($xml, 'addChild'));
        print $xml->asXML();
        break;
    }
  });
  
3. use api with .json | .xml

$ curl http://site/api/user/1
$ {json: data}
$ curl http://site/api/user/1.json
$ {json: data}
$ curl http://site/api/user/1.xml
$ <xml>data</xml>

четверг, 22 ноября 2012 г.

mysql: set utf-8 by default

$ cd /etc/mysql
$ sudo nano my.cnf

[client]
default-character-set   = utf8

[mysqld]
init_connect='SET collation_connection = utf8_general_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_general_ci
skip-character-set-client-handshake

[mysql]
default-character-set   = utf8

$ sudo service mysql restart

понедельник, 17 сентября 2012 г.

mysql: Cannot delete or update a parent row: a foreign key constraint fails


Если при удалении пустой таблицы, не содержащей никаких связей и индексов из БД все же возникает ошибка
MySQL said: Documentation #1217 - Cannot delete or update a parent row: a foreign key constraint fails

Выполняем следующий запрос:

SET FOREIGN_KEY_CHECKS =0;
DROP TABLE IF EXISTS table_name;
SET FOREIGN_KEY_CHECKS =1;




четверг, 19 января 2012 г.

Symfony: short commands in terminal

Save time and reduce typing errors on working in console

$ nano /usr/local/bin/sf

if [ -z "$1" ]; then
    echo "Missing parameters."
    echo "Usage: $0 --midiff, --mi or --buall"
    exit 0
fi

case "$1" in
    "--cc" )
    php symfony cc
    ;;

    "--midiff" )
    php symfony doctrine:generate-migrations-diff
    ;;

    "--mi" )
    php symfony doctrine:migrate
    ;;

    "--buall" )
    php symfony doctrine:build --all-classes
    ;;

    "--busql" )
    php symfony doctrine:build-sql
    ;;

    "--inssql" )
    php symfony doctrine:insert-sql
    ;;

    "--puass" )
    php symfony plugin:publish-assets
    ;;

esac
exit 0

Usage:

For example: you need modify your schema, migrate, rebuild all classes and clear cache.

$ sf --midiff
$ sf --mi
$ sf --buall
$ sf --cc

вторник, 22 февраля 2011 г.

Symfony: doctrine custom sql order

    $this->data = Doctrine_Query::create()
->from('Category c')
->innerJoin('c.Product p')
->whereIn('c.slug', array('cpu', 'mainboards', 'ram', 'hdd', 'videocards', 'cases'))
->addWhere('p.is_published = ?', true)
->addOrderBy('FIELD(c.slug, "cpu", "mainboards", "ram", "hdd", "videocards", "cases")')
->execute()
;

понедельник, 7 февраля 2011 г.