我正在使用 symfony2.16 中产品的 id 更新值,也使用 MngoDBbundle
但我收到这样的错误
在第 1 行的 AcmeStoreBundle:Default:index.html.twig 中,在渲染模板期间抛出了异常(““acme_store_update”路由缺少一些必需参数(“id”)。)。
这是我的控制器,请检查更新操作
<?php
namespace Acme\StoreBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Acme\StoreBundle\Document\Product;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
class DefaultController extends Controller
{
/**
* @Route("/hello/{name}")
* @Template()
*/
public function indexAction($name)
{
return array('name' => $name);
}
// ...
/**
* @Route("/create", name="acme_store_create")
* @Template()
*/
public function createAction(Request $request)
{
$product = new Product();
//$product->setName('apple');
//$product->setPrice('19.99');
$form = $this->createFormBuilder($product)
->add('name', 'text')
->add('price', 'text')
->getForm();
if ($request->getMethod() == 'POST') …Run Code Online (Sandbox Code Playgroud) 我的symfony网站需要一个cron作业.我在http://symfony.com/doc/2.1/cookbook/console/console_command.html找到了创建控制台命令的教程
我的命令.php
namespace xxx\WebBundle\Command;
使用Symfony\Component\Console\Command\Command; 使用Symfony\Component\Console\Input\InputArgument; 使用Symfony\Component\Console\Input\InputInterface; 使用Symfony\Component\Console\Input\InputOption; 使用Symfony\Component\Console\Output\OutputInterface;
class GreetCommand extends Command {protected function configure(){
Run Code Online (Sandbox Code Playgroud)} protected function execute(InputInterface $input, OutputInterface $output) { $em = $this->getContainer()->get('doctrine')->getManager(); $em->getRepository('xxxWebBundle:Wishlist')->findAll(); // $output->writeln($text); }}
当我在控制台中调用命令时,收到错误"调用未定义的方法xxxx\WebBundle\Command\MyCommand :: getContainer()"如何在执行函数中获取文档管理器?
我正在使用命令类发送cron邮件.如何设置发送电子邮件的区域设置?
$this->getRequest()->setLocale('de');
Run Code Online (Sandbox Code Playgroud)
在我的情况下,每个用户都有不同的区域设置 如何在命令类中设置语言环境?
我试过$this->getRequest()->setLocale('de');并收到错误:
namespace IT\bBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class CronCommand extends ContainerAwareCommand {
protected function configure()
{
$this
->setName('send:emails')
->setDescription('Envio programado de emails');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$message = \Swift_Message::newInstance()
->setSubject('bla bla')
->setFrom('x@x.com')
->setTo('x@gmail.com')
->setCharset('UTF-8')
->setContentType('text/html')
->setBody($this->renderView('mainBundle:Email:default.html.twig'));
$this->getContainer()->get('mailer')->send($message);
$output->writeln('Enviado!');
} }
Run Code Online (Sandbox Code Playgroud) symfony-2.1 ×3