Re: Shared code for Models but not in AppModel

2011-12-08 Thread RhythmicDevil
Thats great Geoff thank you.

On Dec 7, 5:08 pm, Geoff Douglas  wrote:
> I think you have most elements i place... I think the thing that is getting
> confusing is how cake is suppose to load the classes.
>
> So here's the kicker. Cake only "loads" models if they are related to
> something that you are using. I will use an example from my world to
> illustrate.
>
> I have a Prototype Model, that is used in the PrototypesController. This
> model belongs to a Creator (from the users table), and belongs to a
> Designer (also from the users table). I have a User Model, that only
> handles the logic for logging in and out and user Identity stuff. So the
> User model doesn't have any relationship to the Prototype Model.
> I created a Designer Model, that extends the User Model. I can use this
> Designer Model just like the User model, because it inherits all the
> methods, but it can contain it's own relationships to Prototype. It doesn't
> always inherit the properties though, and I will tell you why I like
> that... because you can then do what you want as far as tables go, and
> datasources. So, just because you extend the User model, it doesn't mean
> that you have to use the users table... If how ever you need to get
> properties, you can access them via $this, if they are not static, and
> parent::someProperty if it is static.
>
> So, as I said in my Prototype Model I have a belongsTo Designer, so I use
> my Designer Model, and NOT the User Model, in that definition. Now in my
> PrototypesController I can access the Design model like any other related
> model using the chain.
> $this->Prototype->Designer->someMethodInEitherDesignerOrUserModel()
>
> If you are needing to initiate a model on the fly, that's not related, you
> can use ClassRegistry::init('Designer') OR if in a controller I think you
> can use $this->loadModel('Designer') (Which is just a helper to the first
> one) and use it the same way.
>
> Anyways, hope that helps. Let me know if I can clarify, or didn't explain
> anything clearly.

-- 
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
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Shared code for Models but not in AppModel

2011-12-07 Thread Geoff Douglas
I think you have most elements i place... I think the thing that is getting 
confusing is how cake is suppose to load the classes.

So here's the kicker. Cake only "loads" models if they are related to 
something that you are using. I will use an example from my world to 
illustrate.

I have a Prototype Model, that is used in the PrototypesController. This 
model belongs to a Creator (from the users table), and belongs to a 
Designer (also from the users table). I have a User Model, that only 
handles the logic for logging in and out and user Identity stuff. So the 
User model doesn't have any relationship to the Prototype Model.
I created a Designer Model, that extends the User Model. I can use this 
Designer Model just like the User model, because it inherits all the 
methods, but it can contain it's own relationships to Prototype. It doesn't 
always inherit the properties though, and I will tell you why I like 
that... because you can then do what you want as far as tables go, and 
datasources. So, just because you extend the User model, it doesn't mean 
that you have to use the users table... If how ever you need to get 
properties, you can access them via $this, if they are not static, and 
parent::someProperty if it is static.

So, as I said in my Prototype Model I have a belongsTo Designer, so I use 
my Designer Model, and NOT the User Model, in that definition. Now in my 
PrototypesController I can access the Design model like any other related 
model using the chain. 
$this->Prototype->Designer->someMethodInEitherDesignerOrUserModel()

If you are needing to initiate a model on the fly, that's not related, you 
can use ClassRegistry::init('Designer') OR if in a controller I think you 
can use $this->loadModel('Designer') (Which is just a helper to the first 
one) and use it the same way. 

Anyways, hope that helps. Let me know if I can clarify, or didn't explain 
anything clearly.

-- 
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
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Shared code for Models but not in AppModel

2011-12-07 Thread Miles J
Cake just doesn't have a true autoloader so you need to include the
file yourself or use the App class.

