Action Helper

4 messages Options
Embed this post
Permalink
Ian Warner-2

Action Helper

Reply Threaded More More options
Print post
Permalink
Hi

I would like some guidance on best practices for Action Helpers;

I currently use the following in my controllers

        // Get the Users Profile PIC URL
        $this->_helper->facebookPhotos($social);

        // Setup the Invite elements
        $profilePic = $this->_helper->facebookPhotos->getProfilePicURL();

In the helper I have:

    public function direct($social)
    {
        $this->social = $social;
    }

    public function getProfilePicURL() {
    }

Last time I checked I couldnt do something like:

   $profilePic = $this->_helper->facebookPhotos($social)->getProfilePicURL();

Or even
   $helper = $this->_helper->facebookPhotos($social);
   $profilePic = $helper->getProfilePicURL();

Can you give me any pointers on how to invoke and also optimise these little beauties.

Thanks
IAn


Brenton Alker-3

Re: Action Helper

Reply Threaded More More options
Print post
Permalink
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ian Warner wrote:

> Hi
>
> I would like some guidance on best practices for Action Helpers;
>
> I currently use the following in my controllers
>
>         // Get the Users Profile PIC URL
>         $this->_helper->facebookPhotos($social);
>
>         // Setup the Invite elements
>         $profilePic = $this->_helper->facebookPhotos->getProfilePicURL();
>
> In the helper I have:
>
>     public function direct($social)
>     {
>         $this->social = $social;
>     }
>
>     public function getProfilePicURL() {
>     }
>
> Last time I checked I couldnt do something like:
>
>    $profilePic =
> $this->_helper->facebookPhotos($social)->getProfilePicURL();
>
> Or even
>    $helper = $this->_helper->facebookPhotos($social);
>    $profilePic = $helper->getProfilePicURL();

To be able to chain calls like this, you will need to "return $this;"
from your direct() method.

- --

Brenton Alker
PHP Developer - Brisbane, Australia

http://blog.tekerson.com/
http://twitter.com/tekerson

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkrX6VcACgkQ7bkAtAithutYZQCg3Wi4iqw4f/Ys3s/GVNCzlHAO
U5MAn3ktzseT0EN+ZUfTUfw/B7hMdIWx
=n1nE
-----END PGP SIGNATURE-----
weierophinney

Re: Action Helper

Reply Threaded More More options
Print post
Permalink
In reply to this post by Ian Warner-2
-- Ian Warner <[hidden email]> wrote
(on Friday, 16 October 2009, 11:54 AM +0900):

> I would like some guidance on best practices for Action Helpers;
>
> I currently use the following in my controllers
>
>         // Get the Users Profile PIC URL
>         $this->_helper->facebookPhotos($social);
>
>         // Setup the Invite elements
>         $profilePic = $this->_helper->facebookPhotos->getProfilePicURL();
>
> In the helper I have:
>
>     public function direct($social)
>     {
>         $this->social = $social;
>     }
>
>     public function getProfilePicURL() {
>     }
>
> Last time I checked I couldnt do something like:
>
>    $profilePic = $this->_helper->facebookPhotos($social)->getProfilePicURL();

Makes sense -- your direct() method isn't returning anything. Have it
return $this, and you can then chain it:

    public function direct($social)
    {
        $this->social = $social;
        return $this;
    }

> Or even
>    $helper = $this->_helper->facebookPhotos($social);
>    $profilePic = $helper->getProfilePicURL();

Same applies here.

> Can you give me any pointers on how to invoke and also optimise these little
> beauties.

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
Ian Warner-2

Re: Action Helper

Reply Threaded More More options
Print post
Permalink
Thank you - simple answers are the best ones :)


2009/10/16 Matthew Weier O'Phinney <[hidden email]>
-- Ian Warner <[hidden email]> wrote
(on Friday, 16 October 2009, 11:54 AM +0900):
> I would like some guidance on best practices for Action Helpers;
>
> I currently use the following in my controllers
>
>         // Get the Users Profile PIC URL
>         $this->_helper->facebookPhotos($social);
>
>         // Setup the Invite elements
>         $profilePic = $this->_helper->facebookPhotos->getProfilePicURL();
>
> In the helper I have:
>
>     public function direct($social)
>     {
>         $this->social = $social;
>     }
>
>     public function getProfilePicURL() {
>     }
>
> Last time I checked I couldnt do something like:
>
>    $profilePic = $this->_helper->facebookPhotos($social)->getProfilePicURL();

Makes sense -- your direct() method isn't returning anything. Have it
return $this, and you can then chain it:

   public function direct($social)
   {
       $this->social = $social;
       return $this;
   }

> Or even
>    $helper = $this->_helper->facebookPhotos($social);
>    $profilePic = $helper->getProfilePicURL();

Same applies here.

> Can you give me any pointers on how to invoke and also optimise these little
> beauties.

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/