Advertisement:

Author Topic: it correct to copy the same php class of Form.form.class.php to functions.php?  (Read 1361 times)

AdrianOlmedo

  • Newbie
  • *
  • Posts: 46
  • Working with Osclass 3.7.5
Can I copy the same class php Form.form.class.php to functions.php , changing the name of that php class?

I need to access the contents of the select html in my template css of
Code: [Select]
<?php ItemForm::category_select(nullnull__('Select a category''realestate')); ?>

teseo

  • Hero Member
  • *****
  • Posts: 6169
Hi,

Because of that function category_select doesn't use internal class syntax (something like $this->), you just can put a copy of the whole function in your theme functions.php, the only thing you need to do is change:

static public function category_select

to something such as:

function cust_category_select

Then you can adapt it to your needs, and replace in item-post.php and item-edit.php:

Code: [Select]
<?php ItemForm::category_select(nullnull__('Select a category''realestate')); ?>
to

Code: [Select]
<?php cust_category_select(nullnull__('Select a category''realestate')); ?>
Regards

AdrianOlmedo

  • Newbie
  • *
  • Posts: 46
  • Working with Osclass 3.7.5
Thanks for the clarification

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Hi,

I also modified an existing core class but not by copying the whole class but by using the 'extends' functionality in which case there's no need to copy the whole class and you can simply add your own new function or a modified copy of a class function.

In your theme's functions.php you create it like this
Code: [Select]
class Your_Custom_Class extends ItemForm {

Your own custom (modified) class function
OR
Your base class edited function (an existing function of ItemForm using the same name here superseding the ItemForm original function.

}

Using this principle enables you to call ALL functions of class ItemForm including your own modified function by calling it using this code:

Your_Custom_Class::MyCustomFunction();
OR
Your_Custom_Class::ExistingFunctionName();

That's all.