CakePHP - 将参数传递给控制器​​(NOT url request)

时间:2014-05-14 11:17:27

标签: php cakephp

AppController中有一个函数:

function products()  
{  
    $products=$this->Product->find('all',array('order' => array('Product.publish_order  ASC') ,'fields'=>array('id','name','price','publish')));  
    $this->set('products',$products);  
    $counter=$this->Pincode->find('count',array('order' => array('Pincode.product_id DESC '),'conditions' => array('product_id' => $pid,'status'=>0)));  
    $this->set('counter',$counter);  
}

在我的布局products.ctp中,我需要设置一个 $ pid (正如你在appcontroller类中看到的那样使用了这个)并传递它。

1 个答案:

答案 0 :(得分:0)

另一个解决方案是使用cakephp会话

在会话中添加值的代码:

$this->Session->write('Product.id', 25);

从会话中读取值的代码:

$pid= $this->Session->read('Product.id');

从会话中删除值的代码:

$this->Session->delete('Product.id');
相关问题