Dear group,
I've regularly registered a amd plugin, say in myplugin/rewrite/myamd.js .
Now I need improve this with some php, so I've tried the follow:
That's work good for regular php function, but if I try to use some elgg built in as
elgg_get_plugin_from_id('mypluginId')->getAllSettings();
In error log appears
PHP Fatal error: Call to undefined function elgg_get_plugin_from_id()
So I've attempted to handle this page as normal page to require this php via start.php, but neither
elgg_register_page_handler('myplugin', 'myplugin_page_handler');
nor
elgg_register_plugin_hook_handler('route', 'myplugin', 'myplugin_utility_routes_wrap');
intercepts myplugin/rewrite/myamd.js .
I think that's due to the elgg_define_js() routine.
Someone can help me to achieve this goal?
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by Raül Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.
- Juho Jaakkola@juho.jaakkola
Juho Jaakkola - 0 likes
- Simone@Keltroy
Simone - 0 likes
- Juho Jaakkola@juho.jaakkola
Juho Jaakkola - 0 likes
- Simone@Keltroy
Simone - 0 likes
- Juho Jaakkola@juho.jaakkola
Juho Jaakkola - 0 likes
- Simone@Keltroy
Simone - 0 likes
You must log in to post replies.So your goal is to pass plugin settings to your AMD module? Here are the instructions for it: http://learn.elgg.org/en/2.0/guides/javascript.html#passing-plugin-elgg-settings-to-modules
Not exactly... my goal is use hybrid php-javascript amd module.
I know what you suggest but according to documentations, using elgg_register_simplecache_view:
I would generate dinamically this file, so that I could, for example, check if user is admin, else return a simple json:
That's only one example about what my question covers.
Can you describe your needs in more detail? What are the pieces on information that may be different for each user?
Could you simply do something like:
My explanations wasn't clear, sorry...
For Example in myplugin/rewrite/myamd.php something like:
as you can see I need elgg usage to check if is admin an generate content on the fly since the time must be updated every call (that' a simple example, but substantially I need this skill to improve my complex goal), therefore content can't be stored in chache.
Since requirejs can load only ".js" extension file, I use the .htaccess in my first post to rewrite the ".php" in ".js";
Is there a reason why the logic needs to be in the javascript file?
Why not e.g. fetch the needed data via AJAX, checking the user's role on server side, and providing the response based on it?
Or include the data to the page (html) already when it is being rendered on server side?
Because I need that this will be an amd module.
As you suggest I can implement this creating a module that make an ajax call to an action page, that can generate the right content, and store the ajax response in module variable... my problem isn't achieve my purpose in some exotic manner, but if I could reach exactly my goal, with the method I've explained.
Anyway, thanks for all reply... I hope to reach my goal!