[Solar-talk] extending app classes

Antti Holvikari anttih at gmail.com
Tue Jul 11 06:36:13 PDT 2006


Hi Jeff!

Maybe I can try to help on this one, if you will.

On 7/10/06, Jeff Surgeson <solar at 3hex.com> wrote:
> Hi
>
> Up until now all my solar based apps where extended from Solar_App, had a
> single data model that it called on and preformed basic list/edit/add/delete
> actions, nothing fancy.
>
> However I am trying to create a Vendor_App_Class that as before extends from
> Solar_App but I am able to extend, I think I need to give an example to
> explain.
>
> If for instance if I have Vendor_App_Product app with associated data model
> which is a class that describes a product (obvious) and in true OOP style I
> would like to extend it so I can describe differant products types,
> CdProduct, BookProduct, DvdProduct as apposed to creating a new app class
> with data model for each differant product.
>
> Is this possible in a Solar_App enviroment? if so what is the best way to go
> about it and how would I design a Solar data model to represent this?

It certainly is possible. This is how I would do it: Create a base
class Jeff_App_Product, and in it define protected properties
$_product and $_product_type. And also define function _preRun() which
has something like this:

$this->_product = Solar::factory('Jeff_Model_Product', array('type' =>
$this->_product_type));

Then create Jeff_App_Product_Dvd, *_Cd etc. classes. In them override
the $_product_type like this (for Jeff_App_Product_Cd):

protected $_product_type = 'cd';

Ofcourse you need your model to accept a config key 'type' for this to work.

After this you'll have your product model in all of your controllers
configured for certain product types. Finally, set 'classes' config
key for the front controller like so: array('Jeff_App_Product').
You'll have uris like this: www.example.com/cd */dvd.

> Any help would be appreciated.

Hope this helps.

-- 
Antti Holvikari <http://antti.dotgeek.org/blog>
Zend Certified Engineer (ZCE)


More information about the solar-talk mailing list