ajax call not showing $_GET variables - zend-framework2

i am sending 2 parameters with-in ajax call from zf2. I am getting them in print_r() function. for e.g
**echo "<pre>";
print_r($_GET);
echo "</pre>";
exit();**
but when i want to use them in variables like this:
**$sid = $_GET('sid');
$rowid = $_GET('rowid');**
It gives error in broswer console.
Fatal error: Array callback has to contain indices 0 and 1

Use square bracket to access arrays in PHP:
$sid = $_GET['sid'];
$rowid = $_GET['rowid'];

Related

Lua array as parameter with null

I have a problem, i need to call a function with variable parameters that i get from a webservice... so for example:
I have a function:
function MyPrint(param1, param2)
print(param1, param2)
end
I save this function in an array of callbacks:
callback[1] = MyPrint
I get parameters from server:
params = "[2, 88]" --> JSON from server
I do:
params = json.decode(params)
-- so
-- params[1] = 2
-- params[2] = 88
I tried to pass this parameters to my callback as:
pcall(callback[1], unpack(params))
I got 2 and 88 on MyPrint function...
But if server sends "[null, 88]", I got nil on both values... I have readed that unpack function has problem with null values... but then... how can I call callback[1] with some null values?
Is there a way to pass an array of parameters directly to function without unpack it?
EDIT: I created MyPrint as an example... but really I don't know how many params needs the callback function, i only have a list of functions and needs to call them with a variable number of parameters that i got from server.
If a table has gaps, you should explicitly specify a range of indices to unpack: table.unpack(params, 1, table.maxn(params)). This works well in lua 5.1.5.

Garrys Mod lua kick and gag Troubble

I've got a Server and want to add tabs to the menu I've put in the command
local force = actions:AddOption( "Kick Player from the game" )
force:SetIcon( "icon16/delete.png" )
function force:DoClick()
RunConsoleCommand("ulx kick","reason", ply:EntIndex())
end
But i Get This Error sign
RunConsoleCommand: Command has invalid characters! (ulx kick (' '))
The first parameter of this function should contain only the command, the second parameter should contain arguments.
PLEASE Can anyone help me
Your command is ulx
Your arguments are: kick, reason and ply:EntIndex()
So instead of
RunConsoleCommand("ulx kick","reason", ply:EntIndex())
the line should be:
RunConsoleCommand("ulx", "kick", ply:EntIndex(), "reason")
'cause the first argument of the function should only contain the command you want to call.
Source: your Error Message ("The first parameter of this function should contain only the command, [...]") and
http://wiki.garrysmod.com/page/Global/RunConsoleCommand

YouTube video API not working with IDs beginning with a dash

I am accessing data from YouTube's API, I have everything working fine but the problem I'm having is that when there's a dash (-) at the beginning of the videoID that it's not returning the json data.
$videoID = -FIHqoTcZog;
$json = json_decode(file_get_contents("http://gdata.youtube.com/feeds/api/videos?q={$videoID}&alt=json"));
I am however able to return the thumbnail as always with it using this:
$thumbnail = "http://i4.ytimg.com/vi/".$videoID."/mqdefault.jpg";
This is the code that I use to pull the information from the above json that I want.
$title = $json->{'feed'}->{'entry'}[0]->{'title'}->{'$t'};
$description = $json->{'feed'}->{'entry'}[0]->{'media$group'}->{'media$description'}->{'$t'};
$thumbnail = "http://i4.ytimg.com/vi/".$videoID."/mqdefault.jpg";
$ratings = ((round($json->{'feed'}->{'entry'}[0]->{'gd$rating'}->{'average'}, 1)/$json->{'feed'}->{'entry'}[0]->{'gd$rating'}->{'max'})*100)."%";
$views = number_format($json->{'feed'}->{'entry'}[0]->{'yt$statistics'}->{'viewCount'});
$duration = $json->{'feed'}->{'entry'}[0]->{'media$group'}->{'yt$duration'}->{'seconds'};
Are you sure you're only getting a problem with IDs that have a dash in front of it? The code you pasted shouldn't be working with any Youtube ID, because the gdata feed returns, as part of the JSON, some text with the '$' character in it. That character is a PHP identifier, so you'll get 500 errors trying to run the json_decode function on whatever the feed returns.
One way to solve the problem is to use json_decode's 2nd parameter to give you an associative array rather than an object, like this:
$json = json_decode(file_get_contents("http://gdata.youtube.com/feeds/api/videos?q={$videoID}&alt=json"),true);
Of course, that requires you to work with an array, too, but the subsequent code changes should be minimal.
If you aren't getting errors with other videos using the exact same code, perhaps you could post it here?

magento display request url

i wanted to display the module,controller,method being called
i thought that the cms module found in the
app\code\core\Mage\cms\
calls the IndexController.php and uses the IndexAction method .since it is the default page url.
but when I tried to echo out something inside the IndexAction method .nothing comes out. I even tried to call it manually and it still redirects to the home page.
localhost/magento/index.php/cms/index/index/
am i doing it right?
how can i display the request url being called in magento?
I was looking for this also, here's how to do it:
echo Mage::helper('core/url')->getCurrentUrl();
Hi you could try to output the following
<?php
echo Mage::app()->getRequest()->getModuleName();
echo Mage::app()->getRequest()->getControllerName();
echo Mage::app()->getRequest()->getActionName();
?>
Not tested but maybe you can do something like this
<?php
echo Mage::app()->getRequest()->getRequestUri();
?>
Hope this helps
greetings
I needed the URL segments, so I used this:
function getUrlSegment($i) {
$_baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
$_currentUrl = Mage::helper('core/url')->getCurrentUrl();
$_path = str_replace($_baseUrl, '', $_currentUrl);
$_segments = explode('/', rtrim($_path, '/'));
return $_segments[$i];
}
// Would get 'store' if URL: http://example.com/store/product/123
$root = getUrlSegment(1);
You might be getting 'headers already sent' warnings in your log files using an echo in the controller. Instead of using echo use Mage::log, e.g.
Mage::log('My request url is: '.$requestUrl);
The log line should appear in the /var/logs/system.log file.
The route cms/index/index is only ever used for the home page. Other standard pages like "no-route" and "enable-cookies" are optionally handled by specific actions on the IndexController. The remaining pages are handled by Mage_Cms_PageController::viewAction() instead. Try the path cms/page/view/id/customer-service to see. The parameter is id and so the next term customer-service is the page identifier which you set in the admin as "URL Key".

Ruby on Rails: what does "equals" symbol mean as a parameter?

Some open source I've been using has the below line as a function declaration:
def parse_query(query=nil, options={}, models=nil)
What effect do the "equals" symbols have on the statement? Does it just make the parameters optional?
It sets the default value of the parameter, if the person calling the function does not specify one.
Similar to Python and C++, the equals sign in the parameter list lets you specify a default parameter. For example, in Python:
def hello_world(message="Hello World"):
print "message = "+message
Calling this function like this:
hello_world()
Will result in:
message = Hello World
But calling the function like this:
hello_world("changed default")
results in:
message = changed default

Resources