Re: Accessing one model from another (unrelated) model

2010-06-30 Thread Erik Starck
Hi,
this is a bit more cakeish:

App::import('Product', 'Product');
$this-Product = new Product();

Now you can use the model as you ordinary would with e.g.
$this-Product-find(...)


Erik Starck
@erikstarck
http://www.softwaresweden.com

On Tue, Jun 29, 2010 at 5:12 PM, WhyNotSmile sharongilmor...@gmail.com wrote:
 Thanks for the replies.  Erik's solution worked (using
 ClassRegistry).  For some reason, loadModel threw an error.

 I may rewrite it to use a behaviour, but at least it's working for
 now!

 Thanks again,
 Sharon

 Check out the new CakePHP Questions site http://cakeqs.org and help others 
 with their CakePHP related questions.

 You received this message because you are subscribed to the Google Groups 
 CakePHP group.
 To post to this group, send email to cake-php@googlegroups.com
 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?hl=en


Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
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?hl=en


Re: Accessing one model from another (unrelated) model

2010-06-30 Thread Jeremy Burns | Class Outfit
Question: which is the preferred method; App::import or loadModel?

Jeremy Burns
Class Outfit

jeremybu...@classoutfit.com
http://www.classoutfit.com

On 30 Jun 2010, at 08:54, Erik Starck wrote:

 Hi,
 this is a bit more cakeish:
 
   App::import('Product', 'Product');
   $this-Product = new Product();
 
 Now you can use the model as you ordinary would with e.g.
 $this-Product-find(...)
 
 
 Erik Starck
 @erikstarck
 http://www.softwaresweden.com
 
 On Tue, Jun 29, 2010 at 5:12 PM, WhyNotSmile sharongilmor...@gmail.com 
 wrote:
 Thanks for the replies.  Erik's solution worked (using
 ClassRegistry).  For some reason, loadModel threw an error.
 
 I may rewrite it to use a behaviour, but at least it's working for
 now!
 
 Thanks again,
 Sharon
 
 Check out the new CakePHP Questions site http://cakeqs.org and help others 
 with their CakePHP related questions.
 
 You received this message because you are subscribed to the Google Groups 
 CakePHP group.
 To post to this group, send email to cake-php@googlegroups.com
 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?hl=en
 
 
 Check out the new CakePHP Questions site http://cakeqs.org and help others 
 with their CakePHP related questions.
 
 You received this message because you are subscribed to the Google Groups 
 CakePHP group.
 To post to this group, send email to cake-php@googlegroups.com
 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?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
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?hl=en


Re: Accessing one model from another (unrelated) model

