looking for replacement for Jrequest::SetVar(name, $Array)

999 views
Skip to first unread message

joomalungma

unread,
Sep 10, 2011, 7:07:52 AM9/10/11
to Joomla! Framework Development
Hello every one,
I'm trying to upgrade my component from J1.5 -> J1.6
in early version for J1.5 i've used in controller
JRequest::SetVar(name, $Array) to path some Array to the view,
Important that $array is really Array.
Now in J1.6 i'm tryin to use JInput instead of JRequest and i can't
pass Array through it.
my code in the View
$this->get(name); returns just string(5) 'Array' not an Array with
data.

Is there a way to path array to the view?

Sorry if this is a wrong place for this post.

Michael Babker

unread,
Sep 10, 2011, 9:56:15 AM9/10/11
to joomla-dev...@googlegroups.com
JInput wasn't introduced until Platform 11.1, which is in Joomla! 1.7.
JRequest will continue to work through the 2.5 release in January. That
said, I've done some work on a branch to move off deprecated code to
handle getting data, but I'm not sure yet how to set through JInput.

Here's a get example:

$app = JFactory::getApplication();
$input = $app->input;
$input->get('view', 'feeds', 'word');


Hope this helps some!


Michael Babker
Owner, FLBab.com

"The difficult we do immediately. The impossible takes a little longer."
- US Army Corps of Engineers

>--
>You received this message because you are subscribed to the Google Groups
>"Joomla! Framework Development" group.
>To post to this group, send an email to
>joomla-dev...@googlegroups.com.
>To unsubscribe from this group, send email to
>joomla-dev-frame...@googlegroups.com.
>For more options, visit this group at
>http://groups.google.com/group/joomla-dev-framework?hl=en-GB.
>


Louis Landry

unread,
Sep 10, 2011, 12:31:14 PM9/10/11
to joomla-dev...@googlegroups.com
The logic to set a value into JInput is nearly the same as getting a value:

$input->set('name', $value);

When you call:

$input->get('name');

If you are getting back the string 'Array' when you expect an actual array, it is for good reason.  The default filter for JInput::get() is CMD.  This is a fairly strict string filter and is thus casting the value to a string and running it through a regular expression.  There are a couple of ways you could approach this issue.

1.  *Simple*  Ask for an array from JInput::get()

$input->get('name', null, 'array');

The second argument is an optional default value if the named value doesn't exist in the request.  The third value is what type of value you want to get from the request.

2.  *Better*  Ask for an array from JInput with a specific set of filters for array offsets.

// Here is an example array coming in from the request based on submitting a form.
$_REQUEST = array(
'name' => array(
'p_id' => 3,
'body' => '<p>Lorem Ipsum...',
'title' => 'My Item',
'access' => 0
);
};

// Let's get the data from the request as an array exactly filtered the way we want it.
$input->getArray(array(
'name' => array(
'p_id' => 'INT',
'body' => 'HTML',
'title' => 'STRING',
'access' => 'INT'
);
));



------------------------------------------------------------
Louis Landry
louis....@gmail.com



joomalungma

unread,
Sep 10, 2011, 6:29:11 PM9/10/11
to joomla-dev...@googlegroups.com
Thank you for your answer. Both way exactly what I'm looking for.
Reply all
Reply to author
Forward
0 new messages