Nothing to add apart from props to Rafael for an excellent answer.
On Aug 23, 2:05 am, Rafael Bandeira aka rafaelbandeira3
<[EMAIL PROTECTED]> wrote:
> Oh, I almost slept, you should try to more clear and less verborragic,
> so many explanation just messed up things more and more...
> And you should do 2 things when you can't speak a language : 1) look
> for groups with the same language of yours and 2) say your
> nacionality, so members from the same country can get sensible with
> you and try to help you more....
>
> "stop the bullshit and answer me..."
>
> OK, answers :
>
> > 1) Do I have to manually set up Foreign keys for tables?
>
> it depends, did you sitcked to conventions?
> Your CarAd Model has the following scheme and linking convention:
>
> id - primaryKey
> car_type_id - className => CarType, uses table ->
> car_types
>
> car_brand_id - className => CarBrand, uses table ->
> car_brands
>
> car_fuel_id - className => CarFuel, uses table
> -> car_fuels
> car_transmission_id - className => CarTransmission, uses
> table -> car_transmissions
> year
> ad_county_id - className => AdCountry, uses table
> -> ad_countries
> ad_borough_id - className => AdBorough, uses table ->
> ad_boroughs (?)
>
> info
> price
> car_ad_type_id - className => CarAdType, uses tabl ->
> car_ad_types
>
> added <- tip : is this field meant to hold the
> datetime of row creation? if yes, rename it to "created" and cakePHP
> will handle it for you
>
> Said that all this foreign keys says : this CarAd belongs to this
> CarType, and to this CarBrand, and to that CarFuel... so you should
> have in your model class:
>
> class CarAd extends AppModel {
> var $belongsTo = array (
> 'CarType', 'CarBrand', 'CarFuel', 'CarType',
> 'CarTransmission', 'AdCountry', 'AdBorough',
> )
>
> }
>
> now CakePHP will map all your model's foreign keys and you will be
> able to access this relateds models as a property of your CarAd
> model :
> // inside your model
> $this->CarType->find([...]);
> inside your controller
> $this->CarAd->CarType->find([...]);
>
> answered? moving on...
>
> > 2) Do I have to build model for each table I need to get id's
> > from..even if the table itself will stay static ? (model for
> > car_transmissions, car_fuels_id... tables)
>
> No, actually CakePHP map table names for you too.
> >>http://www.littlehart.net/atthekeyboard/2008/08/05/dynamic-models-in-...
>
> > By static I mean that I don't need to add or delete data from it
> > because probably there will not be any new transmission types
> > coming..... I only need to read info from it.
>
> > I know 100% that I have to build model for tables which will have
> > dynamic content...like table car_brand. (new car brand comes.. for ex.
> > "BMW-Jaguar"..and I need to add it to table from site...not manually)
>
> you should avoid this kind of thinking...
>
> > So my main table at this time is car_ads and I have controller for
> > it... and it also gives me it's table contents with simple index():
> > function index() {
> > $this->set('carads',$this->CarAd->find('all'));
> > }
>
> > But I want to see text in the list..not that number which I have on
> > car_transmission_id field. (Instead of number 1 I would like to see
> > text: "Automatic")
> > Currently line looks like this: Brand: 5 Year: 2000 Transmission: 1
> > Gas: 2
> > But it should look like this: Brand: Chevrolet Astro Year: 2000
> > Transmission: Automatic Gas: Benzine
>
> No actually it shouldn't, what is happening is the normal and expected
> behavior.
>
> I'll explain what is already in the manual about cakePHP's data
> scheme, I'll wont reproduce arrays here because it would be very ugly
> and painfull for me so take this as example
> :http://book.cakephp.org/view/448/findall
> -> the grey box at the bottom of the content...
>
> that's how your data will return but with the your model names...
> back to your CarAdsController::index() :
>
> > function index() {
> > $this->set('carads',$this->CarAd->find('all'));
> > }
>
> in your view you will have a var named 'carads', and you'll be able to
> access data as the array in the link shows :
> // first entry's CarTransmission.transmission wil be accessed like
> this
> echo $carads[0]['CarTransmission']['transmission'];
>
> // the nth entry/row CarBrand.name will be accessed like this
> echo $carads[$num]['CarBrand']['name'];
>
> for a dynamic list or table generation, you would do something like
> this:
> foreach($carads as $entryNum => $entryData)
> {
> echo 'Transmission: ' . $entryData['CarTransmission']
> ['transmission'];
> echo 'Brand : ' . $entryData['CarBrand']['name'];
> echo 'Country : <a href="/view/country/' . $entryData['CarCountry']
> ['id'] . '" title="view country:' . $entryData['CarCountry']
> ['name'] . '"> ' . $entryData['CarCountry']['name'] . '</a>';
>
> }
> > I'll try to explain it once more..maybe it helps to clear things out:
>
> you actually didn't explain anything, just asked more questions ;-)
>
> > 1) I have table car_ads which will hold car ads... to that table will
> > be added all kind of info... car brand, car transmission type, fuel
> > type.. info, make year. Most things should be choosed from other
> > tables...so when I'm inserting a new ad, I should see dropdown list
> > for "Car transmission". And when I select from that list "Automatic"
> > then equaling id will be added to table car_ads into
> > car_transmission_id field.
>
> never say "I should be able" things must be done, CakePHP is a full of
> good stuffs framework, but it is no David Blaine
> ->http://www.youtube.com/watch?v=AYxu_MQSTTY
>
> read the following links to get help with form elements
> creation:http://book.cakephp.org/view/182/formhttp://book.cakephp.org/view/455/generatelist
>
> oh last link i couldn't find... it's a link wich talks about the
> magicall dropdown fill up cakePHP form helper does with vars passed to
> views... it's a good reference for newbies...
>
> but basically you can do this: in the action wich displays your form,
> the one users will be able to create new ads, probably
> CarAdsController::create(), you should setup vars with your
> association's table names :
> function create() {
> if(!empty($this->data)) {
> $this->CarAd->create($this->data);
> $this->CarAd->save();
> }
>
> $car_transmissions = $this->CarAd->CarTransmission->find('all');
> $this->set('car_transmissions', $car_transmissions);
> $car_brands = $this->CarAd->CarBrand->find('all');
> $this->set('car_brands', $car_brands );
> [...]
>
> }
>
> And in your view:
> // create.ctp
> echo $form->input('CarAd.car_transmission_id');
> echo $form->input('CarAd.car_brand_id');
>
> And *TCHARAM!*: I rock and I'm a cheater? Pure CakePHP magic? or
> PhpNut and it's companion's skills to your rescue? --- All of
> them! :-)
>
> > 2) When I enter the index(), then list of ads will be displayed...but
> > how to make it show text instead of different id's ?
>
> answered above.
>
> > Big thanks to anyone who helps me getting back on tracks.
>
> You're welcome! Enjoy CakePHP as much as you can, always ask around
> your needings, get help at IRC, and, please visit top rated blogs -
> the ones listed at cakephp.org. And last but not least : Actually read
> the manual :-P
>
> Any doubt? ask here again, in the same post, but be short!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---