When object name ( category ) put directly it returns correct value Like:
$primary = $this->dbmapper->category['primary'] ; // ( Correct Output )
But when , put object name in a variable called $dataname, it returns blank, like:
$dataname = 'category';
$primary = $this->dbmapper->$dataname['primary'] ; ( Blank Output )
my constructor variable is:
$this->dbmapper = $this->mapper();
My function is:
function mapper($module='')
{
$mapper = array();
$mapper['category']['table'] = 'allcategory';
$mapper['category']['primary'] = 'categoryID';
$mapper['page']['table'] = 'allpages';
$mapper['page']['primary'] = 'pageID';
return (object) $mapper;
}
Approach: First make the necessary JavaScript file, HTML file and CSS file. Then store the API URL in a variable (here api_url). Define a async function (here getapi()) and pass api_url in that function. Define a constant response and store the fetched data by await fetch() method.
How do I return a response on Fetch? Use the fetch() method to return a promise that resolves into a Response object. To get the actual data, you call one of the methods of the Response object e.g., text() or json() . These methods resolve into the actual data.
To access an object property(especially if it's an array) via variable enclose it with braces:
...
$dataname = 'category';
$primary = $this->dbmapper->{$dataname}['primary'];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With