We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Plugin: return array

Development and Programming

Forecepts PL's avatar
Forecepts PL
35 posts
14 years ago
Forecepts PL's avatar Forecepts PL

Hi

I face error when I tried to return Array from plugin.

It show error message as “Array to string conversion”.

May I know how to solve this issues?

       
Lisa Wess's avatar
Lisa Wess
20,502 posts
14 years ago
Lisa Wess's avatar Lisa Wess

Hi forecepts.dev,

I’ve moved this down to Development and Programming. Can you share with us your actual code and what you are trying to accomplish? We can’t help without a lot more info.

Thanks!

       
Forecepts PL's avatar
Forecepts PL
35 posts
14 years ago
Forecepts PL's avatar Forecepts PL

Hi

Currently I return values as string format. I wish to return as Array format, I store my value in session as Array format. But when i return as $arr, it gave me error message.

Please kindly advise, thanks.

function getarray() { $arrString=”“; $arr = array(); // check if correct parameters were passed if (!$this->EE->TMPL->fetch_param(‘name’)) { show_error(‘Session Plugin: name parameters must be entered’); } $name = $this->EE->TMPL->fetch_param(‘name’);

    // if no active session we start a new one
    if (session_id() == "") 
    {
        session_start(); 
    }

    if (isset($_SESSION[$name]))
    {
        $arr= $_SESSION[$name];
    }


    for ($a=0;$a<=count($arr)-1;$a++)
    {
        for ($b=0;$b<=count($arr[$a])-1;$b++)
        {
            $arrString .=$arr[$a][$b];

            if ($b==count($arr[$a])-1)
            {
                $arrString .=";";
            }
            else
            {
                $arrString .=",";
            }

        }

    }
    //$arrString = implode(',', $arr);
    return $arrString;

}
       
Forecepts PL's avatar
Forecepts PL
35 posts
14 years ago
Forecepts PL's avatar Forecepts PL

How is my code?? is it any mistake??

       
the3mus1can's avatar
the3mus1can
426 posts
14 years ago
the3mus1can's avatar the3mus1can

You cannout return an array value from a plugin. The template parser expects a string or an instance of a class that has the magic method __toString implemented (which ultimately just returns a string).

What are you trying to achieve in the template with your plugin?

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.