Getting information from a model inside of a model file

2014-02-03 Thread Jaz
For years I worked with a custom framework that was loosely based on CakePHP. In that framework, we could access the model data within a model file by using $this-PROPERTY_NAME. I have seen some Cake examples that use similar code, but for some reason, I can't get it to work. Here

Re: Getting information from a model inside of a model file

2014-02-03 Thread AD7six
add __get to your app model to make other properties accessible in the way you ask but ^ is the normal way to access a models data. AD -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed

Re: Getting information from a model inside of a model file

2014-02-03 Thread Jaz
information is to go through the data array: $this-data['InvoiceItem']['quantity']. You can add __get to your app model to make other properties accessible in the way you ask but ^ is the normal way to access a models data. AD -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us

Re: Form input Automagic on hasAndBelongsToMany when the model is not the model for the form?

2011-12-01 Thread phpMagpie
Can you show us an echo debug of your data array? -- 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

Re: Form input Automagic on hasAndBelongsToMany when the model is not the model for the form?

2011-11-30 Thread phpMagpie
That's a very deeply associated field, Cake is possibly struggling to complete the automagic that deep. You may struggle with a model called Session due to clash with the Session component. AFAIK, any ajax created or deleted fields will mess up the Security Hash as it's generated on page load

Re: Form input Automagic on hasAndBelongsToMany when the model is not the model for the form?

2011-11-30 Thread calzone
Thank you for answering. I was afraid the association might be too deep. Just to clarify one thing, the model is not named Session, I was just trying to describe the nature of my problem using model names here that would make more sense to people not intimately familiar with the project

Re: Form input Automagic on hasAndBelongsToMany when the model is not the model for the form?

2011-11-30 Thread calzone
Also to clarfiy, I have dumped $this-data at the view load time and have verified that all the data needed for the automagic population is present. So the problem is not at the query level, but would appear to be at the Helper level. -- Our newest site for the community: CakePHP Video

Form input Automagic on hasAndBelongsToMany when the model is not the model for the form?

2011-11-29 Thread calzone
I have a model (let's called it Sessions) that hasAndBelongsToMany Tags. Each Session belongsTo a Track Each Track belongsTo an Event Each Event belongs to an EventGroup A User may manage several EventGroups. For UX purposes, I have condensed the maintenance of all these into one form

Re: Easiest way to get data from a model (better way than $model-data['modelname']['field'])?

2011-02-24 Thread Joshua Muheim
Just in case somebody is interested... I have added a small method data() that works a little nicer in my opinion than the standard way of accessing the data array's values is... So instead of $this-Model-data['User']['name'] you can just call $this-Model-data('name')... saves you a few

Re: Easiest way to get data from a model (better way than $model-data['modelname']['field'])?

2011-02-24 Thread cricket
One slight change: you're $model param is superfluous. There's no need to pass the model as this is the AppModel. Just use $this when referencing it. I'd also check if $this-data exists before doing anything. OK, one other possibility: public function data() { if (empty($this-data

Re: Easiest way to get data from a model (better way than $model-data['modelname']['field'])?

2011-02-24 Thread LunarDraco
Great, so now when I need to build my view that displays data from four different models, I can call set a bunch of times in the controller for each model. come up with a whole new form helper to deal with data that does not have a model key. And deal with duplicate fields labeled 'id' in my html

Easiest way to get data from a model (better way than $model-data['modelname']['field'])?

2010-10-19 Thread psybear83
Hi everybody Sorry for this newbish question, but I don't seem to find much about this (although I should, I guess). $m = $this-Model-find(1); echo $m-data['Model']['something]; Is there a better way of getting a model's data fields instead of this? I always thought this could be done with $m

Re: Easiest way to get data from a model (better way than $model-data['modelname']['field'])?

2010-10-19 Thread euromark
nope but thats already a very neat way to do it what is your problem with it? On 19 Okt., 11:53, psybear83 psybea...@gmail.com wrote: Hi everybody Sorry for this newbish question, but I don't seem to find much about this (although I should, I guess). $m = $this-Model-find(1); echo $m-data

Re: Easiest way to get data from a model (better way than $model-data['modelname']['field'])?

2010-10-19 Thread Joshua Muheim
It looks really clumsy to me. What about the following? class AppModel extends Model { function data($field) { return $this-data[$this-name][$field]; } } First I was not sure why in the $data array there is a key 'ModelName', I would have expected something like this: array

Re: Easiest way to get data from a model (better way than $model-data['modelname']['field'])?

2010-10-19 Thread euromark
i think you are missing the obvious point is there a reason why this is done this way in cake? yes, there is trust the guys that work with since several years one example: you have a BelongsTo relationshop cake can easily get this data as well now you can do: $this-Model-recursive = 0; $m

