Last Updated: February 25, 2016
·
4.252K
· fs

CakePHP requestAction()

Need to access a controller method from the view?

View:

$quantity = $this->requestAction(array(
    'controller' => 'articles',
    'action' => 'getRowQuantity'),
    array('id' => $current_id));

Controller:

public function getRowQuantity($id =0)
{
    $id = $this->params['id']; // remember!
    $total = $this->Article->ArticleTransaction->find('all', array(
    'fields' => array('sum(ArticleTransaction.quantity) as TOTAL'),
    'conditions' => array('ArticleTransaction.service_id' => $id)));
    $total_available = $total[0][0]['TOTAL'];
    return $total_available;
}