Frage

I have a database with two tables: users and mails.

In my MailsController.php controller I have a function history():

 public function history() {
 $mails = $this->Mail->find('id');
 $this->set('mails', $mails);
 $result = $this->Mail->find('fromUsername');
 foreach($result as $row){
    $this->set('mails', $row);
 } 
}

My goal is to print on the page all $mails sent by this username. But in case I do this, I do not know what code should I put in the history.ctp page.

Can you please help me a bit?

fromUserame in the column where I save the usernames in the 'mails' table of the database.

War es hilfreich?

Lösung

In MailsController.php:history() you sent the variable $mails to your view (history.ctp).

In your view, you can access $mails as you would any other PHP variable. Since this will be an array, you will want to use a loop to display the data:

foreach ($mails as $mail) {
    echo $mail['Mail']['fromUsername']; // Modify according to your data and required output.
}

To see what $mails contains in your script (for debugging purposes), you can dump its contents:

var_dump($mails);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top