Re: Easiest way to get data from a model (better way than $model-data['modelname']['field'])?

2010-10-19 Thread Joshua Muheim
Maybe I don't really understand your point, but as far as I see that's exactly what I've written here: Then I saw that every related model has its own key there, so it makes a bit sense. But why is the key in the array the model's name? Wouldn't it be better to have the name of the association

Re: Easiest way to get data from a model (better way than $model-data['modelname']['field'])?

2010-10-19 Thread Joshua Muheim
exactly what I've written here: Then I saw that every related model has its own key there, so it makes a bit sense. But why is the key in the array the model's name? Wouldn't it be better to have the name of the association in there? Because what when I have multiple associations to the same

Re: Easiest way to get data from a model (better way than $model-data['modelname']['field'])?

2010-10-19 Thread Jeremy Burns | Class Outfit
I think this is a mute point - it works really well as it is. If a model has a self join relationship with itself you give it a different model alias, so it will appear with that name in the data array, not the name of the model. For example, an employees table might have a self join to denote

Re: Easiest way to get data from a model (better way than $model-data['modelname']['field'])?

2010-10-19 Thread Joshua Muheim
Thanks for your explanations, sounds good. Still I think $model-data['Model']['field'] is very awkward. ;-) On Tue, Oct 19, 2010 at 4:26 PM, Jeremy Burns | Class Outfit jeremybu...@classoutfit.com wrote: I think this is a mute point - it works really well as it is. If a model has a self join

Re: Easiest way to get data from a model (better way than $model-data['modelname']['field'])?

2010-10-19 Thread Jeremy Burns | Class Outfit
for your explanations, sounds good. Still I think $model-data['Model']['field'] is very awkward. ;-) On Tue, Oct 19, 2010 at 4:26 PM, Jeremy Burns | Class Outfit jeremybu...@classoutfit.com wrote: I think this is a mute point - it works really well as it is. If a model has a self join

Re: Easiest way to get data from a model (better way than $model-data['modelname']['field'])?

2010-10-19 Thread Joshua Muheim
. Jeremy Burns Class Outfit jeremybu...@classoutfit.com http://www.classoutfit.com On 19 Oct 2010, at 16:34, Joshua Muheim wrote: Thanks for your explanations, sounds good. Still I think $model-data['Model']['field'] is very awkward. ;-) On Tue, Oct 19, 2010 at 4:26 PM, Jeremy Burns | Class

Re: Easiest way to get data from a model (better way than $model-data['modelname']['field'])?

2010-10-19 Thread Miles J
...@classoutfit.com http://www.classoutfit.com On 19 Oct 2010, at 16:34, Joshua Muheim wrote: Thanks for your explanations, sounds good. Still I think $model-data['Model']['field'] is very awkward. ;-) On Tue, Oct 19, 2010 at 4:26 PM, Jeremy Burns | Class Outfit jeremybu...@classoutfit.com

Re: Easiest way to get data from a model (better way than $model-data['modelname']['field'])?

2010-10-19 Thread cricket
On Tue, Oct 19, 2010 at 5:53 AM, psybear83 psybea...@gmail.com wrote: Hi everybody Sorry for this newbish question, but I don't seem to find much about this (although I should, I guess). $m = $this-Model-find(1); Since when does find() work like that? What version are you using? echo $m

Re: Easiest way to get data from a model (better way than $model-data['modelname']['field'])?

2010-10-19 Thread cricket
On Tue, Oct 19, 2010 at 8:30 AM, Joshua Muheim psybea...@gmail.com wrote: Then I saw that every related model has its own key there, so it makes a bit sense. But why is the key in the array the model's name? Wouldn't it be better to have the name of the association in there? What if you have

Re: Easiest way to get data from a model (better way than $model-data['modelname']['field'])?

2010-10-19 Thread cricket
On Tue, Oct 19, 2010 at 7:03 PM, cricket zijn.digi...@gmail.com wrote: On Tue, Oct 19, 2010 at 5:53 AM, psybear83 psybea...@gmail.com wrote: Hi everybody Sorry for this newbish question, but I don't seem to find much about this (although I should, I guess). $m = $this-Model-find(1); Since

how to get the reference of $this-model id ref in model class for virutal field

