Facebook just released Open Compute Project, their now-public datacenter and server design, optimized for situations in which hundreds or thousands of servers are needed such as the biggest websites and web-hosting companies.
The hardware is somewhat similar to what Google revealed in 2009, but with a different approach to battery backups, and the complete release of the formal design documents so that anyone else could, theoretically, copy Facebook’s design and potentially improve it
Check it Facebook’s Open Compute Project – Marco.org
Pages
Sunday, April 24, 2011
Wednesday, April 13, 2011
Calling ajax function when using form Widgets in doctrine and symfony1.4
Suppose you want to call a ajax function for a dropwon value changes
first define a dropdown in TblNameForm.class.php
$this->widgetSchema('myDropdown',array('label'=>'Drop Down','choices'=>array('Cars'=>'Cars','Bikes'='Bikes'),'onchange'=>'callajax(this.value,'automobileDiv')'));
In your template action class
$this->form = new TblNameForm();
In your template
$this->type = $this->requestParameter('type');
In automobilesSuccess.php
Because the url might change so that you need to change the path to the ajax file to work perfectly.
Hope this helps someone........
first define a dropdown in TblNameForm.class.php
$this->widgetSchema('myDropdown',array('label'=>'Drop Down','choices'=>array('Cars'=>'Cars','Bikes'='Bikes'),'onchange'=>'callajax(this.value,'automobileDiv')'));
In your template action class
$this->form = new TblNameForm();
In your template
<tr>
<td>
<?php echo $form['myDropdown']->renderLabel(); ?>
</td>
<td><?php echo $form['myDropdown']->render(); ?>
<div id='automobileDiv'></div></td>
</tr>
<script type="text/javascript">
function createInstance()
{
if (window.XMLHttpRequest)
{
req = new XMLHttpRequest();
}
else
alert("XHR not created");
return(req);
};
function callajax(val,div)
{
var req = createInstance();
req.onreadystatechange = function()
{
document.getElementById(div).value="Wait server...";
if(req.readyState == 4)
{
if(req.status == 200)
{
document.getElementById(div).innerHTML=req.responseText;
}
else
{
document.ajax.dyn.value="Error: returned status code " + req.status + " " + req.statusText;
}
}
};
req.open("GET", "formWidgets/automobiles?type="+val, true);
req.send(null);
}
</script>
In automobiles function in action class$this->type = $this->requestParameter('type');
In automobilesSuccess.php
<?php if($type=="Cars") { ?>
<select>
<option>BMW</option>
<option>RR</option>
<option>Benz</option>
</select>
<?php } else { ?>
<select>
<option>Pulsar</option>
<option>RR</option>
<option>BR</option>
</select>
<?php } ?>
Please double check the path to the ajax file in fresh page and after submitting the page with required error.Because the url might change so that you need to change the path to the ajax file to work perfectly.
Hope this helps someone........
Required Error does not appears next to field in symfony Doctrine formWidgets
If you are using form widgets and drawn the fields in the template using reder() function you might get this kind of error.ie required errors will not display.
If a form is submitted it will be validated but will not display error/required information in production and shows errors in debug toolbar in dev version then this would the solution use renderError to show the errors as this
<?php echo $form['name']->renderError(); ?>
<?php echo $form['name']->renderLabel(); ?>
<?php echo $form['name']->render(); ?>
Hope this helps someone.........
If a form is submitted it will be validated but will not display error/required information in production and shows errors in debug toolbar in dev version then this would the solution use renderError to show the errors as this
<?php echo $form['name']->renderError(); ?>
<?php echo $form['name']->renderLabel(); ?>
<?php echo $form['name']->render(); ?>
Hope this helps someone.........
_csrf_token required error in Symfony
When we are using formWidgets csrf_token required error occurs
There are certian reasons for that and have solutions for that
First we see when this error will occur
1. When you are using render function in your template
2. When you are adding an extra field
3. When you are changing the behaviour of the fields
4. When we are not binding the form
Solutions
1. When you are using render function in your template
use the below code in your template
<?php echo $form['_csrf_token']->renderLabel() ?>
<?php echo $form['_csrf_token']->render() ?>
afer that refresh the page and view the source code of the page it should have a hidden field called _csrf_token and the value should not be empty. Suppose if it is empty check the csrf token value in your setting.yml it should have some value.
After adding refresh and submit your page. Now it should not ask for _csrf_token required error. If it does then see for next possible solution
2. When you are adding an extra field
You might missed the validation for the field. Please add the validation
and check out this for adding a extra field.If the validations are correct and still the error occurs then see the next possible solution
3. When you are changing the behaviour of the fields
This is a rare condition which would occur. The situation is this ou have changed the bahaviour of the control/field in your template/form/base form class but validations may not match for the control you have modified. If so then _csrf_token error would occur. So please check it once again and check the next solution
4. When we are not binding the form
This would be the error we make most of the times. When we submit the form we should not directly save the form it should be binded and then it should be checked isvalid and then we have to save the form. Sample function to save a form could be like this
public function processForm($request sfWebRequest, $form sfForm,$redirect)
{
$form->bind(
$request->getRequestParameter($form->getName()),
$request->getRequestParameter($form->getFiles())
);
if($form->isValid())
{
$form->save();
$this->redirect($redirect);
}
}
Hope this helps someone.....
There are certian reasons for that and have solutions for that
First we see when this error will occur
1. When you are using render function in your template
2. When you are adding an extra field
3. When you are changing the behaviour of the fields
4. When we are not binding the form
Solutions
1. When you are using render function in your template
use the below code in your template
<?php echo $form['_csrf_token']->renderLabel() ?>
<?php echo $form['_csrf_token']->render() ?>
afer that refresh the page and view the source code of the page it should have a hidden field called _csrf_token and the value should not be empty. Suppose if it is empty check the csrf token value in your setting.yml it should have some value.
After adding refresh and submit your page. Now it should not ask for _csrf_token required error. If it does then see for next possible solution
2. When you are adding an extra field
You might missed the validation for the field. Please add the validation
and check out this for adding a extra field.If the validations are correct and still the error occurs then see the next possible solution
3. When you are changing the behaviour of the fields
This is a rare condition which would occur. The situation is this ou have changed the bahaviour of the control/field in your template/form/base form class but validations may not match for the control you have modified. If so then _csrf_token error would occur. So please check it once again and check the next solution
4. When we are not binding the form
This would be the error we make most of the times. When we submit the form we should not directly save the form it should be binded and then it should be checked isvalid and then we have to save the form. Sample function to save a form could be like this
public function processForm($request sfWebRequest, $form sfForm,$redirect)
{
$form->bind(
$request->getRequestParameter($form->getName()),
$request->getRequestParameter($form->getFiles())
);
if($form->isValid())
{
$form->save();
$this->redirect($redirect);
}
}
Hope this helps someone.....
Adding a extra field in formWidgets
Class files invloved
1. TblNameForm.class.php
//Adding an extra field ---here we are adding a text field
Inside the configure function inside TblNameForm.class.php add a field
$this->widgetSchema('extraField',new sfFormInputText(array('label'=>'My Extra Field')));
Now add a validation for the extra field
$this->setValidator('extraField',new sfValidatorString(array('max_length'=>255')
));
Int the BaseTblNameForm.class.php add
$this->validatorSchema->setOption('allow_extra_fields', true);
Thats it we have added a extra field, Last and final thing to do is drawing the field in the template
your templateSuccess.php
Thats it we have sucessfully added an extra field.
1. TblNameForm.class.php
//Adding an extra field ---here we are adding a text field
Inside the configure function inside TblNameForm.class.php add a field
$this->widgetSchema('extraField',new sfFormInputText(array('label'=>'My Extra Field')));
Now add a validation for the extra field
$this->setValidator('extraField',new sfValidatorString(array('max_length'=>255')
));
Int the BaseTblNameForm.class.php add
$this->validatorSchema->setOption('allow_extra_fields', true);
Thats it we have added a extra field, Last and final thing to do is drawing the field in the template
your templateSuccess.php
<?php echo $form['extraField']->renderLabel(); echo $form['extraField']->render(); ?>
Thats it we have sucessfully added an extra field.
Handling form widgets in Symfony1.4 With doctrine
When you are using formWidgets you might need to change in
1. BaseTblNameForm.class.php
2. TblNameForm.class.php
Let we see something detailed about these classes
1. BaseTblNameForm.class.php
This class contains a setup function which has
1. All the fileds that are in the table.
2. All the validations of the fields.
3. These class decides the basic bahaviour of the controls ie. input, select, etc,.
4. Basic Validation type can be changed here.
Uses of defining bahaviour of the controls in BaseTblName.class.php
1. When a form is drawn without any configuration then the default bahaviour is displayed.
eg. If you are using a filed gender and control you are using is a dropdown/Raido button, then we can change the behaviour in base class itself since it is not going to change for different templates.
2. TblNameForm.class.php
This is a class which extends BaseTblNameForm.
This class contains a configure function which contains
1. All the configurations of the fields
2. Controls bahaviour can be overwritten.
3. Controls or fields cna be unset here.
4. we can also specify the validations here also
5. Extra fields should be specified here with validations
Uses of defining behaviour of the controls in TblNameForm.class.php
1. We can change the dafult behaviour of the control.
2. Since the behaviour of the controls is overwritten you have to specify the validation schema too accordingly.
3. Adding an extra can be specified here with validation.
Hope this helps someone.........
1. BaseTblNameForm.class.php
2. TblNameForm.class.php
Let we see something detailed about these classes
1. BaseTblNameForm.class.php
This class contains a setup function which has
1. All the fileds that are in the table.
2. All the validations of the fields.
3. These class decides the basic bahaviour of the controls ie. input, select, etc,.
4. Basic Validation type can be changed here.
Uses of defining bahaviour of the controls in BaseTblName.class.php
1. When a form is drawn without any configuration then the default bahaviour is displayed.
eg. If you are using a filed gender and control you are using is a dropdown/Raido button, then we can change the behaviour in base class itself since it is not going to change for different templates.
2. TblNameForm.class.php
This is a class which extends BaseTblNameForm.
This class contains a configure function which contains
1. All the configurations of the fields
2. Controls bahaviour can be overwritten.
3. Controls or fields cna be unset here.
4. we can also specify the validations here also
5. Extra fields should be specified here with validations
Uses of defining behaviour of the controls in TblNameForm.class.php
1. We can change the dafult behaviour of the control.
2. Since the behaviour of the controls is overwritten you have to specify the validation schema too accordingly.
3. Adding an extra can be specified here with validation.
Hope this helps someone.........
Bind an interface to more than one class using Guice
Normally you can bind an interface to only one class. But this would not be enough for an application, because we want to use a same interface to bind with more than once class we can achieve this using BindingAnnotation in Guice. A more simplistic example here.
Subscribe to:
Comments (Atom)