Extend XenForo Model

Uniphix

Active member
Is there a way to extend the XenForo Model? I am looking at how to do this but when I try to get the model from the cache (create etc.) it never calls the XenForo_Model class even though it is the base apparently from what I see there may not be a way to actually extend the XenForo Model which I really need to do...
 
I'm trying to create an output of something simular:

Code:
Array
(
    [0] => MyAddon_Extend_Model_Catalog
    [1] => XFCP_MyAddon_Extend_Model_Catalog
    [2] => MyAddon_Model_Catalog
    [3] => MyAddon_Extend_Model
    [4] => XFCP_MyAddon_Extend_Model
    [5] => XenForo_Model
)
 
Could it be feasible to listen for the load_class_model code event and actually not filter anything but extend each model class with the same custom class?
 
It won't work like this because it will attempt to create another XFCP_MyAddon_Extend_Model everytime... Which will break.
 
Whatever I really want to do is not going to work because...


If I extend XenForo_Model_User for example: MyAddon_Extend_Model_User extends XFCP_MyAddon_Extend_Model_User

calling XenForo_Model::create('XenForo_Model_User'); will do the following

Code:
MyAddon_Extend_Model_User extends XFCP_MyAddon_Extend_Model_User
which because I called ::create it will create a proxy class:

Code:
class XFCP_MyAddon_Extend_Model_User extends XenForo_Model_User

There is no way to extend XenForo_Model which is being used by XenForo_Model_User...


Code:
XenForo_Model_User extends XenForo_Model

Thus ::

My concept will not work because in the code bit XenForo_Model_User extends XenForo_Model would actually need to be my new extended method IE:

Code:
XenForo_Model_User extends XFCP_MyAddon_Extend_Model

Where

Code:
XFCP_MyAddon_Extend_Model extends XenForo_Model

In this case it is going to be impossible to extend XenForo_Model correctly when its already being extended by....

The one thing I could do is make a new abstract class calling it MyAddon_Model extends XenForo_Model and have all my classes base off of MyAddon_Model...


The only issue is that I cannot extend MyAddon_Model with the same situation... More than likely I may have to use Interfaces to resolve my issues...
 
You only explained why this is not going to work, but not what you are trying to achieve.

Sample code please?
 
Due to the NDA I cannot provide any direct code examples, We have basically a framework, kinda like XenForo, that overrides a lot of the default systems of XenForo, but for us to really achieve our goals we've had to modify XenForo Framework to suit what we need.

Sorry...
 
Due to the NDA I cannot provide any direct code examples, We have basically a framework, kinda like XenForo, that overrides a lot of the default systems of XenForo, but for us to really achieve our goals we've had to modify XenForo Framework to suit what we need.

Sorry...

Not sure why you can't extend every class that uses XenForo_Model since every model will extend this class. If you need to directly access a grandparent's (or even more levels up) static method, you can directly use the class name, PHP will recognize.

Code:
class A
{
  protected function something()
  {
    echo "And I";
  }
}
 
class B extends A
{
  protected function something()
  {
    echo "Myself, ";
  }
}
 
class C extends B
{
  protected function something()
  {
    echo "Me, ";
  }
 
  public function call()
  {
    echo self::something(); // self
    echo parent::something(); // parent
    echo foo::something(); // grandparent
  }
}
 
$obj = new C();
$obj->call();
Output: "Me, Myself, And I"

But well, if they pay you well enough for the job, I'd say edit XF code, you won't be able to easily upgrade to 1.2 anyways :p
 
Due to the NDA I cannot provide any direct code examples, We have basically a framework, kinda like XenForo, that overrides a lot of the default systems of XenForo, but for us to really achieve our goals we've had to modify XenForo Framework to suit what we need.

Sorry...
At a high level, what functionality do you need to override? There may be ways to achieve what you'd like to do without extending XenForo_Model directly, which, as Mike said, is impossible with the system.
 
Yup Mike is correct and my version of XenForo is very heavy modified, and when it comes time to upgrade i'll just have to do some merging lol
 
To answer your questions we don't want to really override any methods we want to add more methods to XenForo_Model that is used in about 90% of the system... I've had to create my own "XenForo_Model" that extends that XenForo_Model then had my addon base off that
 
At the risk of getting this completely arse-ended and looking incredibly stupid...

Could you just not extend a current default model...but not actually use it?
For example, you're creating MyModel_Model, which extends XenForo_Model_User, which extends XenForo_Model.

You then have access to the grandparent XenForo_Model, and nothing says you have to use anything from the parent XenForo_Model_User

Or have I got it wrong?

Edit : Yup, I've got it wrong. I think I understand. You're trying to extend XenForo_Model in order to overwrite methods within XenForo_Model, and using the method I describe you can't overwrite grandparent methods, only parents?
 
To answer your questions we don't want to really override any methods we want to add more methods to XenForo_Model that is used in about 90% of the system... I've had to create my own "XenForo_Model" that extends that XenForo_Model then had my addon base off that
Wouldn't it be better to create your own model with the methods and extend XenForo_Model from your?
It's ONLY 1 fileedit which shouldn't be problematic with vcs tools!

Rich (BB code):
abstract class XenForo_Model extends Your_Model
{

that's it:)
now you have access to ALL your own methods in all Models.. One could even do this with XenForo_View and XenForo_Controller:D


Edit: Sorry, it seems that you're doing this already:oops:

I've had to create my own "XenForo_Model" that extends that XenForo_Model then had my addon base off that
 
Technically you could do it without code edits, just new files...

Create a file with a custom class: XenForo_Model_Custom (example name, will obviously be different).

This class extends your one, and is basically identical to the main XenForo_Model class.

Then, use the init_dependencies hook with the following code:

Code:
eval("class XenForo_Model extends XenForo_Model_Custom {}");

That way the actual library/XenForo/Model.php file is never read.

This is probably very, very hacky, but if it's only internal it works :P

Liam
 
Back
Top Bottom