2010-09-25 Thread LampExpert
Hi, how to get the reference of $this-model id ref in model class for virutal field using cakephp version 1.3.1 i used virtual field is to get the sum of related amount for every id of studio_id var $virtualFields = array('balance' = 'select sum(j.amount) - ( ( (select sum(p.payment) from

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

Re: Accessing one model from another (unrelated) model

2010-06-30 Thread Jeremy Burns | Class Outfit
= 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

Re: Accessing one model from another (unrelated) model

2010-06-29 Thread Jeremy Burns | Class Outfit
://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

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

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

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

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

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

Re: model::updateAll not triggering model::beforeSave

2010-05-28 Thread mark_story
Model::updateAll is not intended to fire callbacks, as it could update an arbitrary number of records. If you need callbacks to be fired you'll have to use other methods. -Mark On May 28, 4:17 am, Ernesto e.fanz...@gmail.com wrote: Hello. i noticed that model::updateAll isn't triggering

Retrieve data in a model from another unassociated model

2010-02-04 Thread rich...@home
Hi all. I have a stand-alone (not associated with any other model) Setting model that contains key/value pairs containing user editable values used throughout my app (VAT rate, postal costs etc.) I'd like to get at this Setting data inside another model method (Order::calculateTotal

Re: Retrieve data in a model from another unassociated model

2010-02-04 Thread rich...@home
Never mind, found it :-) For anyone else looking for the answer here it is... In model: function foo() { $Setting = ClassRegistry::init('Setting'); $first_class_cost = $Setting-findValue(1st Class); } On Feb 4, 4:50 pm, rich...@home richardath...@gmail.com wrote: Hi all. I have

Re: Model Loading the Wrong Model

2009-01-18 Thread Webweave
Your belongsTo for 'Friend' is set up to use the 'User' model. If you want the Friend model loaded, you need to tell it to load that class instead. On Jan 16, 8:57 am, Chad Casselman ccassel...@gmail.com wrote: I am building a social network and work on the users, requests, friends portion

Re: To model or not to model

2008-09-25 Thread Grzegorz Pawlik
Still thinks that executing queries is needed? Yes. Sometimes You have uncommon database design, and You can't EFFECTIVELY receive data just by using standard, even magic, model functions. In that case you should create method in model that executes your custom query with inner, outer, left

Re: To model or not to model

2008-09-25 Thread Rafael Bandeira aka rafaelbandeira3
Still thinks that executing queries is needed? Yes. Sometimes You have uncommon database design, and You can't EFFECTIVELY receive data just by using standard, even magic, model Definetly correct, my sentence wasn't much happy. I meant for the cases he presented. Anyway, keep in mind

Re: To model or not to model

2008-09-24 Thread forrestgump
Thanks for the info guys...really appreciate it @RichardAtHome.whoops i forgot to mention the model inbetweentypo...thnx for pointing tht out Forrestgump On Sep 23, 2:54 pm, techiguy [EMAIL PROTECTED] wrote: hi forrestgump, using $this-find() in controller doesn't voilate the MVC

Re: To model or not to model

2008-09-24 Thread Rafael Bandeira aka rafaelbandeira3
Model built-in methods to accomplish the same? About performing custom find methods, with default/mandatory/pre- defined params you should read: http://rafaelbandeira3.wordpress.com/2008/08/28/the-new-way-to-define-find-methods/ http://cakebaker.42dh.com/2008/09/23/an-alternative-way

Re: To model or not to model

2008-09-24 Thread forrestgump
I dont think i asked anything bout using queries..i just wanted to know wht would be the best practice..but thnx for the info...will avoid $this-Model-query() On Sep 24, 4:32 pm, Rafael Bandeira aka rafaelbandeira3 [EMAIL PROTECTED] wrote: First of all people: what Rule? It's not made

Re: To model or not to model

2008-09-24 Thread forrestgump
Ohk...sry rafael...i did not read the entire thread On Sep 24, 5:17 pm, forrestgump [EMAIL PROTECTED] wrote: I dont think i asked anything bout using queries..i just wanted to know wht would be the best practice..but thnx for the info...will avoid $this-Model-query() On Sep 24, 4:32

Re: To model or not to model

2008-09-24 Thread dr. Hannibal Lecter
On Wed, Sep 24, 2008 at 1:32 PM, Rafael Bandeira aka rafaelbandeira3 [EMAIL PROTECTED] wrote: First of all people: what Rule? Rule of thumb perhaps? :) -- Misanthropy unleashed: http://dsi.vozibrale.com/ --~--~-~--~~~---~--~~ You received this message

Re: To model or not to model

2008-09-24 Thread Rafael Bandeira aka rafaelbandeira3
Rule of thumb perhaps? :) If you really mean it: Let's say rule of thumb isn't exactly a rule. Now, if you were being ironic: Yay right, that's the kind of rule that can be applied to a pattern! --~--~-~--~~~---~--~~ You received this message because you are

To model or not to model

2008-09-23 Thread forrestgump
Hey guys, Considering the fact that CakePhp follows the MVC architecture, id like to know...y we dont make function calls such as $this- find(where id=xyz) from function blocks typed out in Models rather than controllersim sure there is a logical reason to it...but someone asked me this

Re: To model or not to model

