在purrr中使用MASS :: stepAIC

时间:2019-04-04 21:09:33

标签: r dplyr glm purrr

我尝试将MASS :: stepAIC()函数应用于模型列表。我无法弄清楚使用purrr :: map()的工作原理。

<?php

namespace Esprit\LoisirBundle\Controller;

use Esprit\LoisirBundle\Entity\Livre;
use Esprit\LoisirBundle\Entity\Utilisateur;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

/**
 * Livre controller.
 *
 */
class LivreController extends Controller
{
    /**
     * Lists all livre entities.
     *
     */
    public function indexAction()
    {
        $em = $this->getDoctrine()->getManager();

        //$livres = $em->getRepository('EspritLoisirBundle:Livre')->findAll();
        $livres = $em->getRepository('EspritLoisirBundle:Livre')->findBy([], ['idLivre' => 'DESC']);

        return $this->render('livre/index.html.twig', array('livres' => $livres));
    }

    /**
     * Creates a new livre entity.
     *
     */
    public function newAction(Request $request)
    {
        /* ====== sesssion try */

        $user = $this->container->get('security.token_storage')->getToken()->getUser();
        $user1=new Utilisateur();
        $user1= $this->getDoctrine()->getRepository(Utilisateur::class) ->find($user->getId());

        /* ====== sesssion try */

        $livre = new Livre();
        $form = $this->createForm('Esprit\LoisirBundle\Form\LivreType', $livre);
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            /* ===== session */
            $livre->setIdUtilisateur($user1);
            /* ===== session */

            $em = $this->getDoctrine()->getManager();
            /* =====Image Up====== */
            $livre -> uploadPicture();
            /* =====Image Up====== */
            $em->persist($livre);
            $em->flush();

            return $this->redirectToRoute('livre_show', array('idLivre' => $livre->getIdlivre()));
        }

        return $this->render('livre/new.html.twig', array(
            'livre' => $livre,
            'form' => $form->createView(),
        ));
    }

    /**
     * Finds and displays a livre entity.
     *
     */
    public function showAction(Livre $livre)
    {
        $deleteForm = $this->createDeleteForm($livre);

        return $this->render('livre/show.html.twig', array(
            'livre' => $livre,
            'delete_form' => $deleteForm->createView(),
        ));
    }

    /**
     * Displays a form to edit an existing livre entity.
     *
     */
    public function editAction(Request $request, Livre $livre)
    {
        $deleteForm = $this->createDeleteForm($livre);
        $editForm = $this->createForm('Esprit\LoisirBundle\Form\LivreType', $livre);
        $editForm->handleRequest($request);

        if ($editForm->isSubmitted() && $editForm->isValid()) {
            $this->getDoctrine()->getManager()->flush();

            return $this->redirectToRoute('livre_edit', array('idLivre' => $livre->getIdlivre()));
        }

        return $this->render('livre/edit.html.twig', array(
            'livre' => $livre,
            'edit_form' => $editForm->createView(),
            'delete_form' => $deleteForm->createView(),
        ));
    }

    /**
     * Deletes a livre entity.
     *
     */
    public function deleteAction(Request $request, Livre $livre)
    {
        $form = $this->createDeleteForm($livre);
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $em->remove($livre);
            $em->flush();
        }

        return $this->redirectToRoute('livre_index');
    }

    /**
     * Creates a form to delete a livre entity.
     *
     * @param Livre $livre The livre entity
     *
     * @return \Symfony\Component\Form\Form The form
     */
    private function createDeleteForm(Livre $livre)
    {
        return $this->createFormBuilder()
            ->setAction($this->generateUrl('livre_delete', array('idLivre' => $livre->getIdlivre())))
            ->setMethod('DELETE')
            ->getForm()
        ;
    }

    public function showdetailedAction($id)
    {
        $em= $this->getDoctrine()->getManager();
        $liv=$em->getRepository('EspritLoisirBundle:Livre')->find($id);
        return $this->render('@EspritLoisir/Livre/detailedpost.html.twig', array(
            'libelle'=>$liv->getLibelle(),
            'description'=>$liv->getDescription(),
            'image'=>$liv->getImage(),
            'auteur'=>$liv->getAuteur(),
            'url'=>$liv->getUrl(),
            'type'=>$liv->getType(),
            'categorie'=>$liv->getCategorie(),
            //'posts'=>$liv,
            'comments'=>$liv,
            'idLivre'=>$liv->getIdLivre()
        ));
    }


    public function listlivreAction(Request $request)
    {
        $em=$this->getDoctrine()->getManager();
        $livres=$em->getRepository('EspritLoisirBundle:Livre')->findAll();
        return $this->render('livre/list.html.twig', array(
            "livres" =>$livres
        ));
    }

    public function searchAction(Request $request)
    {
        $em = $this->getDoctrine()->getManager();
        $requestString = $request->get('q');
        $livres =  $em->getRepository('EspritLoisirBundle:Livre')->findEntitiesByString($requestString);
        if(!$livres) {
            $result['posts']['error'] = "0 books given ";
        } else {
            $result['posts'] = $this->getRealEntities($livres);
        }
        return new Response(json_encode($result));
    }
    public function getRealEntities($livres){
        foreach ($livres as $livres){
            $realEntities[$livres->getIdLivre()] = [$livres->getImage(),$livres->getLibelle()];
        }
        return $realEntities;
    }
}


这会产生以下错误:

$('.star, .rating-well').click(labelWasClicked);
    $('.rating-well').each(turnStarBack);
    $('.rating-well').hover(turnToStar,turnStarBack);

在map函数中使用stepAIC函数的方式是什么?

0 个答案:

没有答案