OroCommerce Forums

Covering OroCommerce topics, including community updates and company announcements.

Forums OroCommerce Data is not able to edit or create new

This topic contains 1 reply, has 2 voices, and was last updated by Andrey Yatsenko Andrey Yatsenko 3 weeks, 6 days ago.

  • Creator
    Topic
  • #38163

    Ingole Avinash
    Participant

    Hi

    I have created one bundle then i created entities and loaded data fixtures then i moved to modify task concept but i am failed to edit and create new
    code is below

    src/BlogBundle/controller/BlogController.php
    <?php
    namespace BlogBundle\Controller;

    use BlogBundle\Entity\Blog;
    use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
    use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
    use Symfony\Bundle\FrameworkBundle\Controller\Controller;
    use Symfony\Component\HttpFoundation\Request;
    use BlogBundle\Form\BlogType;

    /**
    * @Route(“/blog”)
    */
    class BlogController extends Controller
    {
    /**
    * @Route(“/he”, name=”app_blog_index”)
    * @Template()
    */
    public function indexAction()
    {
    return array();
    }

    /**
    * @Route(“/create”, name=”app_blog_create”)
    * @Template(“BlogBundle:Blog:update.html.twig”)
    */
    public function createAction(Request $request)
    {
    return $this->update(new Blog(), $request);
    }

    /**
    * @Route(“/edit/{id}”,name=”app_blog_update”, requirements={“id”=”\d+”})
    * @Template(“BlogBundle:Blog:update.html.twig”)
    * @param Blog $blog
    * @param Request $request
    * @return array
    */

    public function editAction(Blog $blog,Request $request)
    {
    return $this->update($blog, $request);
    }

    private function update(Blog $blog, Request $request)
    {
    $form = $this->createForm(BlogType ::class, $blog);

    return array(
    ‘entity’ => $blog,
    ‘form’ => $form->createView(),
    );
    }

    }

    BlogBundle/Entity/Blog.php
    <?php
    namespace BlogBundle\Entity;

    use\Doctrine\ORM\Mapping as ORM;

    /**
    * @ORM\Entity()
    * @ORM\Table(name=”Blog”)
    */

    class Blog
    {
    /**
    * @ORM\Id()
    * @ORM\GeneratedValue(strategy=”AUTO”)
    * @ORM\Column(type=”integer”)
    *
    * @var int
    */
    private $id;

    /**
    * @ORM\Column(type=”string”)
    *
    * @var string
    */
    private $name;

    /**
    * @ORM\Column(type=”string”)
    *
    * @var string
    */
    private $sirname;

    /**
    * Returns the id.
    *
    * @return int
    */
    public function getId()
    {
    return $this->id;
    }

    /**
    * Return the name
    * @return string
    */
    public function getName()
    {
    return $this->name;
    }

    /**
    * @param string $name
    */
    public function setName($name)
    {
    $this->name = $name;
    }

    /**
    * @return string
    */
    public function getSirname()
    {
    return $this->sirname;
    }
    /** Return the sirname
    * @param string $sirname
    */
    public function setSirname($sirname)
    {
    $this->sirname = $sirname;
    }
    }

    BlogBundle/Form/BlogType.php

    <?php
    namespace BlogBundle\Form;

    use Symfony\Component\Form\AbstractType;
    use Symfony\Component\Form\FormBuilderInterface;
    use Symfony\Component\OptionsResolver\OptionsResolver;

    class BlogType extends AbstractType
    {
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
    parent::buildForm($builder, $options); // TODO: Change the autogenerated stub

    $builder
    ->add(‘name’)
    ->add(‘sirname’);
    }

    public function configureOptions(OptionsResolver $resolver)
    {
    parent::configureOptions($resolver); // TODO: Change the autogenerated stub

    $resolver->setDefaults(array(
    ‘data_class’=> ‘BlogBundle\Entity\Blog’,
    ));
    }
    }

    BlogBundle/Data/ORM/LoadBlog.php

    <?php
    namespace BlogBundle\Form;

    use Symfony\Component\Form\AbstractType;
    use Symfony\Component\Form\FormBuilderInterface;
    use Symfony\Component\OptionsResolver\OptionsResolver;

    class BlogType extends AbstractType
    {
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
    parent::buildForm($builder, $options); // TODO: Change the autogenerated stub

    $builder
    ->add(‘name’)
    ->add(‘sirname’);
    }

    public function configureOptions(OptionsResolver $resolver)
    {
    parent::configureOptions($resolver); // TODO: Change the autogenerated stub

    $resolver->setDefaults(array(
    ‘data_class’=> ‘BlogBundle\Entity\Blog’,
    ));
    }
    }

    Resources/config/oro/datagrids.yml
    datagrids:
    app-blogs-grid:
    source:
    type: orm
    query:
    select:
    – blog.id
    – blog.name
    – blog.sirname
    from:
    – { table: BlogBundle:Blog, alias: blog}

    columns:
    id:
    label: ID
    frontend_type: integer
    name:
    label: Name
    sirname:
    label: Sirname

    sorters:
    columns:
    id:
    data_name: blog.id
    name:
    data_name: blog.name
    sirname:
    data_name: blog.sirname

    filters:
    columns:
    id:
    type: number
    data_name: blog.id
    name:
    type: string
    data_name: blog.name
    sirname:
    type: string
    data_name: blog.sirname
    # …
    properties:
    id: ~
    update_link:
    type: url
    route: app_blog_update
    params:
    – id

    actions:
    # …
    edit:
    type: navigate
    label: Edit
    link: update_link
    icon: edit

    Resources/config/oro/navigation.yml
    menu_config:
    items:
    task_list:
    label: Blogs
    route: app_blog_index
    tree:
    application_menu:
    children:
    task_list: ~
    Resources/config/oro/routing.yml
    blog:
    resource: “@BlogBundle/Controller/”
    type: annotation
    prefix: /

    Resources/config/routing.yml
    blog_blog:
    resource: ‘@BlogBundle/Controller/BlogController.php’
    type: annotation

    Resources/views/Blog/index.html.twig

    {% extends ‘OroUIBundle:actions:index.html.twig’ %}

    {% set gridName = ‘app-blogs-grid’ %}
    {% set pageTitle = ‘Blog’ %}

    {% block navButtons %}
    <div class=”btn-group”>
    {{ UI.addButton({
    ‘path’: path(‘app_blog_create’),
    ‘entity_label’: ‘a Blog’,
    }) }}
    </div>
    {% endblock %}

    Resources/views/Blog/update.html.twig

    {# extend the base template from the OroUIBundle #}
    {% extends ‘OroUIBundle:actions:update.html.twig’ %}

    {# reuse the form theme provided with OroPlatform #}
    {% form_theme form with ‘OroFormBundle:Form:fields.html.twig’ %}

    {# make the current task accessible with the task variable #}
    {% set blog = form.vars.value %}

    {# choose the appropriate action depending on whether a task is created or modified #}
    {# this variable needs to be named formAction as this is what the base template expects #}
    {% if blog.id %}
    {% set formAction = path(‘app_blog_update’, { ‘id’: blog.id }) %}
    {% else %}
    {% set formAction = path(‘app_blog_create’) %}
    {% endif %}

    {% block navButtons %}
    {# the cancelButton() macro creates a button that discards the
    entered data and leads the user to the linked controller #}
    {{ UI.cancelButton(path(‘app_blog_index’)) }}

    {# the dropdownSaveButton() macro offers a way to let the user select
    between different options when saving an entity, the selected option
    will be passed to the controller handling the request as an additonal
    parameter #}
    {{ UI.dropdownSaveButton({
    ‘html’: UI.saveAndCloseButton() ~ UI.saveAndStayButton()
    }) }}
    {% endblock navButtons %}

    {% block pageHeader %}
    {% if blog.id %}
    {% set breadcrumbs = {
    ‘entity’: blog,
    ‘indexPath’: path(‘app_blog_index’),
    ‘indexLabel’: ‘Blogs’,
    ‘entityTitle’: blog.name
    } %}
    {{ parent() }}
    {% else %}
    {% set title = ‘oro.ui.create_entity’|trans({ ‘%entityName%’: ‘Blog’ }) %}
    {% include(‘OroUIBundle::page_title_block.html.twig’) %}
    {% endif %}
    {% endblock pageHeader %}

    {% block content_data %}
    {% set id = ‘blog-edit’ %}
    {% set dataBlocks = [{
    ‘title’: ‘General’|trans,
    ‘class’: ‘active’,
    ‘subblocks’: [{
    ‘title’: ”,
    ‘data’: [
    form_row(form.name),
    form_row(form.sirname),

    ]
    }]
    }]
    %}

    {# the data variable is a special variable that is used in the
    parent content_data block to render the visual content “blocks”
    of a page#}
    {% set data = {
    ‘formErrors’: form_errors(form) ? form_errors(form) : null,
    ‘dataBlocks’: dataBlocks,
    } %}

    {{ parent() }}
    {% endblock content_data %}

    Please check what i am missing. for new create and edit form coming but its not creating new one and not able to update

Viewing 1 replies (of 1 total)
  • Author
    Replies
  • #38206
    Andrey Yatsenko
    Andrey Yatsenko
    Moderator

    Please share the code as a gist snipet or at list format it as a code in the wysiwyg editor on forum. It’s hard to read such a big listing.
    Thank you.

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.

You will be redirected to [title]. Would you like to continue?

Yes No
sso for www.magecore.comsso for oroinc.comsso for oroinc.desso for oroinc.fr