2008-09-23 Thread dr. Hannibal Lecter
fat models, thin controllers, meaning that you put as much as you can in your models. Maybe an example is better. Let's say you have a certain criteria for getting an article from the Article model. You can call this from a controller each time you want to get an article: $article = $this-Article

Re: To model or not to model

2008-09-23 Thread RichardAtHome
Also worth noting: A controller can have multiple Models. Which model would $this-find() use? On Sep 23, 12:28 pm, dr. Hannibal Lecter [EMAIL PROTECTED] wrote: Well, calling find() in a controller is not a violation, but not the best practice if overused. Of course, calling find() from

Re: To model or not to model

2008-09-23 Thread techiguy
hi forrestgump, using $this-find() in controller doesn't voilate the MVC architecture even if you use $this-find('all') but i heared if you direct query in controller will violate the MVC rule i.e if you use $this-Model-query(select * from models); the above query will violate the MVC rule

creating another model after saving a model

2007-08-15 Thread rtanz
hi i would like to create a Review model following the manual creation of a Module model. The associations are Module hasMany Review and Review belongsTo Module. Therefore i made a function that is run after a Module is saved. However this doesnt seem to be working well, i would appreciate if you

Re: creating another model after saving a model

2007-08-15 Thread cherrio
it appears that you are not passing in any info to save, thus not working, $this-Module-Review-save(); try, $this-Module-Review-save($this-data); hth, Rob On Aug 15, 4:57 pm, rtanz [EMAIL PROTECTED] wrote: hi i would like to create a Review model following the manual creation of a Module

accessing model from inside another model

2007-02-22 Thread teesea
I'm trying to access a model from another model when I perform a save, there is no association between the two, but in the system i am trying to complete one does have a logically effect on the other and I would like to run code in one model which then runs code on another. Anyone know how to do

Re: accessing model from inside another model

2007-02-22 Thread Riky Kurniawan
You can use: 1. app_model.php 2. request action in different controller 3. var uses if you want the 2 model in the same controller -- http://riky.kurniawan.us On 2/22/07, teesea [EMAIL PROTECTED] wrote: I'm trying to access a model from

RE: accessing model from inside another model

2007-02-22 Thread Mariano Iglesias
If there's no relation betweeen the two and you really need it, put this incide your model: loadModel('ModelB'); $ModelB = new ModelB(); And now you can use $ModelB as any normal model. -MI --- Remember, smart coders

Re: accessing model from inside another model

2007-02-22 Thread Riky Kurniawan
wow, I never realize loadModul Thanx Mariano -- http://riky.kurniawan.us On 2/22/07, Mariano Iglesias [EMAIL PROTECTED] wrote: If there's no relation betweeen the two and you really need it, put this incide your model: loadModel('ModelB

Re: accessing model from inside another model

2007-02-22 Thread teesea
no relation betweeen the two and you really need it, put this incide your model: loadModel('ModelB'); $ModelB = new ModelB(); And now you can use $ModelB as any normal model. -MI --- Remember, smart coders

Re: $this-Model-findAll() with a model over 5000 records.

2006-06-16 Thread davide
Maybe you can even use pagination[1] :) HTH bye Davide 1. http://wiki.cakephp.org/tutorials:pagination signature.asc Description: OpenPGP digital signature

Re: $this-Model-findAll() with a model over 5000 records.

2006-06-15 Thread Grant Cox
To retrieve that many records and instantiate the classes, it is using more than your PHP settings allow for a single script ( see memory_limit in your php.ini , default is 8MB ). So, you can either retrieve less records, or you can increase this memory limit. To only retrieve the 50 records

Re: $this-Model-findAll() with a model over 5000 records.

2006-06-15 Thread Carlos Mauricio Samour
Thanks that did the trick! Apreciate your help. I guess I will have to learn how pagination works to display all that data. On 6/15/06, Grant Cox [EMAIL PROTECTED] wrote: To retrieve that many records and instantiate the classes, it is using more than your PHP settings allow for a single

Re: $this-Model-findAll() with a model over 5000 records.

2006-06-15 Thread lorenzo
Carlos Mauricio Samour ha scritto: Hi everyone. I am having this problem trying to retrieve the data from one of my models. In my controller I use: function index(){ $this-set('data', $this-Product-findAll()); } set to the findAll function a field array: get only the

$this-Model-findAll() with a model over 5000 records.

2006-06-14 Thread Carlos Mauricio Samour
to allocate 48 bytes) in /home/msamour/www/cake/cake/libs/model/dbo/dbo_mysql.php on line 408 Before updating to cake 1.1.4.3083 I got an empty page. Now I get that message. I thought that cake automatically only retreaves 50 recods. What am I doing wrong. As a note I tried scaffolding and I got