Slide 21
Slide 21 text
3FQMJDBUJPO-BH
// Controller
public function add()
{
$article = $this->Articles->newEntity();
if ($this->request->is('post')) {
$article = $this->Articles->patchEntity($article, $this->request->getData());
if ($this->Articles->save($article)) {
$this->Flash->success(__('Your article has been saved.'));
return $this->redirect(['action' => 'index']);
}
....
}
public function index()
{
// use ReadReplica for this action
$this->Articles->changeConnectionToReadReplica();
$articles = $this->Paginator->paginate($this->Articles->find());
$this->set(compact('articles'));
}