1964-1985 Affinità-divergenze fra il compagno ASYNC e noi del conseguimento della Progress Bar

form.html

<!DOCTYPE html>
<html>
<head>
	<title>progressbar</title>
</head>

<body>

	<form  action="upload.php" method="POST">
		<label>File</label>
		<input type="file" name="file">
		<input type="submit" onclick="return uploadFile(this.form);">
	</form>

	<progress min="0" max="100" value="0">0% complete</progress>

<script src="js/script.js"></script>

</body>
</html>

script.js

var uploadFile = function(form){

	var xhr = new XMLHttpRequest();
	var formData = new FormData(form);
	var progressBar = document.querySelector('progress');

	xhr.upload.addEventListener("progress", function(e){
		if(e.lengthComputable) {
			progressBar.value = ( e.loaded / e.total ) * 100;
			progressBar.textContent = progressBar.value + '% complete';
		}

	}, false);

	xhr.open(form.method, form.action, true);
	xhr.send(formData);

        return false;

}

async
An optional boolean parameter, defaulting to true, indicating whether or not to perform the operation asynchronously. If this value is false, the send()method does not return until the response is received. If true, notification of a completed transaction is provided using event listeners. (ma anche eventi non completati AKA progress AKA taaaac) This must be true if the multipart attribute is true, or an exception will be thrown.

Symfony 2.0 + Doctrine + Validare Entity

Mettiamo che voglia evitare che qualche tonto si faccia fregare l’account perchè usa come password il suo nome (non fate spallucce, esistete e siete in troppi).

Entity User:


namespace Acme\*Bundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Acme\*Bundle\Entity\Product
 *
 * @ORM\Table()
 * @ORM\Entity()
 */
class User
{

    /**
     * @var string $name
     *
     * @ORM\Column(name="name", type="string", length=255)
     */
    private $name;

    /**
     * @var string $psw
     *
     * @ORM\Column(name="psw", type="string", length=255)
     */
    private $psw;

...
   
    public function isPasswordLegit()
    {
        return $this->getPsw() != $this->getName();
    }
}

Validation.yml


# src/Acme/*Bundle/Resources/config/validation.yml

Acme\*Bundle\Entity\User: getters:

passwordLegit: - "True": { message: "La password fa schifo, cambiala. <3" }

createAction:

                ...

                $user = new User();

                ...
                setter
                ...

                $validator = $this->get('validator');

                $errors = $validator->validate($user);

                if(count($errors) > 0){
                        return $this->render('Acme*Bundle:Default:validate.html.twig', array(
                                'errors' => $errors,
                                ));

Symfony 2.0 + Twig + Debug

Perchè usare quella rottura di palle di var_dump(variabile) quando puoi usare {{ dump(variabile) }} e mantenere comunque un layout decente.

config.yml

app/config/config.yml
services: 
blablabla.twig.extension.debug:
class:	Twig_Extension_Debug 
tags:
- { name: 'twig.extension' }

blablabla.html.twig

{{ dump(acme) }}

p.s.

i file YAML non amano i tab

spaziospaziospaziospazio >> :set ts=4

primo!

Come un qualsiasi stronzo nei commenti di Youtube