access a variable value sent through url in joomla view - view

I want to access a variable sent through url in the view of a joomla component. How can I achieve it? Please help me.

you can use
$myvar = JRequest::getVar('variablename','defaultvalue') ;
or (only in J1.6+)
$jinput = new JInput();
$myvar = $jinput->getVar('myvar');
There are more methods to JRequest and JInput i.e. JRequest::getInt, getCmd etc you might want to check the docs.joomla.org
With both you can choose to restrict the method from which the values are read, pass 'GET' as a third parameter to any getVar function and the value will be read only if it's from a GET, otherwise you can test COOKIE, POST etc.

Related

How to get PUT and DELETE parameters from HTTPRequest in SilverStripe?

There are getVars(), postVars() and requestVars() methods in HTTPRequest.
They returns parameters from GET and POST requests.
But how can I get parameters from PUT and DELETE requests?
I know that there is a 'body' property somewhere in HTTPRequest. It contains PUT params in query string or something similar.
To use this property I need to parse 'body' field.
Is there a way to get these parameters with comfortable way, like for GET and POST?
You need to do it the old school way.
parse_str($request->getBody(), $params);
$foo = $params['Foo'];
Keep in mind the second parameter of parse_str is a reference, so no need to define that variable before invoking the function call.

what does getcmd do in Joomla

Hi all I am new to programming in Joomla. I am going through the Joomla Programming book by Mark Dexter and Louis Landry. Which for the most part is a good book.
My question is what does $view = JRequest::getCmd('view', 'submanager'); do?
I know it is returning something to the $view variable, but not sure what. Is it looking for the word view as a request URL param? What is submanager?
Any clarity in this matter would be great.
Thanks in advance
Dean-O
getCmd is a proxy function for getVar The difference being is that getCmd only allows words and integers based on [A-Za-z0-9.-_].
getVar simply fetches a variable that you ask it to, depending on the request method, such as a POST or GET request.
Do bare in mind that JRequest is deprecated, therefore should you need to fetch a variable, then use the following:
$jinput = JFactory::getApplication()->input;
$variable = $jinput->get('view', 'submanager');
Example:
Lets say you have a small contact form and within that form is an input field which has name="email".
Once that form is submitted, you can then access this using:
$jinput = JFactory::getApplication()->input;
$variable = $jinput->get('email');
So in your case, the code you provided is getting the variable view, ensuring it is a word or number and submanager is the default value for this variable.

How to get the base url of a specific store view in a static block?

I know that in a .phtml file you do it like this for example:
<?php echo $this->helper('derco_core')->getStoreUrl('dcmotosesp')?>
I want to do the same thing inside a static block. Thanks in advance.
There is no 'clean' way of getting an url for a specific store using shortcodes ({{store url}}).
...because the store shortcode handler end like this (see Mage_Core_Model_Email_Template_Filter::storeDirective()):
return Mage::app()->getStore(Mage::getDesign()->getStore())->getUrl($path, $params);
This means that the store cannot be passed as a parameter.
The following might work but it's a bit ugly. The idea is to send the parameter ___store through $_GET telling Magento to switch to a specific store.
TEST LINK
(replace 'store_code_here' with your specific store code).
An other option would be to extend the method mentioned above and allow it to receive a store_code parameter.

VBScript setting the _POST variable

Is there an equal VBScript solution to PHP's
$_POST("user") = 12345;
I just need to set the $_POST variable to some value (which gets retrieved on the next page) and do not see any direct solution. ( note: I cannot use session, or self-submitting html form with post method.)
Thanks.

How to call an action inside another action in Yii?

I've a situation where i get some information from database and based on the data , i want to do/forward to some other controller & action.
How can i do this using Yii? Its like an ajax request..
If i can use the CController->forward() , then how can use the post values for actions?
I shall assume that the reason why redirect() didn't work for you was because you can't sent post variables with it. If that's the case, then let me show you how to overcome the lack of POST support in redirect(). You can use setState(). It creates variables that simulate POST variables. This is the code to store or set a variable:
Yii::app()->user->setState('var', 'value');
And, in order to trace the value you just code as follows:
Yii::app()->user->getState('param1');
It would equally work with forward, but I'm not sure why you want to use it instead of redirect().

Resources