SplFileObject错误无法打开流:没有这样的文件或目录

SplFileObject错误无法打开流:没有这样的文件或目录

问题描述:

我正在尝试在symfony2中实现存折Web服务,并遵循此存折包,我的控制器看起来像这样

i am trying to implement passbook web service in symfony2 and following this passbook bundle and my controller looks like this

if ($form->isValid()) {
        // Create an event ticket
        $pass = new EventTicket("1234567890", "The Beat Goes On");
        $pass->setBackgroundColor('rgb(60, 65, 76)');
        $pass->setLogoText('Apple Inc.');

        // Create pass structure
        $structure = new Structure();

        // Add primary field
        $primary = new Field('event', 'The Beat Goes On');
        $primary->setLabel('Event');
        $structure->addPrimaryField($primary);

        // Add secondary field
        $secondary = new Field('location', 'Moscone West');
        $secondary->setLabel('Location');
        $structure->addSecondaryField($secondary);

        // Add auxiliary field
        $auxiliary = new Field('datetime', '2013-04-15 @10:25');
        $auxiliary->setLabel('Date & Time');
        $structure->addAuxiliaryField($auxiliary);

        // Add icon image
        $icon = new Image('appassBundle/Resources/Images/icon.png', 'icon');
        $pass->addImage($icon);

        // Set pass structure
        $pass->setStructure($structure);

        // Add barcode
        $barcode = new Barcode(Barcode::TYPE_QR, 'barcodeMessage');
        $pass->setBarcode($barcode);

        // Create pass factory instance
        $factory = new PassFactory('pass.dk.mcoupons.mcoupon', '9W6X83AQ63', 'KA Innovation ApS', '%kernel.root_dir%/Resources/certificates/certificate.p12', 'hestmink09', '%kernel.root_dir%/Resources/certificates/applewwdrca.pem');
        $factory->setOutputPath('%kernel.root_dir%/logs/pkpass');
        $factory->package($pass);
        //$em = $this->getDoctrine()->getEntityManager();
        //$em->persist($task);
        //$em->flush();
        echo 'pass generated ';
        return $this->render('apbappassBundle:Default:index.html.twig');

    }

但这给了我这个错误

SplFileObject :: __ construct(appassBundle/Resources/Images/icon.png):无法打开流:没有这样的文件或目录 500内部服务器错误-RuntimeException

SplFileObject::__construct(appassBundle/Resources/Images/icon.png): failed to open stream: No such file or directory 500 Internal Server Error - RuntimeException

我尝试了其他方法给出路径,但失败了. 这是存储图像的层次结构或文件夹结构

i have tried different ways to give the path but failed. here is the hierarchy or folder structure where my images are stored

尝试

 $icon = new Image('%kernel.root_dir%/appassBundle/Resources/Images/icon.png', 'icon');

或者也许:

$iconPath = $this->get('kernel')->getRootDir().'/appassBundle/Resources/Images/icon.png';
$icon = new Image($iconPath, 'icon');

类似,我看不到您项目的整个结构.

Or similar, I don't see whole structure of your project.