I am using joomla 3.3.6 and have added a menu item type variable. I want to get the value of this variable using jinput to query the database.
The controller file is external so i added the framework but the value of variable is not available.
<?php
// Get Joomla! framework
define( '_JEXEC', 1 );
define( '_VALID_MOS', 1 );
define( 'JPATH_BASE', realpath(dirname(__FILE__)));
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$mainframe =&JFactory::getApplication('site');
$mainframe->initialise();
$jinput = JFactory::getApplication()->input;
$city = $jinput->get('city');
include('config.php');
$mysqli->set_charset("utf8");
if($stmt=$mysqli->prepare("SELECT * from test where City=?"));{
$stmt->bind_param("s",$city);
$result=$stmt->execute();
$result = $stmt -> get_result();
$arr = array();
if($result->num_rows >"0") {
while($row = $result->fetch_assoc()) {
$arr[] = $row;
}
}
# JSON-encode the response
$json_response = json_encode($arr);
// # Return the response
echo $json_response;
}
?>
The xml file for the menu variable is
<metadata>
<layout title="COM_HELLOWORLD_HELLOWORLD_VIEW_DEFAULT_TITLE">
<message>COM_HELLOWORLD_HELLOWORLD_VIEW_DEFAULT_DESC</message>
</layout>
<fields name="request">
<fieldset name="request">
<field
name="city"
type="list"
label="COM_HELLOWORLD_HELLOWORLD_FIELD_GREETING_LABEL"
description="COM_HELLOWORLD_HELLOWORLD_FIELD_GREETING_DESC"
default="London">
<option value="London">London</option>
<option value="Paris">paris</option>
<option value="New Delhi">New Delhi</option>
<option value="Amsterdam">Amsterdam</option>
<option value="Las vegas">Las vegas</option>
<option value="Birmingham">Birmingham</option>
<option value="new york">new york</option>
<option value="mumbai">mumbai</option>
</field>
</fieldset>
</fields>
</metadata>
Hope you can help.
-----------------------------------Update---------------------------------------------
Deine a problem: i am trying to get the variable value from menu item so i can run a query . i have set a menu item variable as described above but it is not working.
As a alternative i am trying to get the menu item alias so i can use that in my query and get results.
Below is the code I tried but i get some warnings but no variable value.(added joomla framework to external file)
<?php
// Get Joomla! framework
define( '_JEXEC', 1 );
define( '_VALID_MOS', 1 );
define( 'JPATH_BASE', realpath(dirname(__FILE__)));
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$mainframe =&JFactory::getApplication('site');
$mainframe->initialise();
$menu = JFactory::getApplication()->getMenu();
$alias = $menu->getActive()->alias;
$jinput = JFactory::getApplication()->input;
$city = $jinput->get('city');
include('config.php');
$mysqli->set_charset("utf8");
//$rcity ="london";
if($stmt=$mysqli->prepare("SELECT * from ratedmain where City=?"));{
$stmt->bind_param("s",$alias);
$result=$stmt->execute();
$result = $stmt -> get_result();
$arr = array();
if($result->num_rows >"0") {
while($row = $result->fetch_assoc()) {
$arr[] = $row;
}
}
# JSON-encode the response
$json_response = json_encode($arr);
// # Return the response
echo $json_response;
echo $parentname;
}
?>
Strict standards: Only variables should be assigned by reference in C:\wamp\www\tets\test.php on line 9
Trying to get property of non-object in C:\wamp\www\test\test.php on line 16
Trying to get property of non-object in C:\wamp\www\test\test.php on line 17
Am I using the right method to get the menu item alias?
mysqliqueries. You can simply use JDatabase