Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8209989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:55:28+00:00 2026-06-07T09:55:28+00:00

I have an Entity in Symfony called Ip and I save my IP address

  • 0

I have an Entity in Symfony called Ip and I save my IP address as integer – I use the IP as primary key, too.

But when I display and enter the IP in a form or list I want to convert it to a IP, e.g. 127.0.0.1 is saved as 2130706433.

I created the forms with the CRUD generator.

My entity comes here:

<?php

namespace IS\ClearanceBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * IS\ClearanceBundle\Entity\Ip
*/
class Ip
{
/**
 * @var bigint $ip
 */
private $ip;

/**
 * @var integer $high
 */
private $high;

/**
 * @var string $hoster
 */
private $hoster;

/**
 * @var datetime $scandate
 */
private $scandate;

/**
 * @var integer $id
 */
private $id;

/**
 * @var IS\ClearanceBundle\Entity\Clearance
 */
private $clearance;

public function __construct()
{
    $this->clearance = new \Doctrine\Common\Collections\ArrayCollection();
}

/**
 * Set ip
 *
 * @param bigint $ip
 */
public function setIp($ip)
{
    $this->ip = $ip;
}


/**
 * Get ip
 *
 * @return bigint
 */
public function getIp()
{
    return $this->ip;
}


/**
 * Set high
 *
 * @param integer $high
 */
public function setHigh($high)
{
    $this->high = $high;
}

/**
 * Get high
 *
 * @return integer
 */
public function getHigh()
{
    return $this->high;
}

/**
 * Set hoster
 *
 * @param string $hoster
 */
public function setHoster($hoster)
{
    $this->hoster = $hoster;
}

/**
 * Get hoster
 *
 * @return string
 */
public function getHoster()
{
    return $this->hoster;
}

/**
 * Set scandate
 *
 * @param datetime $scandate
 */
public function setScandate($scandate)
{
    $this->scandate = $scandate;
}

/**
 * Get scandate
 *
 * @return datetime
 */
public function getScandate()
{
    return $this->scandate;
}

/**
 * Get id
 *
 * @return integer
 */
public function getId()
{
    return $this->id;
}

/**
 * Add clearance
 *
 * @param IS\ClearanceBundle\Entity\Clearance $clearance
 */
public function addClearance(\IS\ClearanceBundle\Entity\Clearance $clearance)
{
    $this->clearance[] = $clearance;
}

/**
 * Get clearance
 *
 * @return Doctrine\Common\Collections\Collection
 */
public function getClearance()
{
    return $this->clearance;
}
}

And here is my Controller:

<?php

namespace IS\ClearanceBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use IS\ClearanceBundle\Entity\Ip;
use IS\ClearanceBundle\Form\IpType;