On Dec 7, 12:38 pm, RhythmicDevil  wrote:
> Well the basic idea is that the application uses two datasources. One
> is the MySQL one the other is a custom one I wrote for our API. The
> Models that use the custom datasource require some methods and
> properties, I posted those in the initial question on this thread.
> Normally I would just put those in AppModel and be done with it. But,
> they break the models that use MySQL so AppModel is not the
> appropriate place.
>
> So what I wanted to do was have AppModel at the top of the chain
> containing all common Model code. Then extend that to GtiApi, User,
> and Group. GtiApi would contain the methods and properties I
> mentioned. Then API driven Models like Solidcore would extend GtiApi.
> This now works.
>
> In reality though I actually dont "need" the Solidcore models, I could
> really just use GtiApi model and then do something fancy so that Model
> data was under the right index, say  "Solidcore". That way the
> controller and views would work properly as well. Currently the Models
> that extend GtiApi are empty. There may be a case for doing some extra
> Model work in some of them, but I dont have all the requirements yet.
>
> On Dec 7, 11:19 am, Geoff Douglas  wrote:
>
>
>
>
>
>
>
> > Where are you trying to use the Solidcore Model?
>
> > I have done what you are explaining several times. Generally to apply
> > different relationships to the same models, for better performance, and
> > cleaner code.
>
> > It is possible. And it is not breaking "the Cake way" to do it either. Cake
> > is very versatile, especially with how models work.
>
> > Let me know.

-- 
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
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Shared code for Models but not in AppModel

2011-12-07 Thread RhythmicDevil
Well the basic idea is that the application uses two datasources. One
is the MySQL one the other is a custom one I wrote for our API. The
Models that use the custom datasource require some methods and
properties, I posted those in the initial question on this thread.
Normally I would just put those in AppModel and be done with it. But,
they break the models that use MySQL so AppModel is not the
appropriate place.

So what I wanted to do was have AppModel at the top of the chain
containing all common Model code. Then extend that to GtiApi, User,
and Group. GtiApi would contain the methods and properties I
mentioned. Then API driven Models like Solidcore would extend GtiApi.
This now works.

In reality though I actually dont "need" the Solidcore models, I could
really just use GtiApi model and then do something fancy so that Model
data was under the right index, say  "Solidcore". That way the
controller and views would work properly as well. Currently the Models
that extend GtiApi are empty. There may be a case for doing some extra
Model work in some of them, but I dont have all the requirements yet.



On Dec 7, 11:19 am, Geoff Douglas  wrote:
> Where are you trying to use the Solidcore Model?
>
> I have done what you are explaining several times. Generally to apply
> different relationships to the same models, for better performance, and
> cleaner code.
>
> It is possible. And it is not breaking "the Cake way" to do it either. Cake
> is very versatile, especially with how models work.
>
> Let me know.

-- 
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
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Shared code for Models but not in AppModel

2011-12-07 Thread Geoff Douglas
Where are you trying to use the Solidcore Model?

I have done what you are explaining several times. Generally to apply 
different relationships to the same models, for better performance, and 
cleaner code.

It is possible. And it is not breaking "the Cake way" to do it either. Cake 
is very versatile, especially with how models work.

Let me know.

-- 
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
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Shared code for Models but not in AppModel

2011-12-07 Thread RhythmicDevil
Thanks man. I dont actually expect magic. Although Cake does do some
things magically, I am never sure where the magic ends and my
ignorance begins. In all my searching I never actually found a
document that stated what you did. I realized that I could load the
classes but was not sure if I was somehow stepping around the
framework. I always try to do things in the Cake way if at all
possible.



On Dec 7, 9:22 am, AD7six  wrote:
> On Dec 7, 3:11 pm, RhythmicDevil  wrote:
>
> > No actually. I created the file and class structure as shown above. I
> > get an error from PHP saying class not found. So unless I have to add
> > includes or requires to my files Cake does not load the classes.
>
> well, yes. since Cake is just php, and that's how php works.
>
>
>
> > So Cake handles this just fine:
>
> > AppModel->SubClass
> > AppMode->AnotherSubClass
>
> It handles that case automatically.
>
>
>
> > But not this
>
> > AppModel->SubClass->AnotherSubClass
>
> It does not handle that case automatically - it does however handle it
> 'fine'.
>
>
>
> > If I am wrong about this please tell me where I am going wrong. Please
> > see my example above.
>
> CakePHP isn't magic. It does somethings for you "automagically". If
> you're using 1.3 you must load the classes before you use them, if
> you're using 2.0 you must declare you are going to use them before
> using them.
>
> the only thing cake does for you (in 1.3) is automatically load App
> classes for you. In 2.0 it doesn't do that any more 
> seehttps://github.com/cakephp/cakephp/blob/master/lib/Cake/Model/AppMode...
> But you aren't talking about App classes - you're talking about some
> other classes, and you need to load/use the classes before you can
> reference them.
>
> AD

