Last Updated: February 25, 2016
·
4.529K
· 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;
}

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Related Tags
#php
#cakephp
Did you know?

PHP applications still send a browser full of JavaScript. Hardening the server does not inventory the payment, analytics, and plugin scripts that run after the HTML is delivered.

Security insights from Cside