Question

I have a route in symfony2

evr_admin_languages:
    pattern:  /admin/languages/{page}
    defaults: { _controller: EvrAdminBundle:Languages:index , page: 1 }

As you can see, page argument is set to a default value '1'.

So this controller must be working without any errors

      public function indexAction($page) {
            $query = $this->getDoctrine()->getManager()
//...

And that's what's happening in app_dev.php, but not the same for the app.php, which returns a 500 Error.

Here's my prod.log file:

[2014-01-26 12:39:08] request.CRITICAL: Uncaught PHP Exception RuntimeException: "Controller "Evr\AdminBundle\Controller\LanguagesController::indexAction()" **requires that you provide a value for the "$page" argument (because there is no default value or because there is a non optional argument after this one)."** at D:\Sources\symfera\app\cache\prod\classes.php line 2075 {"exception":"[object] (RuntimeException: Controller \"Evr\\AdminBundle\\Controller\\LanguagesController::indexAction()\" requires that you provide a value for the \"$page\" argument (because there is no default value or because there is a non optional argument after this one). at D:\\Sources\\symfera\\app\\cache\\prod\\classes.php:2075)"} []

So, I tested the prod result with adding a default argument value to the indexAction() controller:

 public function indexAction($page = 1) {

And, as expected .. it works now, But the prod version is not updated to the current update I have on the dev_app.php.

So, I run cache:clear --env-prod , assets:install --env-prod, assetic:dump --env-prod and nothing happened.

Is there something I missed?

EDIT Actually, I didn't pay attention to the command prompt error message when trying to run the command php app/console cache:clear --env=prod , this is the error message :

 The type hint of parameter "category" in method "setCategory" in class "Evr
 \HomeBundle\Entity\Category" is invalid.

 [ReflectionException]
 Class varchar does not exist

Note I posted the Routing issue, with what it seems to be a cache issue, because I think they're related.

EDIT 2 This is my Category Entity, notice that there's no error in Dev mode when clearing the cache, My Entity is automatically generated using ORM Doctrine.

<?php

namespace Evr\HomeBundle\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;

/**
 * Category
 *
 * @ORM\Table(name="ev_category")
 * @ORM\Entity
 */
class Category
{
    /**
     * @var integer
     *
     * @ORM\Column(name="category_id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

     /**
     * 
     * @ORM\ManyToOne(targetEntity="Language",inversedBy="categories")
     * @ORM\JoinColumn(name="language_id",referencedColumnName="id")
     */
    private $language;

    /**
     * @var varchar
     *
     * @ORM\Column(name="category", type="varchar", length=255)
     */
    private $category;

    /**
     * @ORM\OneToMany(targetEntity="Subcategory", mappedBy="category")
     */
    protected $subcategories;

    public function __construct(){
        $this->subcategories=new ArrayCollection();
    }

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

    /**
     * Set category
     *
     * @param \varchar $category
     * @return Category
     */
    public function setCategory(\varchar $category)
    {
        $this->category = $category;

        return $this;
    }

    /**
     * Get category
     *
     * @return \varchar 
     */
    public function getCategory()
    {
        return $this->category;
    }
}
Was it helpful?

Solution

I don't have enough reputation to comment, but I'll try here.

Your function is ok:

public function indexAction($page) {
            $query = $this->getDoctrine()->getManager()
//...

But when you call it you have to provide it &page.

If you get error clearing the cache, of course you don't clear the cache! So the problem is different and is in your entity. Show it.

UPDATE

Actually I'm very new of Symfony and php, but reading the error seems that Symfony doesn't recognize the "varchar" type. I would try erasing \varchar in the setCategory function and annotation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top