Products Module

edited April 2012 in Modules
Hi,

Created a products module, which is an advnace module, but now i need to have a link to delete a certain uploaded PDF and trying to create normal controllers, and models as you would with a standalone version of Codeigniter, i find this doesn't work, so what should I do?

Comments

  • edited 6:43PM
    Hey,

    Can you be a little more specific about what doesn't work? Examples of what you have now would be helpful.
  • edited 6:43PM
    Well basically i have done the database with several fields which Fuel then produced the form, and I added in some extra functionality, but now I need it to delete a certain field when the user clicks the link.

    So I need to grab the ID of the product and then tell it to delete a certain row from the database.
  • edited 6:43PM
    Sorry I'm not quite getting it.. Have you created a custom field to hold the pdf or something?

    Can you screen shot the form?

    Just trying to understand why the normal delete for a form doesn't work for you. It's purpose is to delete rows from the database..
  • edited 6:43PM
    I don't want to delete everything from that record i just want to remove what is in the pdf field, so i need a function to do this, any idea's?
  • edited April 2012
    Ah right gotcha.

    You could include a checkbox in the after_html form field.

    Then check for it's existence in $this->normalized_save_data (or plain old $_POST) in the models on_before_save() hook. If there, unset your pdf field and save.
  • edited 6:43PM
    But i have a link like: Delete so need to know what to put in the href
  • edited 6:43PM
    so i have form_fields that produce all the fields

    see image -> http://imageshack.us/photo/my-images/546/screenshot20120426at120.png/ see the delete text so when this delete link is clicked is need to remove that pdf from the database but leave everything else as is
  • edited April 2012
    I can't see that pic here.

    I figure you're meaning from the list items. That will be much trickier.

    I don't think an extra url component will get it done for you. I think you're best bet is to have a look at the create_function() call in /modules/fuel/config/fuel_modules.php in the users config array.

    I've not had to do one of those yet so can't be of too much help. I'd say you'll need a custom controller to catch it too.

    Hopefully Dave can offer you some better advice.
  • edited 6:43PM
    So where do i go from here, if it was conventional codeigniter i could write something but seen has the main files are in modules with no real controllers I'm kinda stuck what to do.
  • edited 6:43PM
    Perhaps you can use a little bit of javascript and some ajax. You can create the javascript file and associate it with the module using the "js" parameter in your fuel/application/MY_fuel_modules.php config. Then, if you specify a method on your model that begins with "ajax_" you can call on your module's controller the 'ajax' method, then pass it the name of the model method (without the "ajax_" prefix) as a URI segment. The method on your model needs to accept an array and will get passed any $_GET parameters in the ajax request. So for example, you could pass it the id of the row you need to delete the PDF from. More about it can be found in this thread:

    http://www.getfuelcms.com/forums/discussion/comment/2138/#Comment_2138

    The module method can be examined in the fuel/modules/fuel/controllers/module.php file
  • edited 6:43PM
    I'm not really that good with ajax just wanted to keep it simple like click the link and the PDF gets removed or even a checkbox then click save and it gets removed, but just the pdf that is clicked via link or check box
  • edited 6:43PM
    Here's my complete products module so what can i add into to make this work?

    http://pastebin.com/Jm8jeF9X
  • edited 6:43PM
    Another option could be that your link submits the form (would require using javascript):
    $(function(){ if ($('.my_delete').click(function(e)){ $('#delete_pdf').val('1'); $('#form').submit(); } });
    Then in the model, you could use an on_after_save hook to detect the value of "delete_pdf" and put code in your hook to delete it.
    function on_after_save($values) { if (isset($this->normalized_save_data['delete_pdf'])) { .... delete code... } }
  • edited 6:43PM
    And what you wrote is that based on my pastebin link?
  • edited 6:43PM
    So then how would i get the id and delete just a pdf field whichever is clicked to delete? As there are 3 pdf fields so don't want it deleting all 3 just which ever is clicked.
  • edited 6:43PM
    Perhaps instead of "1" you could pass the name of the field in the "delete.pdf" field and then you can access that value in the normalized_save_data model property in your hook.
Sign In or Register to comment.