dou4064 2011-06-15 11:50 采纳率: 100%
浏览 8
已采纳

CakePHP中的控制器宽阵列/功能

I have a local application that runs on multiple screens which I am in the process of moving over to cakePHP. Each screen represents a different view of a production line and has multiple items on each.

I need to refrenece some sort of controller wide function or array that defines the structure of my application, but I am unsure of the best way to do this. Since it will only be used in one controller, it seems excessive to create a global item. I thought I could include a simple array in the controller, outside of a function, and use it in each function. This didn't work for some reason (probably a good reason).

$structure = array(
    'stage_1'=>array('duration'=>5,'temperature'=>293),
    'stage_2'=>array('duration'=>8, 'temperature=>'280),
    'stage_3'=>array('duration'=>3,'temperature'=>283)
);

So... What is the best way to create a controller wide array or function that can be referenced in the controllers view functions?

  • 写回答

1条回答 默认 最新

  • dongpo2340 2011-06-15 11:57
    关注

    Sounds like you forgot the var keyword or didn't use $this->structure to call the variable.

    class ExamplesController extends AppController {
        var $name = 'Examples';
    
        var $structure = array(
            'stage_1'=>array('duration'=>5,'temperature'=>293),
            'stage_2'=>array('duration'=>8, 'temperature=>'280),
            'stage_3'=>array('duration'=>3,'temperature'=>283)
        );
    
        function action() {
            $this->set( 'structure', $this->structure );
        }
    }
    

    You might find reading up on object-oriented programming in PHP helpful when developing with CakePHP.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 chaquopy python 安卓
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题