понедельник, 3 июня 2013 г.

Using repositories in Doctrine 2 Submitted by Richard on Mon, 10/04/2010 - 13:37

http://mackstar.com/blog/2010/10/04/using-repositories-doctrine-2

Using repositories in Doctrine 2


One feature of Doctrine 2 and other data mapper style ORM's is that rather than each class model invoking itself to make queries in the database (Active Record style), custom queries to the database are handled by a bridge layer that is extends the Entity Manager.
We cannot do any any queries to the DB without going through the Entity Manager, here is the simplest case:
$user $em->find('Entities\User'$id);
But more often than not we will need to go through a repository for that model, in the Java world these are often referred to as Data Access Objects or DAO's. Again a simple example would look like the following:
$user $em->getRepository('Entities\User')->find($id);
Here the Entity Manager will look for the Repository which is attached to your Entity class. If you have not set this yet it will provide you with a default Repository class (Doctrine\ORM\EntityRepository) which contains the following methods for accessing your data:
public function findAll()
public function findBy(array $criteria)
public function findOneBy(array $criteria)
With these very simple methods you can get direct access to your data, but more than often this will not be enough. The default EntitiyRepository class contains
public function createQueryBuilder($alias)
Which you can probably just go ahead and use just like in the example above (I have never tried) in your controller etc, but this should not really be done, when you need the power of the query builder, DQL (Doctrine Query Language) or native SQL calls you should be writing these in your own repository class for the particular entity that you are using.
This will inherit Doctrine\ORM\EntityRepository:
namespace Repositories;
 
use Doctrine\ORM\EntityRepository;
use Entities;
 
class UserRepository extends EntityRepository
{
    public function finderMethod($arguments){
        // My custom query etc
    }
}
But you need to tell Doctrine now that you have created this repository. You can do that by the Driver Implementation type you are using(ie YAML/Annotations/XML). I use annotations and I highly recommend you do as it keeps everything in the same place. Here is how we do this in your entitiy class:
namespace Entities;
 
/** @Entity(repositoryClass="Repositories\UserRepository")
 *  @Table(name="dealers")
 */
class User
So now when you try and access your own custom finder method it will now all be lovely-jubbly!:
$users $em->getRepository('Entities\User')->finderMethod($arguments);
An example of this might be:
$users $em->getRepository('Entities\User')->findAuthenticatedUsersForDate($date);
Which you can add the following type of repository custome finder method:
public function findAuthenticatedUsersForDate($date)
 
    // First get the EM handle
    // and call the query builder on it
    $qb $this->_em->createQueryBuilder();
    $qb->select('u')
        ->from('Entities\User''u')
        ->where('u.authenticated = 1')
        ->andWhere('u.date = :date')
        ->setParameter('date'$date)
        ->orderBy('u.name');
 
    return $qb->getQuery()->getResult();
}
I found the $qb->getQuery()->getResult();  explanations quite scarce, but you need to use them even if using DQL.

Дока по гиту (очень неплохая)

http://www-cs-students.stanford.edu/~blynn/gitmagic/intl/ru/ch04.html

суббота, 4 мая 2013 г.

понедельник, 22 апреля 2013 г.

MySQL Default to UTF-8 & MyISAM


mcedit /etc/mysql/my.cnf


[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
default-storage-engine=MyISAM

Result is

mysql> show variables like "%character%";show variables like "%collation%";

+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

+----------------------+-----------------+
| Variable_name | Value |
+----------------------+-----------------+
| collation_connection | utf8_unicode_ci |
| collation_database | utf8_unicode_ci |
| collation_server | utf8_unicode_ci |
+----------------------+-----------------+

HowTo: Find Out My Linux Distribution Name and Version

source : http://www.cyberciti.biz/faq/find-linux-distribution-name-version-number/

by  on OCTOBER 25, 2007 · 44 COMMENTS· last updated at AUGUST 21, 2012
How do I find out what version of Linux distribution I'm using from the shell (bash) prompt?

To find out what version of Linux (distro) you are running, enter the following command at the shell prompt:
$ cat /etc/*-release
Sample output from my RHEL v5.x server:
Red Hat Enterprise Linux Server release 5 (Tikanga)
Sample outputs from my Ubuntu Linux v7.10 server:
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=7.10
DISTRIB_CODENAME=gutsy
DISTRIB_DESCRIPTION="Ubuntu 7.10"

lsb_release Command

The lsb_release command displays certain LSB (Linux Standard Base) and distribution-specific information. Type the following command:
$ lsb_release -a
Sample outputs:
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 6.0.1 (squeeze)
Release: 6.0.1
Codename: squeeze

How Do I Find Out My Kernel Version?

Type the following command:
$ uname -a
OR
$ uname -mrs
Sample outputs:
Linux 2.6.32-5-amd64 x86_64
Where,
  1. Linux - Kernel name
  2. 2.6.32-5-amd64 - Kernel version number
  3. x86_64 - Machine hardware name (64 bit)

Say hello to /proc/version

Type the following command to see kernel version and gcc version used to build the same:
$ cat /proc/version
Sample outputs:
Linux version 3.2.0-0.bpo.1-amd64 (Debian 3.2.4-1~bpo60+1) (ben@decadent.org.uk) (gcc