-- 
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
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Shared code for Models but not in AppModel

2011-12-07 Thread AD7six


On Dec 7, 3:11 pm, RhythmicDevil  wrote:
> No actually. I created the file and class structure as shown above. I
> get an error from PHP saying class not found. So unless I have to add
> includes or requires to my files Cake does not load the classes.

well, yes. since Cake is just php, and that's how php works.

>
> So Cake handles this just fine:
>
> AppModel->SubClass
> AppMode->AnotherSubClass

It handles that case automatically.

>
> But not this
>
> AppModel->SubClass->AnotherSubClass

It does not handle that case automatically - it does however handle it
'fine'.

>
> If I am wrong about this please tell me where I am going wrong. Please
> see my example above.

CakePHP isn't magic. It does somethings for you "automagically". If
you're using 1.3 you must load the classes before you use them, if
you're using 2.0 you must declare you are going to use them before
using them.

the only thing cake does for you (in 1.3) is automatically load App
classes for you. In 2.0 it doesn't do that any more see
https://github.com/cakephp/cakephp/blob/master/lib/Cake/Model/AppModel.php#L23
But you aren't talking about App classes - you're talking about some
other classes, and you need to load/use the classes before you can
reference them.

AD

-- 
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
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Shared code for Models but not in AppModel

2011-12-07 Thread RhythmicDevil
No actually. I created the file and class structure as shown above. I
get an error from PHP saying class not found. So unless I have to add
includes or requires to my files Cake does not load the classes.

So Cake handles this just fine:

AppModel->SubClass
AppMode->AnotherSubClass

But not this

AppModel->SubClass->AnotherSubClass

If I am wrong about this please tell me where I am going wrong. Please
see my example above.

Thank you.



On Dec 7, 8:55 am, AD7six  wrote:
> On Dec 7, 1:55 pm, RhythmicDevil  wrote:
>
> > Guess I was right about sub classing with Cake.
>
> what was your guess - that they work exactly the same way as the
> language itself?

-- 
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
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Shared code for Models but not in AppModel

2011-12-07 Thread AD7six


On Dec 7, 1:55 pm, RhythmicDevil  wrote:
> Guess I was right about sub classing with Cake.

what was your guess - that they work exactly the same way as the
language itself?

-- 
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
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Shared code for Models but not in AppModel

2011-12-07 Thread RhythmicDevil
Guess I was right about sub classing with Cake.






On Dec 6, 9:34 am, RhythmicDevil  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  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  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  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  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  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  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;
> > > > > 

Re: Shared code for Models but not in AppModel

2011-12-06 Thread RhythmicDevil
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  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  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  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  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  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  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, $recurs

Re: Shared code for Models but not in AppModel

2011-12-05 Thread Miles J
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  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  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  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  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  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
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Shared code for Models but not in AppModel

2011-12-05 Thread RhythmicDevil
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  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  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  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  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
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Shared code for Models but not in AppModel

2011-12-05 Thread Miles J
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  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  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  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
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Shared code for Models but not in AppModel

2011-12-05 Thread Tilen Majerle
yes you can
--
Lep pozdrav, Tilen Majerle
http://majerle.eu



2011/12/5 RhythmicDevil 

> 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  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  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
> cake-php+unsubscr...@googlegroups.com For more options, visit this group
> at http://groups.google.com/group/cake-php
>

-- 
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
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Shared code for Models but not in AppModel

2011-12-05 Thread RhythmicDevil
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  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  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
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Shared code for Models but not in AppModel

2011-12-05 Thread Miles J
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  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
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php