Forums

Covering OroCommerce, OroCRM, OroPlatform topics, including community updates and company announcements.

Forums OroCommerce Unable to create and and edit tasks, giving error

This topic contains 5 replies, has 2 voices, and was last updated by  avinashingole417 3 days, 10 hours ago.

  • Creator
    Topic
  • #38103

    avinashingole417
    Participant

    Hi this is Avinash
    I have created entity and datagrid and all,now data is displaying in the grid then i moved to modify the task and i follwed the documentation and created the files
    but when i clicking on create new task button or edit button its giving error like this

    Error: Unexpected content format
    There was an error performing the requested operation. Please try again or contact us for assistance.

    my code is
    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)
    {
    $resolver->setDefaults(array(
    ‘data_class’=>’BlogBundle\Entity\Blog’,
    ));
    }
    }

    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;

    /**
    * @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”)
    */
    public function editAction(Blog $blog, Request $request)
    {
    return $this->update($blog, $request);
    }

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

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

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

    BlogBundle/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 blog variable #}
    {% set blog = form.vars.value %}

    {# choose the appropriate action depending on whether a blog 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’, { title: title }) %}
    {% 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 %}

    BlogBundle/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 %}

    BlogBundle/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

    /*please check my code and give me solution where iam wrong */

Viewing 5 replies - 1 through 5 (of 5 total)
  • Author
    Replies
  • #38108

    avinashingole417
    Participant

    Hi
    when i see errors in debug its showing like this

    CRITICAL 11:29:53 php Class ‘BlogBundle\Controller\BlogType’ not found

    CRITICAL 11:29:54 request Uncaught PHP Exception Symfony\Component\Debug\Exception\ClassNotFoundException: “Attempted to load class “BlogType” from namespace “BlogBundle\Controller”. Did you forget a “use” statement for another namespace?” at /usr/share/nginx/html/oroapp/src/BlogBundle/Controller/BlogController.php line 48

    please give me solution what i missed
    above is my code

    #38110
    Michael
    Michael
    Keymaster

    The error message actually explains exactly what you missed – you forgot to add “use BlogBundle\Form\BlogType;” at the beginning of your controller class.

    #38111

    avinashingole417
    Participant

    Hi michael
    hi have givean same what you said then also its giving error like below

    CRITICAL 12:08:58 request Uncaught PHP Exception Symfony\Component\Form\Exception\UnexpectedTypeException: “Expected argument of type “string”, “BlogBundle\Form\BlogType” given” at /usr/share/nginx/html/oroapp/vendor/symfony/symfony/src/Symfony/Component/Form/FormFactory.php line 55

    #38114
    Michael
    Michael
    Keymaster

    https://api.symfony.com/3.4/Symfony/Bundle/FrameworkBundle/Controller/Controller.html#method_createForm
    Parameters
    string $type The fully qualified class name of the form type

    $this->createForm(new BlogType(), ... -> $this->createForm(BlogType::class, ...

    #38149

    avinashingole417
    Participant

    Now Errors Gone.
    But when i click on create new blog button its opening form to fill details but when i click on save and close button its not creating new one and for edit also its happening same, details are displaying in form but when i edit it and save its not updating. Where i am wrong.Above is my code

Viewing 5 replies - 1 through 5 (of 5 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