【发布时间】:2023-03-12 22:18:01
【问题描述】:
我在 symfony2 中有一条路线
evr_admin_languages:
pattern: /admin/languages/{page}
defaults: { _controller: EvrAdminBundle:Languages:index , page: 1 }
如您所见,页面参数设置为默认值“1”。
所以这个控制器必须工作没有任何错误
public function indexAction($page) {
$query = $this->getDoctrine()->getManager()
//...
这就是 app_dev.php 中发生的情况,但 app.php 中的情况不同,它返回 500 错误。
这是我的 prod.log 文件:
[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)"} []
所以,我通过向 indexAction() 控制器添加默认参数值来测试 prod 结果:
public function indexAction($page = 1) {
而且,正如预期的那样......它现在可以工作了,但是 prod 版本没有更新到我在 dev_app.php 上的当前更新。
所以,我运行cache:clear --env-prod、assets:install --env-prod、assetic:dump --env-prod,但什么也没发生。
我错过了什么吗?
EDIT其实我在尝试运行命令php app/console cache:clear --env=prod时并没有注意命令提示错误信息,这是错误信息:
The type hint of parameter "category" in method "setCategory" in class "Evr
\HomeBundle\Entity\Category" is invalid.
[ReflectionException]
Class varchar does not exist
请注意,我发布了路由问题,似乎是缓存问题,因为我认为它们是相关的。
EDIT 2这是我的Category Entity,注意在Dev模式下清除缓存没有错误,My Entity是使用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;
}
}
【问题讨论】:
-
我不确定,但你的索引函数不应该是这样的
indexAction($page)吗? -
对不起,我发错了..不是在我自己的代码中。因为我仍在使用
indexAction($page = 1)...所以发布它,我删除了整个东西。即使是indexAction($page)...它也会变成 500 错误
标签: php symfony routing production-environment