CakePHP View a Record

cakephp

To view a record in CakePHP, you’ll need to create a controller action that retrieves the record from the database and renders a view template with the record data.

Here’s an example of how to view a record in CakePHP:

Controller action:

public function view($id)
{
    $post = $this->Posts->get($id);
    $this->set(compact('post'));
}

View template:

<h1><?= $post->title ?></h1>
<p><?= $post->body ?></p>

In this example, the view action uses the CakePHP ORM to retrieve a post with the specified id from the database. The view action then sets the post variable, which is passed to the view template and used to display the post data.

For more information about using the ORM in CakePHP, you can refer to the documentation at https://book.cakephp.org/4/en/orm.html.