Skip to content

Instantly share code, notes, and snippets.

View redleafar's full-sized avatar
🎯
Focusing

Rafael Bermúdez redleafar

🎯
Focusing
  • Globant
  • Bogotá, Colombia
View GitHub Profile
@redleafar
redleafar / custom_query_sonata_type_model.md
Created October 24, 2016 00:44
Custom query for sonata_type_model
protected function configureFormFields(FormMapper $formMapper)
{
    $em = $this->modelManager->getEntityManager('MyBundle\Entity\Categoria');

    $query = $em->createQuery('SELECT b FROM MyBundle:Categoria b WHERE b.name = :name');
	
    $query->setParameter('name', 'name_of_categoria');
    
 $formMapper
@redleafar
redleafar / get_user_from_admin.md
Created October 13, 2016 01:39
Get logged user from Admin
$user = $this->getConfigurationPool()->getContainer()->get('security.token_storage')->getToken()->getUser();
@redleafar
redleafar / upload_image_register.md
Last active October 10, 2016 00:37
Upload image in register

Follow this guide: http://symfony.com/doc/current/controller/upload_file.html There is no problem using the same file field, that I use for the sonata admin guide. This allows in theory separate all the upload code from the entity code, but it didn't work in sonata admin, so I'll have to look for a complement to this.

@redleafar
redleafar / acl_edit_own_objects.md
Created September 19, 2016 00:03
Let Sonata admin users only edit entities they own
@redleafar
redleafar / composer_php_override_error.md
Created September 18, 2016 19:33
Your PHP version (5.6.18) overriden by “config.platform.php” version (5.3.9) does not satisfy requirement

Look in composer for:

"config": {
   "preferred-install": "dist",
   "platform": {
       "php": "5.3.9"
   }
}
@redleafar
redleafar / array_adapter.md
Last active September 17, 2016 22:53
Change list dynamically
package in.wptrafficanalyzer.additemsdynamically;
 
import java.util.ArrayList;
 
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
@redleafar
redleafar / get_request_parameter.md
Last active October 31, 2016 14:39
Get parameters of a get request in a controller

If is just a parameter use:

$page = $request->query->get('page');

If you have to get a form value do this (pais is a field of the form):

$data = $formtest->getData();
@redleafar
redleafar / edittext_textarea.md
Last active September 15, 2016 18:54
EditText as TextArea

In the layout:

<EditText
    android:id="@+id/textArea_information"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@null"
    android:gravity="top|left"
@redleafar
redleafar / recycler_view_onclick.md
Created September 14, 2016 22:30
Set a click listener on a RecyclerView

Source: http://antonioleiva.com/recyclerview-listener/

If you’ve used a RecyclerView, you may know that they don’t have a setOnItemClickListener as ListView had, so we have to create our own way to do it. Many people asked me how to do this, so that’s why I decided to write about it. There are many ways to achieve this, but I will show you the way I usually do it. My mechanism consists of passing the listener as a parameter to the constructor and then assign it when I bind the data to the view in onBindViewHolder. You’ll first need an interface that specifies listener’s behaviour. In this example, there is a sample model called ContentItem, so the click will return an item of that type:

public interface OnItemClickListener {
    void onItemClick(ContentItem item);
}
@redleafar
redleafar / change_checkbox_image.md
Created September 14, 2016 19:45
Change icons checkbox depending of its states

In the layout:

<CheckBox android:layout_width="wrap_content"
 android:layout_height="wrap_content" 
 android:text="new checkbox"
 android:background="@drawable/checkbox_background" 
 android:button="@drawable/checkbox" />

Where @drawable/checkbox is: