Menon Jats
Menon Jats

Reputation: 327

Send data from view to controller in opencart

I'm new to opencart MVC is it possible to send view data like this

<p><?php echo  "$i )".$showall['store_name']. '<br>'.$showall['store_address'].'<br>'. $showall['zipcode'].'<br>'.$showall['zipcode'].'<br>'.$showall['city'].'<br><a href='.$delaction.'>Delete</a>' ; ?> </p>

here I would like to send $delcation variable to controller

Upvotes: 1

Views: 1215

Answers (2)

purna chandra
purna chandra

Reputation: 1

In your controller file use $data[] global variable to send data to view

Ex: In controller file $data['var_name']="something";

In view file you can use it has <?php echo $var_name; ?>

Upvotes: 0

user3703155
user3703155

Reputation: 76

I'm not familiar with opencart, but I'm with MVC. In some frameworks you have a routes file, in others the framework interprets your controller structure to provide routes. I'm assuming opencart works like the last.

You have a controller with an index function right? And to load that page via the url, something like: "http://localhost/index.php?route=test/abc"

You can try the following:

  • Create an other function in the controller called delete
  • The link in the href will be like so: index.php?route=test/abc/delete
  • Then to pass the id of the object to delete you pass another variable in the query sting like so: index.php?route=test/abc/delete&id='.$idToDelete.'
  • To retrieve the variable in the controller you do this: $idToDelete = $this->request->get['id'];
  • Then you can remove that object in this function and redirect back to the correct page.

What to do if "index.php?route=test/abc/delete" doesn't work? If opencart doesn't support this you can do the following:

  • create different functions like get/update/delete etc. in the controller
  • create a index function with a switch
  • add a func variable in the query string like so: index.php?route=test/abc&func=delete
  • Then just run the correct function for $this->request->get['func'];

Hope it works out for you! (let me know what helped, so I can update the answer accordingly)

Upvotes: 1

Related Questions