Extending class in application level

A place for users and developers of the Xataface to discuss and receive support.

Extending class in application level

Postby kevinwen » Tue Jan 05, 2010 3:22 pm

I want to extend the class under framework in my application so I can have my own customization with changing anything in the framework, and I won't have any problem doing framework upgrade in the future. Does anybody know how to do it? Thanks. For example, I want to create a file (MyHistoryTool.php) doing the following:

class MyHistoryTool extends Dataface_HistoryTool {
function myfunc() {
return 'Hello World!';
}

function getHistoryLog(&$record, $lang=null, $limit=100){ //override the function in parent class
echo "this is the new history log";
}
}

In which folder under my application should I put this MyHistoryTool.php? Does anybody know? If it's possible to do so, how do I use these new/overriding function and integrate with those templates in Dataface/templates?
kevinwen
 
Posts: 109
Joined: Mon Dec 28, 2009 3:44 pm

Re: Extending class in application level

Postby shannah » Tue Jan 05, 2010 9:35 pm

Unfortunately this isn't easy to do. Ideally you want to make use of the Factory design pattern but Xataface doesn't use this pattern currently.

One option is to exploit Xataface's include directory order of lookup and just override the HistoryTool class. Xataface will look in the following locations for its classes, in this order:

1. . (i.e. current directory).
2. xataface (i.e. the xataface directory)
3. xataface/lib

Do if you were to add a directory named 'Dataface' (capitals count) into your application directory, and place your modified HistoryTool.php file into that directory, your application would use your version instead of the one with the Xataface distribution. Then you only need to worry if there are changes made to the HistoryTool when you update Xataface (and you can always run a diff or a merge on that file to ensure that all is ok).

-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 8 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved