Guess I was right about sub classing with Cake.





On Dec 6, 9:34 am, RhythmicDevil <[email protected]> wrote:
> Ok so I tried extending the AppModel class to a third level sub class
> but Cake fails to find it. Perhaps you can clue me in to where I am
> going wrong.
>
> I have the following file structure:
>
> Models/
>     AppModel
>     GtiApi
>     Solidcore
>
> Here are what the class files contain:
>
> class AppModel extends Model
> {
>     public function __construct()
>     {
>         parent::__construct();
>     }
>
> }
>
> class GtiApi extends AppModel
> {
>
>     public $useDbConfig = 'gti';
>     public $useTable = false;
>
>     public function __construct()
>     {
>         parent::__construct();
>     }
>
>     // Some custom functions here that I did not paste due to space
> for this post
>
> }
>
> class Solidcore extends GtiApi
> {
>
>     public function __construct()
>     {
>         parent::__construct();
>     }
>
> }
>
> This is the error that I get when I attempt to load a 
> page:http://swright-dev.epic-cake/solidcores/performance
>
> Fatal error: Class 'GtiApi' not found in /var/www/html/epic-cake/app/
> models/solidcore.php on line 4
>
> So that means to me that Cake's autoloaders dont expect more than one
> level of subclass for AppModel. How do I get around that?
>
> On Dec 5, 4:04 pm, Miles J <[email protected]> wrote:
>
>
>
>
>
>
>
> > Cake simply has trouble when trying to merge properties in one class
> > with the AppClass. This should only be a problem with the
> > AppController since you aren't defining many properties in AppModel.
>
> > On Dec 5, 12:34 pm, RhythmicDevil <[email protected]> wrote:
>
> > > Yeah I had thought, and now have to go and check, that you could never
> > > extend passed one sub class from AppModel or AppController for that
> > > matter. I always thought that was odd but had something to do with
> > > cake's auto loaders. Thanks for the clue, I will check this out.
>
> > > On Dec 5, 3:11 pm, Miles J <[email protected]> wrote:
>
> > > > Are you referring to where the files go?
>
> > > > You can do anything in Cake that PHP allows, so extend as many times
> > > > as you please.
>
> > > > On Dec 5, 11:54 am, RhythmicDevil <[email protected]> wrote:
>
> > > > > Hi Miles,
> > > > > thanks for the response. Yeah I think that would be the number 3
> > > > > option I Iisted.
>
> > > > > The thing is how would I do the following:
>
> > > > > AppModel
> > > > >     DbBaseModel
> > > > >          SomeModel
> > > > >     ApiBaseModel
> > > > >          AnotheModel
>
> > > > > To the best of my knowledge you can actually build that kind of
> > > > > heirarchy in Cake right?
>
> > > > > On Dec 5, 2:49 pm, Miles J <[email protected]> wrote:
>
> > > > > > You could always just create 2 base models?
>
> > > > > > class ApiBaseModel extends AppModel {}
> > > > > > class DbBaseModel extends AppModel {}
>
> > > > > > They both would extend AppModel to gain shared functionality and 
> > > > > > then
> > > > > > both would have their own functionality. Cake IS PHP, so you can do
> > > > > > whatever you want with classes.
>
> > > > > > class User extends DbBaseModel {}
> > > > > > class News extends ApiBaseModel {}
>
> > > > > > -Miles
>
> > > > > > On Dec 5, 11:29 am, RhythmicDevil <[email protected]> wrote:
>
> > > > > > > My application has two datasources. I use one to talk to MySQL for
> > > > > > > ACL. The other is a custom datasource that talks an API my 
> > > > > > > company is
> > > > > > > developing. There are about 15 models that use the custom 
> > > > > > > datasource
> > > > > > > and will probably be more. For each of those models I need to 
> > > > > > > share
> > > > > > > methods and  properties but DO NOT want the ACL models to have 
> > > > > > > them so
> > > > > > > they cannot go into AppModel.
>
> > > > > > > The reason I have many models for the API is that I want the data
> > > > > > > structures returned by the Model to have the correct naming. I 
> > > > > > > suppose
> > > > > > > I could set the name on the fly but for now I am curious how to 
> > > > > > > solve
> > > > > > > this other problem.
>
> > > > > > > Do behaviors solve this problem? I did not think that was really 
> > > > > > > their
> > > > > > > function. These are the properties and methods I need shared and 
> > > > > > > it
> > > > > > > has to do with how the datasource works.
>
> > > > > > >     public $useDbConfig = 'gti';
> > > > > > >     public $useTable = false;
>
> > > > > > >     public function __construct()
> > > > > > >     {
> > > > > > >         parent::__construct();
> > > > > > >     }
>
> > > > > > >     /**
> > > > > > >      * Overridden paginate method - group by week, away_team_id 
> > > > > > > and
> > > > > > > home_team_id
> > > > > > >      */
> > > > > > >     function paginate($conditions, $fields, $order, $limit, $page 
> > > > > > > = 1,
> > > > > > > $recursive = null, $extra = array())
> > > > > > >     {
> > > > > > >         //var_dump($conditions, $fields, $order, $limit, $page,
> > > > > > > $recursive, $extra);
> > > > > > >         $recursive = -1;
> > > > > > >         //$group = $fields = array('week', 'away_team_id',
> > > > > > > 'home_team_id');
> > > > > > >         return $this->find('all', compact('conditions', 'fields',
> > > > > > > 'order', 'limit', 'page', 'recursive'));
> > > > > > >     }
>
> > > > > > >     /**
> > > > > > >      * Overridden paginateCount method
> > > > > > >      */
> > > > > > >     function paginateCount($conditions = null, $recursive = 0, 
> > > > > > > $extra
> > > > > > > = array())
> > > > > > >     {
> > > > > > >         //var_dump($conditions, $recursive, $extra);
> > > > > > >         return 1000;
> > > > > > >         $sql = "SELECT DISTINCT ON(week, home_team_id, 
> > > > > > > away_team_id)
> > > > > > > week, home_team_id, away_team_id FROM games";
> > > > > > >         $this->recursive = $recursive;
> > > > > > >         $results = $this->query($sql);
> > > > > > >         return count($results);
> > > > > > >     }
>
> > > > > > > I see the following options:
>
> > > > > > > 1. Place the code in the AppModel file and then do some work every
> > > > > > > time those methods and properties are needed to decide whether I 
> > > > > > > use
> > > > > > > these or the other. That seems like a lot of work.
>
> > > > > > > 2. Duplicate the code in each model
>
> > > > > > > 3. Use one model for the API and then just set it's name so that 
> > > > > > > my
> > > > > > > data structures are named correctly.
>
> > > > > > > And again, behavior? Probably not, but figured I'd ask one more 
> > > > > > > time.
>
> > > > > > > Thanks for any advice.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to