ich habe folgendes Problem.
Ich backe mit CakePHP gerade eine Bilder-Gallery. In dieser Gallery können Bilder auch von User kommentiert werden.
Anbei meine Models:
Pic Model
- Code: Alles auswählen
class Pic extends AppModel {
var $name = 'Pic';
var $validate = array(
'id' => array('numeric'),
'image_name' => array('notempty'),
'image_path' => array('notempty'),
'thumb_path' => array('notempty'),
'width' => array('numeric'),
'height' => array('numeric'),
'size' => array('numeric'),
'keywords' => array('notempty'),
'created' => array('date'),
'modified' => array('date'),
'user_id' => array('numeric'),
'active' => array('numeric'),
'image_downloads' => array('numeric'),
'image_views' => array('numeric')
);
//The Associations below have been created with all possible keys, those that are not needed can be removed
var $belongsTo = array(
'User' => array('className' => 'User',
'foreignKey' => 'user_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
var $hasMany = array(
'Comment' => array('className' => 'Comment',
'foreignKey' => 'pic_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);
var $hasAndBelongsToMany = array(
'Category' => array('className' => 'Category',
'joinTable' => 'pics_categories',
'foreignKey' => 'pic_id',
'associationForeignKey' => 'category_id',
'unique' => true,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
)
);
}
User Model
- Code: Alles auswählen
<?php
class User extends AppModel {
var $name = 'User';
var $validate = array(
'user_name' => array('rule' => array( array('custom', '/^[a-z0-9]{5,20}$/i'), 'message' => 'Der Benutzername muss zwischen 5 und 20 Zeichen lang sein und darf nur aus Buchstaben und Zahlen bestehen')),
'suname' => array('notempty'),
'name' => array('notempty'),
'password' => array('rule' => array('isPassword'), 'message' => 'Passwörter nicht identisch oder zu kurz'),
'e_mail' => array('rule' => 'email', 'message' => 'Bitte geben sie eine gültige E-Mailadresse an'),
'created' => array('date'),
'modified' => array('date')
);
function isPassword($data,$field){
$valid = false;
if($data['password'] == $this->data['User']['password2']){
$valid=true;
}
if(strlen($data['password']) < 5){
$valid = false;
}
return ($valid);
}
function uniqueUser($data,$field){
return ($valid);
}
}
?>
Comment Model
- Code: Alles auswählen
<?php
class Comment extends AppModel {
var $name = 'Comment';
var $validate = array(
'id' => array('numeric'),
'user_id' => array('numeric'),
'pic_id' => array('numeric'),
'comment' => array('notempty')
);
//The Associations below have been created with all possible keys, those that are not needed can be removed
var $belongsTo = array(
'User' => array('className' => 'User',
'foreignKey' => 'user_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Pic' => array('className' => 'Pic',
'foreignKey' => 'pic_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
}
?>
Mein Problem ist jetzt das ich bei der Abfrage eines Pics nicht den Usernamen eines Kommentarschreibers zurückbekomme.
Das müsste doch auch noch irgendwie aufgelößt werden. Es ist ja definiert.
Momentan bekomme ich aber nur die folgende Ausgabe --> Da fehlen die Userdaten des Komentarschreibers
- Code: Alles auswählen
Array
(
[Pic] => Array
(
[id] => 41
[image_name] => rusty.jpg
[image_path] => img\uploads/rusty0.jpg
[thumb_path] => img\uploads/thumb_rusty0.jpg
[width] => 512
[height] => 512
[colors] => 0
[size] => 77220
[image_type] => jpg
[description] => Beschreibung
[keywords] => Metall
[created] => 2009-01-11 01:21:33
[modified] => 2009-01-11 01:21:33
[user_id] => 22
[active] =>
[image_downloads] => 2
[image_views] => 9
)
[User] => Array
(
[id] => 22
[gender] =>
[user_name] => TestUser
[suname] => Test
[name] => User
[password] => 123456
[e_mail] => test@test.de
[created] => 2009-01-06 20:07:49
[modified] => 2009-01-06 20:07:49
[activation_key] => PEMCM-BUNXJ-NSDPW-VCRJQ-ACCGW-1231268869
[active] => 0
)
[Comment] => Array
(
[0] => Array
(
[id] => 1
[user_id] => 1
[pic_id] => 41
[comment] => Alles cool man !!!!! Das ist doch mal ein Kommentar !!!
[modified] => 2009-01-06 20:09:54
[created] => 2009-01-06 20:09:54
)
)
Was mache ich falsch???????????
Danke im voraus.......