0

I'm making a main app in CakePHP 1.3.10 that has a couple of plugins. In one of them, I need to use a very big array ($array_test) populated "manually".

The way I have it now (which works perfectly) is that I declare the array in the controller of the plugin that I want to use it in (plugin1_home_controller.php for example), doing something like var $array_test = array(1,2,3,4,5...), and I can access it perfectly from the views in that controller.

The thing is that I would prefer having the array declared somewhere else in the plugin, since it's too big, and then load it when I need it.

So I'm trying to create a array_test.php file with the array declared in it, put in /app/plugins/plugin1/webroot/php/array_test.php, and then load it from the view using include "/php/array_test.php" (I also tried include "/plugin1/php/array_test.php" as the CakeBook says in the plugins assets section), but none of them work.

How can I get the right path? Or is there any good alternative to what I want to do? Thank you so much in advance!

1 Answer 1

2

If your plugin is in the app's directory use:

APP_PATH.'plugins'.DS.'plugin1'.DS.'webroot'.DS.'php'.DS.'array_test.php'

If your plugin is installed in the common cake directory:

CORE_PATH.'plugins'.DS.'plugin1'.DS.'webroot'.DS.'php'.DS.'array_test.php'
Sign up to request clarification or add additional context in comments.

2 Comments

Cool! It works! Thank you very much. I just found out that I can use App::import('Plugins', 'plugin1.php/array_test.php'); as well, but then I have to declare the array as a property of a class. What way is better? Your way needs less code, that's for sure, but I don't know if there's any benefit of using the Import and a class...
A simple include has less overhead

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.