Skip to content

Instantly share code, notes, and snippets.

if($this->getObject()->isNew() || $this->getValue('attachment_name') != $this->getObject()->getAttachmentName())
{
//check if attachment filename field or attachment file field are both filled, they both have to be filled if you want to upload an attachemnt file
$this->mergePostValidator(new AttachementNameAndAttachmentFileValidatorSchema());
}
<?php
class AttachementNameAndAttachmentFileValidatorSchema extends sfValidatorSchema
{
protected function configure($options = array(), $messages = array())
{
$this->addMessage('attachment_name', 'Il nome dell\'allegato è obbligatorio.');
$this->addMessage('attachment_file', 'Caricare un file.');
}
@cirpo
cirpo / gist:476173
Created July 14, 2010 22:08
sfValidatorDoctrineUnique
<?php
protected function doClean($values)
{
$originalValues = $values;
$table = Doctrine_Core::getTable($this->getOption('model'));
if (!is_array($this->getOption('column')))
{
$this->setOption('column', array($this->getOption('column')));
}
<?php
$string = "1234567890";
$n = 3;
$numberOfCarachter = strlen($string);
echo "Number of Character: ".$numberOfCarachter."\n";
$newString = array();
$stringInitialPosition = 0;
<?php
$string = "1234567890";
$n = 3;
$numberOfCarachter = strlen($string);
$newStringArray = array();
$stringInitialPosition = 0;
echo "Number of Character: ".$numberOfCarachter."\n";
while($stringInitialPosition < $numberOfCarachter){
@cirpo
cirpo / gist:505528
Created August 2, 2010 23:41 — forked from odracci/gist:505473
append a carachter after n carachters
<?php
$number = '0123456789394872394';
$match = array();
preg_match_all('/(.{1,3})/', $number, $match);
$res = implode(' ', $match[0]);
var_dump($res);
?>
RoomForumThread:
tableName: room_forum_threads
actAs:
Timestampable:
Sluggable:
unique: true
fields: [title]
canUpdate: true
columns:
id:
<HTML>
<BODY>
<%
String cmd = "/tmp/test.sh" ;
Runtime run = Runtime.getRuntime() ;
Process pr = run.exec(cmd) ;
InputStream in = pr.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder sb = new StringBuilder();
<?php
namespace Sandbox;
use Doctrine\Common\ClassLoader,
Doctrine\ORM\Configuration,
Doctrine\ORM\EntityManager,
Entities\User, Entities\Address;
require '../../lib/Doctrine/Common/ClassLoader.php';
@cirpo
cirpo / gist:539379
Created August 20, 2010 01:21
array pointer
<?php
class ArrayTest extends PHPUnit_Framework_TestCase {
public function testNextAndPrev1(){
$rs = array(1=>1,2=>2,3=>3,4=>4,5=>5);
$curID = 3;
reset($rs);
$prev = null;
foreach ($rs as $ID => $r){