Saturday, February 27, 2010

Re: how to adress specific data from related models?

Hi Paul, I heard your scream still here in Germany ;-)
Thanks so far .. it is hard to learn cake with only one book in my
native language and two other books written in english but nor realy
wrote to fit my needs (they are more done to show hot to do a specific
project with cake).

I think with your help and use of the debug() function I managed to
solve the problem so far. - this time ...
It looks as if I still have problems to use the multidimensional
arrays inside of cake in the right manner/way because indexing makes a
lot of trouble.

The code yiu posted here to me still did me some error messages till I
changed some parts and got this:

$Y1=$this->Lodging-
>find('first',array('conditions'=>array('Lodging.id'=>$this-
>data['BookingPosition']['lodging_id'])));
//debug($Y1);
echo $Y1['Lodging']['NumberOfBeds'];

as part of my own custom validation function inside the model.

It's the same rersult like my quick and dirty code I posted before
$A = $this->query("SELECT Bettenanzahl FROM Lodgings WHERE
id=" . $this->data['BookingPosition']['lodging_id'] );

So thanks a lot for showing me there is a better way than using a
query; I'll try to keep in mind the find () syntax
..... started to do me my own cake sheet/minibook to keep all the
hints I get here :)

Now I can proceed with my project and shure soon with new questions as
well.

Have a nice weekend.

Michael

On 26 Feb., 10:29, WebbedIT <p...@webbedit.co.uk> wrote:
> Nooooooo (screamed in a big dramatic 'stop the wedding' type styleee)
>
> If you resort to using Model->query() you're never going to get your
> head around the basics of cake which sort of negates the point of
> using Cake in the first place.  Honestly, querying related models is
> so simple, I gave you the code further up this post.
>
> If you are wanting to find a field's value from a record within the
> Lodging model and you have the record's id available at $this-
>
> >data['BookingPosition']['lodging_id']  you need to run Model->field()
>
>   $value = $this->BookingPosition->Lodging->field('your_field_name',
> array('Lodging.id'=>$this->data['BookingPosition']['lodging']));
>
> Or you can pull the whole record by using the convenience method Model-
>
> >findBy()
>
>   $record = $this->BookingPosition->Lodging->findById($this-
>
> >data['BookingPosition']['lodging']);
>
> Or using Model->find()
>
>   $record = $this->BookingPosition->Lodging->find('first',
> array('conditions'=>array('Lodging.id'=>$this->data['BookingPosition']
> ['lodging'])));
>
> You really need to get your head around Naming Conventions,
> Controllers, Models, Associations, Retrieving and Saving data etc. and
> the best way to do that is learnt he cookbook inside out, it's all
> there for you to reference at any time.
>
> Paul

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

No comments: