7

Instantly see the issue here. What you basically doing is the following: <?php $var = 'foo'; <?php echo $foo; ?> ?> You're using duplicate <?php tags which will cause issues. Use the following instead <?php $document = JFactory::getDocument(); $variable = "test"; $document->addScriptDeclaration(' ...


6

Your code is correct - I have tested it on a custom module myself, in Joomla 3. Please make sure you have cookies enabled. Try this in your module, and you will see that it works: $app = JFactory::getApplication(); $app->setUserState('com_mycomponent.view.filter.variable' ,'new state'); $variable = $app->getUserState('com_mycomponent.view.filter....


6

After this question was originally answered, Joomla introduced in version 3.5 another way of passing variables to javascript, using the addScriptOptions() method of the Joomla Document class. So I'm just adding this to make other people who are interested in this question aware of this alternative. In your php file you can write eg: $phpvars = array('...


4

Javascript have global variables : http://www.w3schools.com/js/js_scope.asp inside you php file you call: JFactory::getDocument(); and you can now add some javascript at the current page with addScriptDeclaration() In this example, we declare a myJoomlaVersion variable <$php $jdocument = JFactory::getDocument(); $jversion = new JVersion(); $...


3

Good question this one. I have been in this consideration many times as well. Not sure if there is one right answer and also not sure if my answer will be totally correct and clearly explained. From what I have seen so far, the database will understand a query containing a number/ integer in a where statement, and will compare it with its records set, even ...


3

Your code contains several errors, including a syntax error. You should use an IDE with proper code completion and signature hints (any modern IDE should be able to do that). $query->select('value', 'item_id', 'field_id'): JDatabaseQuery::select() takes exactly one parameter. If it is only one field, you can provide the name as a string directly; ...


3

You shouldn't use using $_SESSION with Joomla, but instead JFactory::getSession(). Try the following: Module: $session = JFactory::getSession(); $session->set('favcolor', 'green'); PHP file: $session = JFactory::getSession(); $session->get('favcolor');


2

I'm not sure if this is for a custom component or a core Joomla component, but to get the author's name, you can simply use the following: <?php echo $this->item->author; ?> If the component has the option to select an alias for the author, then you should use this instead: <?php $author = ($this->item->created_by_alias) ? $this-&...


1

Joomla syntax aside, let's start by explaining your desired action. You want to apply an incrementing counter to a specific column for all rows in the table. This is a very reasonable and common task. Your raw query is correct. (SQLFiddle Demo) The tricky part is getting Joomla to understand that you want the counter to be instantiated prior to the ...


1

Addendum: OP wants the menu item params accessible in the view, but he tries to override the component params var ($this->params) with the menu item params object/class. Which is unnecessary complicated. In the core article component, the component and the menu item params are merged (in the view.html.php), which is cool if you are trying to override some ...


1

You are getting $params from $state $state = $this->get('State'); This means the state must have $params populated in your model. Check if you are populating the $state with $params in your model's populateState function protected function populateState($ordering = null, $direction = null) { $params = JComponentHelper::getParams('com_mycomponent');...


1

It looks like you are trying to get the menu parameters for your current active menu. Try the following code, this hasn't been tested, I am giving you this reference from memory. $app = JFactory::getApplication(); $params = $app->getMenu()->getActive()->getParams(); That may work for the current active menu parameters. If not you may have to pass ...


1

It is not that clear you are after here, and I don't think that there is going to be an easy and one-go way. You probably have to look for a 3rd party extension, but it is recommended to make a descriptive explanation of what you want to achieve. At the end, this could be an e-commerce component working as a product catalogue, or maybe a tables/spreadsheets ...


1

You can achieve this with the use of a global function. So, in your JS file, you would do something like this: <script> var myFunction; jQuery(document).ready(function($){ myFunction = function(version) { console.log(version); // You have the version here } }); </script> Then, in ...


1

If you run this controller file directly you can't get the the active menu item because the application is not rendered yet. You only init the application by using $mainframe->initialise(); but to start it you need to use $mainframe->execute();, however running this will render the whole application and the code below this call will not be called at ...


Only top voted, non community-wiki answers of a minimum length are eligible