2010-06-29 Thread Jeremy Burns | Class Outfit
I guess there are a few options. If the data is coming from a database, you 
could use loadModel wherever needed 
(http://book.cakephp.org/view/992/loadModel).

If it is not coming from a database (it's hard coded) you could use a behaviour 
from within the models that need the information. If you want to get to it  
from controllers only, then substitute behaviour for component, or you could 
even add the data to your config.php file and extract it using Configure::read.

I *think* the behaviour route would perform better.

Jeremy Burns
Class Outfit

jeremybu...@classoutfit.com
http://www.classoutfit.com

On 28 Jun 2010, at 23:36, WhyNotSmile wrote:

 I have a model which is kind of generic - it's a list of column
 names.  For some models, I need to get a list of all the column
 names.  However, I can't do this as they are not associated, so using
 the column model throws an error.
 
 I've a feeling I'm meant to be doing this in some other way - i.e.
 should the column names be something other than a model?  And how do I
 do that?
 
 Or is there a way to tell Cake that a particular model should be
 accessible from all others without having to define an association?
 
 I apologise if this is a very dumb question.
 
 Thanks!
 Sharon
 
 Check out the new CakePHP Questions site http://cakeqs.org and help others 
 with their CakePHP related questions.
 
 You received this message because you are subscribed to the Google Groups 
 CakePHP group.
 To post to this group, send email to cake-php@googlegroups.com
 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?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
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?hl=en


Re: Accessing one model from another (unrelated) model

2010-06-29 Thread Anthony
You could make use of the $uses variable.

Say you need to access the unrelated table Bar from controller Foo,
you would add a uses variable for something like:

$uses = array('Foo', 'Bar');


On Jun 28, 5:36 pm, WhyNotSmile sharongilmor...@gmail.com wrote:
 I have a model which is kind of generic - it's a list of column
 names.  For some models, I need to get a list of all the column
 names.  However, I can't do this as they are not associated, so using
 the column model throws an error.

 I've a feeling I'm meant to be doing this in some other way - i.e.
 should the column names be something other than a model?  And how do I
 do that?

 Or is there a way to tell Cake that a particular model should be
 accessible from all others without having to define an association?

 I apologise if this is a very dumb question.

 Thanks!
 Sharon

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
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?hl=en


Re: Accessing one model from another (unrelated) model

2010-06-29 Thread Erik Starck
...but the question was a model in a  model, not in a controller.

I'm using this in my model class:

  $Category = ClassRegistry::init(Category);
  $category = $Category-findById($underThisCategoryId);

Don't know if there's a better way. loadModel would be nicer I suppose.


BR Erik

On Tue, Jun 29, 2010 at 4:32 PM, Anthony anthony.c.fra...@gmail.com wrote:
 You could make use of the $uses variable.

 Say you need to access the unrelated table Bar from controller Foo,
 you would add a uses variable for something like:

 $uses = array('Foo', 'Bar');


 On Jun 28, 5:36 pm, WhyNotSmile sharongilmor...@gmail.com wrote:
 I have a model which is kind of generic - it's a list of column
 names.  For some models, I need to get a list of all the column
 names.  However, I can't do this as they are not associated, so using
 the column model throws an error.

 I've a feeling I'm meant to be doing this in some other way - i.e.
 should the column names be something other than a model?  And how do I
 do that?

 Or is there a way to tell Cake that a particular model should be
 accessible from all others without having to define an association?

 I apologise if this is a very dumb question.

 Thanks!
 Sharon

 Check out the new CakePHP Questions site http://cakeqs.org and help others 
 with their CakePHP related questions.

 You received this message because you are subscribed to the Google Groups 
 CakePHP group.
 To post to this group, send email to cake-php@googlegroups.com
 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?hl=en


Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
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?hl=en


Re: Accessing one model from another (unrelated) model

2010-06-29 Thread Anthony
..but the question was a model in a  model, not in a controller.

Ah, that's my bad.  Sorry.

On Jun 29, 9:40 am, Erik Starck erik.sta...@gmail.com wrote:
 ...but the question was a model in a  model, not in a controller.

 I'm using this in my model class:

   $Category = ClassRegistry::init(Category);
   $category = $Category-findById($underThisCategoryId);

 Don't know if there's a better way. loadModel would be nicer I suppose.

 BR Erik

 On Tue, Jun 29, 2010 at 4:32 PM, Anthony anthony.c.fra...@gmail.com wrote:
  You could make use of the $uses variable.

  Say you need to access the unrelated table Bar from controller Foo,
  you would add a uses variable for something like:

  $uses = array('Foo', 'Bar');

  On Jun 28, 5:36 pm, WhyNotSmile sharongilmor...@gmail.com wrote:
  I have a model which is kind of generic - it's a list of column
  names.  For some models, I need to get a list of all the column
  names.  However, I can't do this as they are not associated, so using
  the column model throws an error.

  I've a feeling I'm meant to be doing this in some other way - i.e.
  should the column names be something other than a model?  And how do I
  do that?

  Or is there a way to tell Cake that a particular model should be
  accessible from all others without having to define an association?

  I apologise if this is a very dumb question.

  Thanks!
  Sharon

  Check out the new CakePHP Questions sitehttp://cakeqs.organd help others 
  with their CakePHP related questions.

  You received this message because you are subscribed to the Google Groups 
  CakePHP group.
  To post to this group, send email to cake-php@googlegroups.com
  To unsubscribe from this group, send email to
  cake-php+unsubscr...@googlegroups.com For more options, visit this group 
  athttp://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
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?hl=en


Re: Accessing one model from another (unrelated) model

2010-06-29 Thread WhyNotSmile
Thanks for the replies.  Erik's solution worked (using
ClassRegistry).  For some reason, loadModel threw an error.

I may rewrite it to use a behaviour, but at least it's working for
now!

Thanks again,
Sharon

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
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?hl=en


Accessing one model from another (unrelated) model

2010-06-28 Thread WhyNotSmile
I have a model which is kind of generic - it's a list of column
names.  For some models, I need to get a list of all the column
names.  However, I can't do this as they are not associated, so using
the column model throws an error.

I've a feeling I'm meant to be doing this in some other way - i.e.
should the column names be something other than a model?  And how do I
do that?

Or is there a way to tell Cake that a particular model should be
accessible from all others without having to define an association?

I apologise if this is a very dumb question.

Thanks!
Sharon

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
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?hl=en