what does getcmd do in Joomla - 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.

Related

In codeigniter, var_dump($this) displays all the variables that are availible in the view

In codeigniter, If you use var_dump($this) you can see all the variables that are availible in your view. Database username and passwards are also visible. I am new to codeigniter, I do not know can this be misused or it is safe.
`var_dump($data)`
This is mainly used to display your structured information with type and value retrieved on your backend like model or controller etc.
Just refer the link to know more regarding var_dump and information on how to safeguard your credentials from var_dump(),var_export() and print_r().
Hope these reference's help you.
In codeigniter we call methods using $this. So there is 100+ $this lines.
if your want to check value of some variable, You have to
Assign value to variable.
ex: $array = $query->result_array(); //Model example
Then check it using
print_r
var_dump

Other way to pass data from block to controller Magento

I'm pretty new to PHP programming and Magento. I wanna to pass the current ProductId from a form within a custom block to a controller (new action).
Yes I know that one method would be to add an input hidden (with my product id) in the custom block form and then to retrieve the Value through a regular:
$this->getRequest()->getPost('myvalue'))
Is there a better way in Magento to retrieve the value within the controller without having to declare extra secret input fields ?
Good for you for wanting to adhere to best practices within Magento! The passing of data to controllers is pretty standard, however. If we look at how the product is added from a product page, we'll actually see the product ID in the form action URL's parameters:
http://domain.com/checkout/cart/add/uenc/uenc_value/product/45573/
...where 45573 is the product ID. Of course this can also be sent to the controller via a hidden input field, which I use all the time. Note that the above is the same as http://domain.com/checkout/cart/add/?uenc=uenc_value&product=45573 in Magento.
Another way of storing data for use in controllers for future use is setting data into a session. For posting data to a controller I wouldn't recommend this method but it's something to keep in mind:
$session = Mage::getSingleton('core/session');
$session->setMyValue(true);
We can then retrieve the data from my_value later just by instantiating the session. Good luck!
Passing your data could be done in different ways :
You could use Magento's magic setters and getters.
So you would have to do this to set the value :
Mage::getSingleton('core/session')->setSomeVariable($value);
and this to retrieve it :
Mage::getSingleton('core/session')->getSomeVariable();
Or you could use the register.
Mage::register('key', $value); //to set your data
Mage::registry('key'); //to get your data
Magento provides a way to construct a URL with the necessary values, calculated against the configuration DOM. Blocks (and therefore block templates) can call Mage_Core_Block_Abstract::getUrl() directly:
$this->getUrl('some_handle/foo/test',array('id'=>'some_value'));
// Mage::getUrl() will work as well
The above would result in the following URL:
http://base_url/frontname/foo/action/id/some_value/
...which can be read in the FooController testAction() as
$this->getRequest()->getParam('id') // 'some_value'

access a variable value sent through url in joomla 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.

passing data to another controller

I need to pass product Id from cart to custom controller, for example
http://**/catalogsearch/filter/results?product={ID}
I dont have a clue how to pass data like that using magento helpers etc
Thanks
I am assuming from your question that you are redirecting from one controller to another and would like to pass query parameters along?
The syntax would be:
$params = array('key' => 'value');
$this->_redirect('frontname/controlller/action', array('_query' => $params));
EDIT
To answer the question in the comment on how to get these parameters from a template:
First off, I would advise not to do this, you should be recieving parameters in the controller. So, your custom controller should be responsible for receiving any parameters.
Regardless, the code in either situation is the same:
All parameters…
$this->getRequest()->getParams()
Single parameter…
$this->getRequest()->getParam('parameter_name')

Passing form data through MVC - Joomla

I'm creating a search form that shows a single user depending on the exact match of the first and last names and a member ID. I have the component shell set up with the form data going to a custom controller in 'com_medsearch/controllers/search.php'. I've read the tutorials in the Joomla docs, but I'm not sure how to pass the data to the model (com_medsearch/models/search.php) and the query results back to the same view. Answers?
You can do this 2 ways:
You detect that you had a search post in your controller then you call your model and in the model you can use JRequest::getVar / getInt / etc to read your variables.
You detect your search post and read your variables from the post all in your contoller function and pass it to your model.
Here is an example for point 2:
$settings = JRequest::get( 'POST' );
$model = & $this->getModel('settings');
$model->saveSettings($settings);
Then in your model you can access your post variables like:
$settings->input_name

Resources