0

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 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the help. I needed to use $this->structure as your pointed out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.