FuelPHP \URI::current() does not get file extension - fuelphp

My project requires me to know what file extension was used while calling a route.
For example,
If the route was 127.0.0.1/controller/action/filea.json
Then then I would need to have a function that returns ".json" when called from inside action function "get_action".
If the route was 127.0.0.1/controller/action2/fileb.xml
Then then the function should return ".xml" when called from inside action function "get_action2".
Right now, I tried using \URI::current(), but that only gets me "127.0.0.1/controller/action/filea" or "127.0.0.1/controller/action2/fileb"

Whether or not the extension is used is controlled by the config key routing.strip_extension, which is true by default.
The current extension can be retrieved using \Input::extension().

Related

Joomla 3.9.19 get the constants from global configuration in component display function

I have created a component and need to get a constant value in the component administrator and list the item according to it. I have tried different ways to get the constant value in the 'display()' function in 'view.html.php'. I am expecting the value will be available in the default.php with $this.
I have defined the constant in the configuration.php file, A URL is supposed to define.
define('CONSTANTVALUE', 'the URL string');
in the display() function,
$config = JFactory::getConfig();
$constantvalue = $config->get('CONSTANTVALUE');
$this->constantvalue= $constantvalue;
Seems this is not working.
Then, I have tried
JFactory::getApplication()->get('CONSTANTVALUE');
That also not working.
I have referred to this thread, Joomla 3 - How to get value from configuration file?
How can I get the constant from configuration to component view file?

Adding another function in an "App Designer" function

I'm using App Designer in MATLAB. I have created a push button, 51-54 work no problem, then when I assigned another function into it (highlighted in the screenshot), it wouldn't work!
Please help me overcome this problem.
Screenshot showing the problem:
Problem: function inside of a function the way it is written in the screenshot.
4 things come up my mind:
Generally:
yourApp.mlapp or any other code.m file
function someProcess()
end
function subProcess()
end
In your case rather try to write your function in an second .m file and call it from within your your app.
be sure to have it on the MATLAB path.
yourApp.mlapp or any other code.m file
function someProcess()
subProcess();
end
+ external code.m file
function someProcess()
subProcess();
end
define your function as a public or private function (method) inside the app. ( for others: the block is not there by default. click: app designer> code view > function > add private function | add public function)
screenshot
if your function is only used once you could also write an anonymous function
https://www.mathworks.com/help/matlab/matlab_prog/anonymous-functions.html

Extbase Hooks - execute code upon record creation

I want to create a standard typo3 extension but when I create a record (or modify it) I want to calculate something (in my case I want to call the Google Map API to get coordinates from a given address).
SO I search for a hook or something. Any idea?
One of my project example, may helps you for hook in backend when record has been changed.
In your extension file ext_localconf.php
// Hook for cancellation
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][] = 'EXT:femanager/class.tx_femanager_tcemainprocdm.php:tx_femanager_tcemainprocdm';
hook file class.tx_femanager_tcemainprocdm.php where you can execute
your script
class tx_femanager_tcemainprocdm{
function processDatamap_postProcessFieldArray ($status, $table, $id, &$fieldArray, &$reference){
// $status also called action like delete
// $table - table name of excute backend action
// $id - record UID
// $fieldArray - fields of your table
if($table = 'your_extension_table_name'){
// your script
}
}
}
Maybe this answer is useful to you.
Register your class as a data handling hook in your extension. This one "is called AFTER all commands of the commandmap" were executed. Maybe you need to look for a more appropriate one.
Then in your registered Hook i.e. 'typo3conf/ext/your_ext/Classes/Hooks/AfterCreate.php' do your calculation. Hope this sets you on the right track.
In my special case there was no need to calculate the coordinates when the record got saved. So I just used the listAction in the controller, check if coordinates are there and if not call the Google API (and send an email if the Google API does not give a coordinate back).
In another case where the new record comes from a frontend plugin and I had to do something with this data I used the createAction in the Controller. (I am not sure if the createAction is also called when the record is created from the backend.)

Accessing value by javascript Play Framework/Scala

First of all I am using Play framework with scala.
I am creating a graph and with the node id I would like to show some information at the same page.
In order to do that, first I need to get node.name but for some reasons #node.name function is not working. When searching for it I learnt that it's because play is server-side and js is client-side. However I need to get the data somehow.
I also cannot access:
var html = "<h4>" + node.name + "</h4><b> connections:</b><ul><li>"
How can I access this through the view?
My second question is after reaching the js node.name, I need to access to controller and do the same action one more time but this time with the new node.name .
View Part:
onClick: function(node) {
#node.name
}
1) Is this code in your controller? And are the node variable in scope? If so this should be perfectly legal code, since it will be evaluated as pure scala.
2) The templates are a different story however. You probably know they parse everything as normal html, unless escaped. To use a variable you have to bring it into scope by either:
defining a 'constructor' for the template at the absolute beginning of the file:
#(node : Node)
...
#node.name // later in the file
See http://www.playframework.com/documentation/2.0/ScalaTemplates
or define a variable inside the template:
#defining( Get.node.from.somewhere ) { node =>
#node.name
}
See Play! framework: define a variable in template?
If you did either of the two, you should have no problem accessing the node variable. Even in scripts. But note that external scripts does not have access to the same variables. It is thus very common to use inline scripts or import it as another template if you need to access a variable from JavaScript.
Edit: I've made a gist of a template, controller and routes file: https://gist.github.com/Jegp/5732033

Which file contains function of core/session in magento?

I need to customize other's code,
so I found they used
Mage::getSingleton('core/session')->getMyCustomBlockInfo();
in Order.php file for custom order email
so I can't find this function getMyCustomBlockInfo();
Can anyone tell me where this function reside?
Thanks
those are magic functions get() and set() and you are asking a session variable there that is set as
Mage::getSingleton('core/session')->setMyCustomBlockInfo();
somewhere in your code. If you use terminal you can easily find by making a following grep:
grep '>setMyCustomBlockInfo(' . -rsni
and it will list the files where your variable is set to session.
example :
Mage::getModel('catalog/product'); //or
Mage::getSingleton('catalog/product');
the code must be in '../app/core/Mage/Catalog/Model/Product.php' file
then
Mage::getSingleton('core/session');
the code must be in '../app/core/Mage/Core/Model/Session.php' file
because the class Mage_Core_Model_Session's parent::parent is Varien_Object, then you can do all magic functions and you can ->getData() to see the Data inside.
Mage::getSingleton('core/session')->getData();
on your problem when go call ->getData() you can see data : [my_custom_block_info]
you can set it with call
Mage::getSingleton('core/session')->setMyCustomBlockInfo('what');
Mage::getSingleton('core/session')->getMyCustomBlockInfo();
// will return 'what'