Kryptronic Software Support Forum

You are viewing this forum as a guest. Login to an existing account, or create a new account, to reply to topics and to create new topics.

#1 12-31-2009 13:47:28

Tanushiheadbash
Member
From: Stirling, Scotland
Registered: 07-20-2009
Posts: 82

Correct way to extend a class in ECP/CCP7

What is the correct way to extend a class in ECP7
I made some mods to my clients live shop a few weeks back as I could not fathom this, at the time, I added a new function (method) into the Core_Displays Class and this worked fine. However I am concious thet this modifies main system files and I really don't want this to be the way I do things. So I figured it would be better to add my new Method into a new class that extends Core_Display.
I have added my class to the database called HWM_Display but the file that relies onthe method now complains that it cannot see it in CORE Display.
(Not to worry this is on my development system!)
I have had a look through the various backend files but tis not obvious to me at all how a class extension woul dbe enabled?

Any clues?
A guid New Year when it comes

Kenny

Offline

 

#2 12-31-2009 14:01:44

Dave
Member
Registered: 07-05-2003
Posts: 11233

Re: Correct way to extend a class in ECP/CCP7

You don't really. Create your class following the same directory structure as the core or application directories then, if you need something from one of the CCP classes (core or otherwise) create an instance of it in your class so you can leverage it. If you need functions from CORE_Display for example use the following in your main function:

Code:

// +--
// | Quick object load: CORE_Display
// +--

$this->CORE_Display =& $this->quick_object('CORE_Display','core');

if ($this->IsError($this->CORE_Display)) {$this->cerror = $this->CORE_Display; return;}

then reference it in your methods using something along these lines:

Code:

$variable = $this->CORE_Display->xhtml_encode($somevariable);

If you need to be able to use your methods elsewhere in CCP define their method, or methods, in the namespace table as required.

Offline

 

#3 12-31-2009 14:51:45

Tanushiheadbash
Member
From: Stirling, Scotland
Registered: 07-20-2009
Posts: 82

Re: Correct way to extend a class in ECP/CCP7

OK
Thanks Dave- will need to absorb this!
Many thanks for your fast reply

Kenny

Offline

 

#4 01-04-2010 10:51:15

Tanushiheadbash
Member
From: Stirling, Scotland
Registered: 07-20-2009
Posts: 82

Re: Correct way to extend a class in ECP/CCP7

Hi
Right I think I understand this but I don't think its what I am trying to do.
I built a method which I simply tacked on the end of the CORE_Display class.
its called: xhtml_custom_buy
it creates three globals called
$this->globals('core_display.custom_buy_button',$button);
$this->globals('core_display.custom_buy_id',$formname);
$this->globals('core_display.custom_buy_buttonp',$buttonp);

