Tutorial :Request different data from the same component in Joomla



Question:

I have a simple component that displays a list of products. I want to separate the products by type. Is there a way through the task= or something like that where I can call a different function in the model? Or... better question: How would I go about using the url to retrieve different data, change a header on the template, but display the data in the same way for each type?

sql will look something like:

SELECT * FROM stoves WHERE type=1  SELECT * FROM stoves WHERE type=2  


Solution:1

Maybe I don't see the complexity but it seems pretty simple. You just need to add another parameter to the url request to your component. Call it "type" for example.

Then your sample url will look like: "index.php?option=com_example&task=view&type=1". Then inspect the value of the "type" parameter in your component's controller and act depending on its value...


Solution:2

You don't need the controller to call a different view. In the controller, look for the additional input "type" in the query string, then create a WHERE clause that you append to your SQL query when pulling the data out of the DB. Be sure that you have a where clause for each type you want to use plus a default for the times type is missing or not defined.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »