php

Qualche difficoltà nel capire nel php l'implementazione della closure

In javascript tutto è più semplice. Ora sto usando/imparando Phalcon e il secondo esempio/tutorial è strambo un bel po' (INVO).

Definisce una class Services, derivata da \Base\Services, a sua volta derivata da \Phalcon\Di\FactoryDefault.

In \Base\Services è definito un metodo, bindServices(), che cicla sui metodi definiti per la classe stessa, controllando che abbiano almeno 4 lettere, e che le prime 4 siano 'init'. In caso affermativo fa ... meglio incollare il codice:

Why not to use remove link

This is my experience: I have to rewrite administration page where
there is remove button (in a form) with only javascript confirm.

I thought: "no one had problem with no limitation in the past, why they
should now? I'll use a link with javascript confirm.

It happened I have a dashboard page where is listed the last entries
and links for update and delete its. It happened that few day later 20
entries was deleted and I was looking for what caused the problem for
one day.

php goodies: filter

Filter is in php by default from 5.2.0 and is a usefull library for web developer, so it is the time to make use of it.

It was created for validation and sanitization of foreign input, that is GET, POST, COOKIE, or anything that you can't trust on. With php filter one can tests if a variable is present in the current request: 

if(filter_has_var(INPUT_POST,'login')) {
//manage login
}

Using this function a check state of a checkbox in a form could be tested as well:

shuffle db table order

simple code to shuffle a table ... with php shuffle:

$result = $mysql->query("SELECT id FROM $table ORDER BY id");
$rows = $result->num_rows;
$order = shuffle(range(1,$rows));
while($row=$result->fetch_row()) {
  $num=array_shift($order);
  $mysql->query("UPDATE $table SET rand_sort=$num WHERE id=".$row[0]);
}

added:
with MySQL RAND():