0
votes

I'm working on a symfony site and it continue to goes down almost every day so I have to clear the cache and chmod all cache folder content to solve the problem.
Clearing the cache is the quick solution that I had but sometimes it doesn't do the job.
Also I figured that the site doesn't completely crash,it still working for some user but not for others (they call me to fix the problem but when I access the site it work for me)
In the prod log file I get an error that I do not understand:

[2015-10-08 16:43:18] request.INFO: Matched route "product". {"route_parameters":{"_controller":"FM\FmBundle\Controller\HomeController::productAction","_route":"product"},"request_uri":"https://first1-market.com/product/puma-pu102601002u"} []
[2015-10-08 16:43:18] security.INFO: Populated the TokenStorage with an anonymous Token. [] []
[2015-10-08 16:43:18] request.CRITICAL: Uncaught PHP Exception RuntimeException: "Controller "FM\FmBundle\Controller\HomeController::productAction()" requires that you provide a value for the "$product_slug" argument (because there is no default value or because there is a non optional argument after this one)." at /home/firstmarlo/app/cache/prod/classes.php line 2595 {"exception":"[object] (RuntimeException(code: 0): Controller \"FM\FmBundle\Controller\HomeController::productAction()\" requires that you provide a value for the \"$product_slug\" argument (because there is no default value or because there is a non optional argument after this one). at /home/firstmarlo/app/cache/prod/classes.php:2595)"} []

the product route

product:
    path:     /product/{product_slug}
    defaults: { _controller: FMFmBundle:Home:product }

the product Action

public function productAction($product_slug)
    {
        $product=$this->getDoctrine()->getEntityManager()->getRepository('FMFmBundle:Products')->findOneBy(array('slug'=>$product_slug));
        $collection=$product->getCategory()->getCollection();
        return $this->render('FMFmBundle:Product:index.html.twig',array('product'=>$product,'color'=>$collection->getColor()));
    }

the link to this action

{% for product in FmarketProductService.getRecommanded() %}
<a href="{{  url('product',{'product_slug': product.slug})}}">

this work fine but I don't Know why I'm getting this error in the log file and why the site goes done
Any idea or a workaround to solve this problem?

1
very quick and dirty solution to hide that error (or prevent to go down), can be set a default value (may be like public function productAction($product_slug = null)) then check and return something if it receives null.xurshid29

1 Answers

1
votes

Problem is that somewhere in entity record ,there is no slug generated . I got the same issue when i worked with imported data from legacy project.

The best idea was to create command that regenerates slugs .

look at http://symfony.com/doc/current/components/console/introduction.html

In my command i did something like that

$em = $this->getContainer()->get('doctrine')->getManager();
    $pages=$em->getRepository('PoznetAdminBundle:page')->findAll();
        $ile=count($pages);
        for($i=0;$i<$ile;$i++){
             $pages[$i]->setSlug($pages[$i]->getTitle());
        }
    $em->flush();

my slugs are based on title field