$this->loadModel('Siteconfig');
$data=$this->Siteconfig->find('all');
foreach($data as $data)
{
$email=$data['Siteconfig']['email'];
$companyname=$data['Siteconfig']['companyname'];
$cfa=$data['Siteconfig']['cfa'];
}
以上是控制器
如何使用 CAKEPHP获取 cfa 数据?
答案 0 :(得分:1)
在您的控制器方法中,您可以使用此
$this->set('var_name_in_view', $cfa); //You will find the variable $cfa as $var_name_in_view in your view(You have to use $var_name_in_view in view)
您也可以一次向视图发送多个变量
$this->set(compact('cfa', 'another_variable')); //You can acceess using $cfa and $another_variable
Compact生成一个数组,将变量名称保存为键,将变量值保存为数组键的值。
答案 1 :(得分:0)
将脚本修改为
$this->loadModel('Siteconfig');
$data=$this->Siteconfig->find('all');
$cfa = '';
foreach($data as $datum)
{
$email=$datum['Siteconfig']['email'];
$companyname=$datum['Siteconfig']['companyname'];
$cfa=$datum['Siteconfig']['cfa'];
}
$this->set('view_cfa',$cfa);
这将解决它。你的foreach正在重新分配$ data。