Search code examples
opencartopencart-module

Opencart - Get html module description value in controller


Im a begginer at opencart, I need to be able to give an option for a user to edit some text through the html module. And then a controller that i created would get the html description part. Not really sure how could I achieve this?

I need this because I'm making a custom page and I need the sites admin to be able to edit text later.

Thanks for help!

Edit: Trying to explain this a little bit better.

I have created a controller -> custom/custompage.php

So when someone goes to my /index.php?route=custom/custompage I show a custom view I created.

Now I want to add the possibility for the admin to add some custom text to it. And I don't know how should i go about it. What would be the best way of achieving this.

The answer lead me to the right direction and I found a really good tutorial code here: https://bitbucket.org/mariavilaro/opencart-2-hello-world-module/src/f4bc431c439258f5c145fe7f3f43a372204b5fd5?at=master It has loads of comments and I managed to make a module that would provide me with the values for my custom field.


Solution

  • You need to create an admin panel for this module. Give admin few fields to save his custom text. Then submit the form to save entered values in the database.

    Use below Opencart function to save post data

    $this->model_setting_setting->editSetting('your_variable',$this->resquest->post);

    In front end, get saved values using below function.

    $this->model_setting_setting->getSetting('your_variable');

    Then use those values to create your custom page.

    NOTE: We recommend you to check code of /admin/controller/module/category.php to understand how to save values from admin panel.