[SOLVED] creating module - can't see my functions

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
turniphead
Forum Members
Forum Members
Posts: 40
Joined: Thu Jul 31, 2008 12:16 pm

[SOLVED] creating module - can't see my functions

Post by turniphead »

I'm developing my first module using the documentation and skeleton module as a reference. I'm using a one-file approach with one .module.php file. All was going well until I tried to bundle some of my code in a function. So I have something like

Code: Select all

function myfunction() 
{
  return "myfunction";
}

function DoAction($action, $id, $params, $returnid=-1)
{
.
.
.

  if ($action == 'addproduct')
  {
    $x=myfunction();
  }
.
.
.
}
This arrangement gives me
Fatal error: Call to undefined function myfunction()
Can anyone explain why?
Last edited by turniphead on Fri Aug 01, 2008 5:18 pm, edited 1 time in total.
oi_antz

Re: creating module - can't see my functions

Post by oi_antz »

When you're working within a class such as "class MyNewModule extends CMSModule{...}", you need to reference methods by $this->myFunction() instead of just myFunction(). Look for a tutorial on OOP with PHP, this will explain how to use classes and objects.
turniphead
Forum Members
Forum Members
Posts: 40
Joined: Thu Jul 31, 2008 12:16 pm

Re: [SOLVED] creating module - can't see my functions

Post by turniphead »

Of course!

Thank you.
Post Reply

Return to “Developers Discussion”