定义在视图中使用的全局数组常量 [英] Define global array constant for using in view

查看:125
本文介绍了定义在视图中使用的全局数组常量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在bootstrap.php中定义全局数组常数

I want to define global array constant

$ adv_types = array('top'=>'Верх','left'=>'Левое','right'=>'Правое','bottom'=>'Нижнее');

视图文件中的代码


echo $ form-> input('Adv.type',array('type'=>'select','option'=> $ adv_types,'label'=>'Месторекламы'));

但cakephp提供错误:

but cakephp gives error:


未定义的变量:adv_types

"Undefined variable: adv_types"


推荐答案

这些需要在app_controller中设置。 php,然后传递给你的视图

These need to set in your app_controller.php, and then passed to your views

// app_controller.php
class AppController extends Controller {
        var $adv_types = array('top' => 'Верх', 'left' => 'Левое', 'right' => 'Правое', 'bottom' => 'Нижнее');
        function beforeFilter() {
            $this->set('adv_types', $this->adv_types);
        }
}

对我来说,bootstrap.php不是正确的文件对于此常数

To me, bootstrap.php is not the correct file for this constant

这篇关于定义在视图中使用的全局数组常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