Announcement

Collapse
No announcement yet.

tip: php and defining functions

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    tip: php and defining functions

    in actinic, you can use php to do complex things, we know this, but what happens when you want to define a function?

    first of all, you can do it in the actinic_main.php file, but, what if thats not appropriate?

    well, if you define a function within a template, actinic accepts it, but then, if you look at the page again, it suddenly decides to throw a wobbler. You cannot define the same function twice in the same session.

    PHP does not allow you to 'unset' a function, but luckily, I found a quick workaround:

    PHP Code:
    if (!function_exists('myFunc')) {
        function 
    myFunc($variable) {
        
    //function here
        
    }

    Voila. The function is created on the first pass, then next time its parsed, actinic skips over the creation.

    Hope this helps someone.

    #2
    Thanks Gabe, very good tip!

    PHP Code:
    if (!function_exists('myFunc')) {
      
    // just remember that any changes you make inside this block will
      // not take effect until you restart actinic :)

    Rob Williams
    Ink Cartridges
    Stinky Ink - Blog

    Comment

    Working...
    X