/**
* Ip controller.
*
* @Route("/ip")
*/
class IpController extends Controller
{
/**
 * Lists all Ip entities.
 *
 * @Route("/", name="ip")
 * @Template()
 */
public function indexAction()
{
    $em = $this->getDoctrine()->getEntityManager();

    $entities = $em->getRepository('ISClearanceBundle:Ip')->findAll();

    return array('entities' => $entities);
}

/**
 * Finds and displays a Ip entity.
 *
 * @Route("/{id}/show", name="ip_show")
 * @Template()
 */
public function showAction($id)
{
    $em = $this->getDoctrine()->getEntityManager();

    $entity = $em->getRepository('ISClearanceBundle:Ip')->find($id);

    if (!$entity) {
        throw $this->createNotFoundException('Unable to find Ip entity.');
    }

    $deleteForm = $this->createDeleteForm($id);

    return array(
        'entity'      => $entity,
        'delete_form' => $deleteForm->createView(),        );
}

/**
 * Displays a form to create a new Ip entity.
 *
 * @Route("/new", name="ip_new")
 * @Template()
 */
public function newAction()
{
    $entity = new Ip();
    $form   = $this->createForm(new IpType(), $entity);

    return array(
        'entity' => $entity,
        'form'   => $form->createView()
    );
}

/**
 * Creates a new Ip entity.
 *
 * @Route("/create", name="ip_create")
 * @Method("post")
 * @Template("ISClearanceBundle:Ip:new.html.twig")
 */
public function createAction()
{
    $entity  = new Ip();
    $request = $this->getRequest();
    $form    = $this->createForm(new IpType(), $entity);
    $form->bindRequest($request);

    if ($form->isValid()) {
        $em = $this->getDoctrine()->getEntityManager();
        $em->persist($entity);
        $em->flush();

        return $this->redirect($this->generateUrl('ip_show', array('id' => $                                                                            entity->getId())));

    }

    return array(
        'entity' => $entity,
        'form'   => $form->createView()
    );
}

/**
 * Displays a form to edit an existing Ip entity.
 *
 * @Route("/{id}/edit", name="ip_edit")
 * @Template()
 */
public function editAction($id)
{
    $em = $this->getDoctrine()->getEntityManager();

    $entity = $em->getRepository('ISClearanceBundle:Ip')->find($id);

    if (!$entity) {
        throw $this->createNotFoundException('Unable to find Ip entity.');
    }

    $editForm = $this->createForm(new IpType(), $entity);
    $deleteForm = $this->createDeleteForm($id);

    return array(
        'entity'      => $entity,
        'edit_form'   => $editForm->createView(),
        'delete_form' => $deleteForm->createView(),
    );
}

/**
 * Edits an existing Ip entity.
 *
 * @Route("/{id}/update", name="ip_update")
 * @Method("post")
 * @Template("ISClearanceBundle:Ip:edit.html.twig")
 */
public function updateAction($id)
{
    $em = $this->getDoctrine()->getEntityManager();

    $entity = $em->getRepository('ISClearanceBundle:Ip')->find($id);

    if (!$entity) {
        throw $this->createNotFoundException('Unable to find Ip entity.');
    }

    $editForm   = $this->createForm(new IpType(), $entity);
    $deleteForm = $this->createDeleteForm($id);

    $request = $this->getRequest();

    $editForm->bindRequest($request);

    if ($editForm->isValid()) {
        $em->persist($entity);
        $em->flush();

        return $this->redirect($this->generateUrl('ip_edit', array('id' => $                                                                            id)));
    }

    return array(
        'entity'      => $entity,
        'edit_form'   => $editForm->createView(),
        'delete_form' => $deleteForm->createView(),
    );
}

/**
 * Deletes a Ip entity.
 *
 * @Route("/{id}/delete", name="ip_delete")
 * @Method("post")
 */
public function deleteAction($id)
{
    $form = $this->createDeleteForm($id);
    $request = $this->getRequest();

    $form->bindRequest($request);

    if ($form->isValid()) {
        $em = $this->getDoctrine()->getEntityManager();
        $entity = $em->getRepository('ISClearanceBundle:Ip')->find($id);

        if (!$entity) {
            throw $this->createNotFoundException('Unable to find Ip entity.'                                                                            );
        }

        $em->remove($entity);
        $em->flush();
    }

    return $this->redirect($this->generateUrl('ip'));
}

private function createDeleteForm($id)
{
    return $this->createFormBuilder(array('id' => $id))
        ->add('id', 'hidden')
        ->getForm()
    ;
}
}

And here the form:

 <?php

 namespace IS\ClearanceBundle\Form;

 use Symfony\Component\Form\AbstractType;
 use Symfony\Component\Form\FormBuilder;

 class IpType extends AbstractType
 {
 public function buildForm(FormBuilder $builder, array $options)
 {
    $builder
        ->add('ip')
        ->add('high')
        ->add('hoster')
        ->add('scandate')
        ->add('clearance','entity', array('class'=>'IS\ClearanceBundle\Entity\Clearance', 'property'=>'id','required'=>false, 'multiple'=>true))
    ;
}

public function getName()
{
    return 'is_clearancebundle_iptype';
}
}

Thanks for any help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T09:55:31+00:00Added an answer on June 7, 2026 at 9:55 am

    IMO if you want do it, you should use data transformer http://symfony.com/doc/current/cookbook/form/data_transformers.html and implement __toString for your entity IP.

    EDIT:

    Created sample at gist: https://gist.github.com/3086241

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I use two different tables for one entity in Symfony? I have
I am trying to use Symfony 2 security component, but I have a problem
I have a form type in symfony2 : namespace Acme\SomethingBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilder;
Symfony Docs say that we can use birthday date in forms. but they have
I have a entity called Container in a Symfony application, which I have included
I am using Symfony 2 with doctrine. I currently have an entity called Worker
I have some form, and one column have Entity type, but this entity have
I have this entity: <?php namespace Comakai\MyBundle\Entity; use Doctrine\ORM\Mapping as ORM, Symfony\Component\Validator\Constraints as Assert;
In my Symfony 2 project, I have a page displaying information about an entity.
How to use related select boxes in Symfony ? Let's say, I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.