We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Adding new function to existing module

Development and Programming

lukemcr's avatar
lukemcr
154 posts
16 years ago
lukemcr's avatar lukemcr

I’m looking to modify an existing module for personal use. Among other things, it provides tags that produce a form in a template which, when submitted, write form data to a table in the EE database.

I want to keep that functionality, but also write some of the same form data to a different table (exp_categories). I’ve written the add_categories function to do that, but I can’t seem to actually call the function correctly so it activates. (When I split the function up in to its parts and put it in an existing function within the module file, it writes to the categories table as it should, but the module’s original functionality doesn’t work.)

Anyway, here’s the function:

function add_categories ()

    {
        global $DB, $EXT, $FNS, $IN, $LANG, $LOC, $OUT, $PREFS, $REGX, $SESS, $TMPL;

        $_POST = $REGX->xss_clean( $_POST );
    
$cat_query = $DB->query("SELECT AUTO_INCREMENT FROM information_schema.tables WHERE table_name='exp_categories' AND TABLE_SCHEMA='db_name' ORDER BY Auto_increment DESC LIMIT 1");
foreach($cat_query->result as $row){}

$cat_id = $row['AUTO_INCREMENT'];
$site_id = "1";
$group_id = "4";
$parent_id = "0";
$cat_name=$_POST['name']." Moderators";
$cat_title = $REGX->create_url_title($cat_name);
$cat_description = $_POST['description'];
$cat_image = "";
$cat_order = "0";

    $data = array(
            'cat_id' => $cat_id, 
            'site_id' => $site_id, 
            'group_id' => $group_id, 
            'parent_id' => $parent_id, 
            'cat_name' => $cat_name, 
            'cat_url_title' => $cat_title, 
            'cat_description' => $cat_description, 
            'cat_image' => $cat_image, 
            'cat_order' => $cat_order
              );

            $sql = $DB->insert_string('exp_categories', $data); 

        $DB->query($sql);

}

Is there anything obvious that I’m doing wrong? This is going in to the mod.module_name.php file.

       
Mark Croxton's avatar
Mark Croxton
319 posts
16 years ago
Mark Croxton's avatar Mark Croxton

I’m not sure if I understand you, but I think what you want is $this:

class my_module {
   ...

   function an_existing_function()
   {
      ...

      // call your method here
      $this->add_categories();
   }

   function add_categories()
   {
      // your method
   }

}
       
lukemcr's avatar
lukemcr
154 posts
16 years ago
lukemcr's avatar lukemcr

That was exactly what I was missing. I’m new w/ EE module building and stuff… thank you so much.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.