symfony adding file image constraints to form

let’s say you want to constraint what people are uploading and you don’t want to use assert statements in the entity. you can do it in the formbuilder

use Symfony\Component\Validator\Constraints\File;
...
$form = $this->createFormBuilder($entity)
            ->add('logo', FileType::class,
                array(
                    'label' => false,
                    'attr' => array(
                        'accept' => "image/jpeg, image/png"
                    ),
                    'constraints' => [
                        new File([
                            'maxSize' => '2M',
                            'mimeTypes' => [
                                'image/jpeg',
                                'image/png',
                            ],
                            'mimeTypesMessage' => 'Please upload a JPG or PNG',
                        ])
                    ]
                )
            )

Drupal 8 quickstart using composer

There are benefits of using installing drupal via composer. Forget about drush, let us use the drupal console to install the site. This is the symfony way. # let us configure the drupal command line ln -s /path_to_myproj/vendor/drupal/console/bin/drupal /usr/local/bin/drupal cd web drupal site:install [/php]

Best Vagrant Lamp Stack

imagine setting up a vagrant and playing around with the vagrant config file. boots up and some libraries are not working, dependencies not working…etc. thanks to scotch box, a vagrant lamp stack that just works https://box.scotch.io/

Docker Cheatsheet

Docker helps a lot in the dev process. If using windows or mac, need to use a vagrant vm that allows nfs. https://github.com/blinkreaction/boot2docker-vagrant this will help u setup the vagrant. Once vagrant is up, shell in and run docker commands. Remember to port follow all the relevant application port in virtualbox. Here are some commonly … Continue reading

extending phpstorm

simply install the EAP https://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Early+Access+Program

git push origin feature refspec error

If you try to git push -u origin feature/branch_name and you get this error “error: src refspec feature/branch_name does not match any”, it means that your local branch are not named correctly. It should be named feature/branch_name as well, not just branch_name. Do a “git branch” to confirm yourself.

Good online drawing tool

I think https://cacoo.com/ is pretty cool. what a gem. check it out.

FTP in yosemite

we can use the in build ftp daemon To load: To unload:

Vagrant Authentication fails

Sometimes things go wrong during vagrant setup especially if have set it up already. You might get errors like “Authentication Failure” during “vagrant up” command. It is troublesome to get into the VM if there is no ssh key. Type in vagrant ssh-config To see whats happening. make sure u have ssh keys already. then … Continue reading

Tips for working with dates in PHP

Converting from different date format can be challenging. All the php and mysql date functions can be confusing. Just store the date as yearmmdd format, eg 20160220 means year 2016, 02 month and 20 day. This format works well with strtotime function. As per unix timestamp, you can also use basic arithmetic to compare the … Continue reading

Page 1 of 3512345Next Page »