and it pulls in an include called
'custom_buy_button.php' which lives in the CORE/includes directory.
My prodmulti file (that lives in apps\ECOM\includes\prodmulti.php
has been modifued to make use of this function to draw the buy button which in my case is a graphic not the text/css generated standard ones.
Like this:
$this->xhtml_custom_buy($formid,'Add To Cart',1);

I presume this works because CORE_Display is availble to prodmulti.php (though I don't see it mentioned inthe file itslef, I guess as prodmulti is an include its inheriting the settings from elsewhere.

If I move my method: xhtml_custom_buy () into a stand alone class- for arguments sake I call it HWM_Custom  how do I make this class available to the prodmulti include. (and also be able to utilise the parent services of CORE_Display.

I had a look at the namespaces table in the database ( I have done so a few times) but really don't understand how this works or how the classes come to know about each other: I did notice a line I think in the CORE class that creates a file path to what might be the classes and I suspect this is how its done but have not found any obvious code that shows how the databse relates to the availability of classes. As you can probably tell I am pretty new to OOphp and the reading and playing I have done has all been relative to php 5.2 and the examples I see don't appear to relate to well to the structure of CCP (probably because it uses the older php4 methodology

Offline

 

#5 01-04-2010 11:14:12

Dave
Member
Registered: 07-05-2003
Posts: 11233

Re: Correct way to extend a class in ECP/CCP7

Tanushiheadbash wrote:

If I move my method: xhtml_custom_buy () into a stand alone class- for arguments sake I call it HWM_Custom  how do I make this class available to the prodmulti include. (and also be able to utilise the parent services of CORE_Display.

The way I described in post 2 substituting your class name of course as well as your method name.

Tanushiheadbash wrote:

I had a look at the namespaces table in the database ( I have done so a few times) but really don't understand how this works or how the classes come to know about each other:

They don't. If a class needs to use a method in another class it creates a pointer to it using the method I described in post 2.

Tanushiheadbash wrote:

As you can probably tell I am pretty new to OOphp and the reading and playing I have done has all been relative to php 5.2 and the examples I see don't appear to relate to well to the structure of CCP (probably because it uses the older php4 methodology

You probably don't need to worry about or use an entry in the namespace table if you're only going to be using your class/method in a single place. The classes in CCP aren't truly OO since CCP is written to work with (a rather old version of) PHP 4. In a lot of cases, CORE_Display being a good example, the class has been loaded and made available very early in the calling sequence which is why you may use its methods without creating an instance of it.

Offline

 

#6 01-04-2010 15:41:15

Tanushiheadbash
Member
From: Stirling, Scotland
Registered: 07-20-2009
Posts: 82

Re: Correct way to extend a class in ECP/CCP7

Hi Dave
Ok I have spent some time fiddling around with this.
I tried using the method you mentioned but its not working and I cannot myself see how my include file gets to know about the new class.
I have however manged to get it working doing this- which while probably not wrong in a php sense is probably not tthe way to do it within CCP.

In the top of my prodmulti.php I have added this

$include_file = $this->globals('core.path_private') . '/core/HWM_Display/HWM_Display.php';
include_once($include_file);
$classholder = new HWM_Display();

Then in the code where I need the custom button to appear this:
print '<p>';
$classholder->xhtml_custom_buy($formid,'Add To Cart',1);
print '</p></div>' ; //close product box div
print '</td>' . $eol . $eol;

This works , so in many ways allows me to remove my method from the Core_Display class but its not the way you have it.

Offline

 

#7 01-04-2010 16:33:27

dh783
Member
From: Avondale, Arizona
Registered: 04-06-2005
Posts: 6233
Website

Re: Correct way to extend a class in ECP/CCP7

If you look at any script you will see how it is declared, the directory name, script name and class name declared have to be exactly the same. The area to look at is from the top to the end of the constructor function.

John

Offline

 

#8 01-06-2010 14:39:16

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19798
Website

Re: Correct way to extend a class in ECP/CCP7

This could have been done with:

$classholder =& $this->quick_object('HWM_Display','core');


Nick Hendler

Offline

 

#9 01-06-2010 19:12:06

Tanushiheadbash
Member
From: Stirling, Scotland
Registered: 07-20-2009
Posts: 82

Re: Correct way to extend a class in ECP/CCP7

I have managed to get a local copy of the shop running and can run it through my debugger in phpEd and am getting mor eof a handle on how it loads stuff and what globals are available. Not yet really that familiar with OOP yet and its going to take a lo tof time on my part but certainly using the debugger is helping me enormously as I can step through the application a line at a time and see what it does.
Thanks
K

Offline

 

#10 01-12-2010 14:32:35

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19798
Website

Re: Correct way to extend a class in ECP/CCP7

Check out the wiki article on enabling the built in debugger.  That will tell you exactly what's going on.


Nick Hendler

Offline

 

#11 01-17-2010 09:11:28

Tanushiheadbash
Member
From: Stirling, Scotland
Registered: 07-20-2009
Posts: 82

Re: Correct way to extend a class in ECP/CCP7

I use the inbuilt debugger but its no substitute really for actually stepping through the code and seeing it build the page. Its fine for diagnostics when you understand how it works inthe first place.
I got my class working externally and was able to extract my new method from the standard Display Class and it all seems to work fine.
Thanks

Offline

 

#12 01-17-2010 09:25:11

Dave
Member
Registered: 07-05-2003
Posts: 11233

Re: Correct way to extend a class in ECP/CCP7

There is no "stepping through the code" with PHP. The debug output details, in great detail, exactly what classes and includes are being called/used in what sequence.

Offline

 

#13 01-17-2010 19:18:35

Tanushiheadbash
Member
From: Stirling, Scotland
Registered: 07-20-2009
Posts: 82

Re: Correct way to extend a class in ECP/CCP7

Sorry but you are factually incorrect- you can step through the code in phpEd one line at a time. and see what every variable and attribute is doing, using the degugger tool. Totally excellent tool IMO.

Offline

 

#14 01-17-2010 19:23:10

Dave
Member
Registered: 07-05-2003
Posts: 11233

Re: Correct way to extend a class in ECP/CCP7

I said "with PHP" not with an external package such as phpEd not to mention that most people aren't going to drop over 200 dollars for a PHP tool like that.

Offline

 

#15 01-18-2010 08:01:41

Tanushiheadbash
Member
From: Stirling, Scotland
Registered: 07-20-2009
Posts: 82

Re: Correct way to extend a class in ECP/CCP7

OK Sorry misunderstood. I got it over Christmas there for less than £100 which I thought was good for the amount of time I spend up to my neck in code- cheaper than Zend too. A few recent investments in my arsenal have proved excellent- Navicat too is worth name dropping in this regard- makes SQL and database management so much more stress free.

K

Offline

 

#16 01-18-2010 08:09:00

Dave
Member
Registered: 07-05-2003
Posts: 11233

Re: Correct way to extend a class in ECP/CCP7

Wow, that's even more expensive than phpEd. I've been using plain old PHP with a text editor and phpMyAdmin for 9 years and have yet to discover a need to use expensive tools like that. But, everyone is different and I understand the desire for nice GUIs smile

Offline

 

#17 01-18-2010 17:13:20

Tanushiheadbash
Member
From: Stirling, Scotland
Registered: 07-20-2009
Posts: 82

Re: Correct way to extend a class in ECP/CCP7

Premium edition of Navicat is expensive but not the MYsql only version that I have. I have used phpMyAdmin for years too but with so many databases to manage its a pain having to login to the various hosting accounts to maintain them all. Its al lin one place with Navicat, building queries is infinitely easier than phpMyAdmin, backups and transferring dbs between hosts is really easy (by easy I mean MUCH faster than phpMyAdmin)- and you dinnae get the annoying back quotes phpMyAdmin chucks in. Ther eis a free trial version for 30 days its well worth trying. PS I have no affiliations  etc. My client also uses it to mnage the prods, cats tables etc as its like working in aspreadsheet and exports right in (xml too which is handy for some shipping programs)

Unlike you probably I am not natively a web developer or trained- in my day job I am a mobile telecomms core ngineer- I am all self taught from books and my first script in phpEd was SOOO much faster to throw together that I felt obliged to buy it while it was cheap- the in built debugger has just allowed me to sort the remote add to cart stuff I was asking about earlier as I could see what the shop was looking for inthe variables as it clocked them through. Worth every penny (or cent as you yanks have it ;-) )

Last edited by Tanushiheadbash (01-18-2010 17:17:11)

Offline

 

Board footer