aws / aws-sdk-php-zf2

ZF2 module for using the AWS SDK for PHP to interact with AWS services like S3, DynamoDB, SQS, EC2, etc.
http://aws.amazon.com/sdkforphp/
Apache License 2.0
103 stars 63 forks source link

$this->s3Link doesn't exist in view #20

Closed kfirufk closed 10 years ago

kfirufk commented 10 years ago

Hello. I'm writing a PHP application with zend framework 2.4.0dev PHP version 5.5.12

I used composer to install the aws-sdk-php-zf2 module and I add Aws to the application.config.php under modules.

in views I don't have $this->s3Link. am i missing something ?

my composer.json has the following: "aws/aws-sdk-php-zf2": "1.2.*"

which means it should install the latest version that already has this feature.

gws commented 10 years ago

@kfirufk Did you try to call the view helper as outlined in the documentation?

If you aren't familiar with view helpers in ZF2, please read the following: http://framework.zend.com/manual/2.3/en/modules/zend.view.helpers.html

kfirufk commented 10 years ago

unfortunately this is not the issue. i'm trying to use setDefaultBucket and i get 'call to a member fuction on a non object' which shows that s3Link is a none existing object. i read the view helpers url you provided and it seems that I don't think i'm missing anything.

$this->s3Link should be available in views after adding Aws module to applications config but for some reason it doesn't.

gws commented 10 years ago

@kfirufk What happens when you try the example from the README in your view script?

<?php echo $this->s3Link('my-object', 'my-bucket'); ?>
kfirufk commented 10 years ago

ok that works. so only setDefaultBucket doesn't.

gws commented 10 years ago

You need to invoke s3Link in your view script:

// This works
echo $this->s3Link(...);

you can't simply refer to it:

// This doesn't work because s3Link is looked up in the ViewModel
echo $this->s3Link;

because in this case s3Link would be looked up in the ViewModel like any other variable assigned to the ViewModel as part of your application.

If you need to set up setDefaultBucket, the very first set of examples walk you through how to retrieve the helper instance, which you can do from pretty much anywhere in your application:

// You should be able to use $this instead of $view if you are
// doing this from the view context
$view->plugin('s3link')->setDefaultBucket(...);

For more information I will once more suggest reviewing the documentation: http://framework.zend.com/manual/2.3/en/modules/zend.view.helpers.html

kfirufk commented 10 years ago

thank your very much for your assistance and patience. i did not try the $view->plugin thingy because your documentation is showing the following example: <?php $this->s3Link->setDefaultBucket('my-bucket'); echo $this->s3Link('my-object');

so maybe you should modify that.

thanks again :)

gws commented 10 years ago

I didn't write that documentation. Feel free to submit a PR :)