Joomla 1.5 can't save component parameters - joomla

I have custom coded Joomla v1.5 component. In administrator zone I change its parameters, but when I taking param values in my code I get only default values, but not the new as I set in components admin zone params window.
global $option;
$params = &JComponentHelper::getParams( $option );
print_r($params);
The output looks like this:
JParameter Object
(
[_raw] => param_1=This is changed value of the param 1
param_2=20
param_3=This is changed value of the param 3
[_xml] =>
[_elements] => Array
(
)
[_elementPath] => Array
(
[0] => /home/x/domains/xyz.com/public_html/libraries/joomla/html/parameter/element
)
[_defaultNameSpace] => _default
[_registry] => Array
(
[_default] => Array
(
[data] => stdClass Object
(
[param_1] => some default value 1
[param_2] => 10
[param_3] => some default value 3
)
)
)
[_errors] => Array
(
)
)
How you in output, param raw data changes, but the data field does not. So what's the problem ? Any ideas ?

I've found out the problem. So when I create a menu link to my component view, it duplicates the component parameters in menu item params list. So it overrides the main component parameters. That's why if I change param value in components param window(in admin zone), I get only param values that are in menu items window. Also found some more information about it in Joomla forum: http://forum.joomla.org/viewtopic.php?f=304&t=485837

Related

laravel 5.4 validation array with keys

In laravel 5.4 when validation is failed I do like:
if ($validator->fails()) {
$errors_list = $validator->messages()->all();
and I got array like :
[errors_list] => Array
(
[0] => The image has already been taken.
[1] => The is main has already been taken.
)
What I dislike in this output that actuall name of error field is ommitted.
Code
echo '<pre>$validator->messages()::'.print_r($validator->messages(),true).'</pre>';
has output:
$validator->messages()::Illuminate\Support\MessageBag Object
(
[messages:protected] => Array
(
[image] => Array
(
[0] => The image has already been taken.
)
[is_main] => Array
(
[0] => The is main has already been taken.
)
)
[format:protected] => :message
)
And I did not find how access to messages data.
I would like to get array like:
[errors_list] => Array
(
[image] => The image has already been taken.
[is_main] => The is main has already been taken.
)
Is there is a way to make it ?
Thanks!
I hope this will work for you.
$errors->has('image');
$errors->get(image);
$errors->has('is_main');
$errors->get(is_main);
It's a tricky one. The reason it's like that is because there may be multiple validation errors happening at once. However if you only have a single rule per entry:
array_combine($validator->messages()->keys(),$validator->messages()->all())

Smarty: How to get value of array in Object

I have an array inside an object inside an array in my smarty template. A simplified example below, but using the same structure.
Array (
[product] => ModelView Object (
[model:protected] => Model Object (
[id] => 1234
)
)
)
How can I get [id]?
I can get the 'product' object to appear on the page as an array using:
$this->get_template_vars('product')
But from there I can't seem to narrow it down to only get the [id].
Apparently all it takes is a post on stackoverflow and then you try one more thing after hours and it works.
My solution below.
{php}
$id = $this->get_template_vars('product');
$id = $id->id;
{/php}

xpath get node from inside value

Current xpath: Product/ProductMultimediaObject/MultimediaObject
Returns:
Array
(
[0] => SimpleXMLElement Object
(
[#attributes] => Array
(
[ContentType] => application/pdf
[Date] => 2014-11-01 01:20:35
[Description] => Leaflet
)
)
)
But I'm currently just hoping that the found MultimediaObject is the correct one - which is not. I need to get the MultimediaObject where Description has a specific value.
What I've tried:
Product/ProductMultimediaObject/MultimediaObject[Description/text() = 'WhatIWant']
Product/ProductMultimediaObject/MultimediaObject/Description[text() = 'WhatIWant']
Your Desciption is an attribute. Try
Product/ProductMultimediaObject/MultimediaObject[#Description = 'WhatIWant']
or, for short,
//MultimediaObject[#Description = 'WhatIWant']

A number appearing in place of first letter of array

I am trying to create a upload plugin. I am keeping all the logic in behavior. This thing was working all fine by yesterday and from no where this strange problem is surfaced.
/*controller code */
debug($this->request->data);
$this->Model->saveAll($this->request->data);
/* outputs
Array
(
[Ad] => Array
(
[s] => 2
[d] => 2
)
[Upload] => Array
(
[field] => Upload
[table] => Ad
[filename] => Array
(
[name] => index.php
[type] => application/x-php
[tmp_name] => /tmp/php3MbvRh
[error] => 0
[size] => 32
)
)
)
*/
I am developing a plugin. In plugins beforeSave() i debug the same data and it shows
public function beforeSave(Model $Model) {
debug($Model->data);
}
/* outputs
Array
(
[Upload] => Array
(
[1pload] =>
)
)
*/
Everytime there appears a number for the fields property. Sometimes its 1, 8 and/or 9. :(
The plugin is loaded fine from bootstrap.php (CakePlugin::loadAll())
The plugin uses uploads table. The model of which is maintained as model.
The plugin behavior is properly defined and was working perfectly. NOT NOW
I couldn't figure out the problem. But the debug() in beforeSave() was being executed several times. So, I added in the plugin
if( isset ($this->data['preferred']['data'] ) {
}
For first few passes it is still something similar but on the third or fourth time it does show the data.
So, I have come with a theory that the beforeSave in plugin was being asynchronous to that of model's beforeSave and if i put a check then that would solve the issue. In fact it did.

Simplexml How to access all element of the same node

[Villa] => Array
(
[0] => SimpleXMLElement Object
(
[VillaID] => 6
[VillaName] => Mary
[Distances] => SimpleXMLElement Object
(
[Distance] => Array
(
[0] => SimpleXMLElement Object
(
[Destination] => Sea
[Value] => 1000 m
)
[1] => SimpleXMLElement Object
(
[Destination] => Market
[Value] => 800 m
)
)
)
)
[1] => SimpleXMLElement Object
(
[VillaID] => 21
[VillaName] => Marion
[Distances] => SimpleXMLElement Object
(
[Distance] => Array
(
[0] => SimpleXMLElement Object
(
[Destination] => Beach
[Value] => 5 min
)
)
)
)
)
I need to print all, only of 1 villa (example with id = 6) but VillaId is not an array so it's impossible to get all with foreach
I can obtain it with:
echo 'Name of Villa: '.$xml->Villa[0]->VillaName.'';
etc. etc ... but in this way have to change manually for every villa (too much) the value in the brackets.
i've tried with $xml->Villa[$value]->VillaName; ($value comes from another page) but it's not working...
Tanks for help!
First of all, your question starts with "i have this xml:" followed by something that is not XML. I'm not saying this to be a smartass, rather because it's important for XML beginners to understand that print_r() is not the right way to inspect SimpleXMLElements. Sometimes it will show you things that aren't in your XML, other times it will not show things that are actually in your XML. In short: do not use print_r() on SimpleXMLElement. Just use ->asXML() and look at the actual XML.
From what I understand, you want to locate and select a node based on some criteria. XML just happens to have a language for that: XPath. The official specs aren't terribly user-friendly but w3schools.com has a pretty good XPath tutorial.
I need to print all, only of 1 villa (example with id = 6) but VillaId is not an array so it's impossible to get all with foreach
Anywhere in your document, you want to select all Villa nodes with an attribute VillaID whose value is "6". In XPath:
//Villa[#VillaID="6"]
Via SimpleXML:
$xml->xpath('//Villa[#VillaID="6"]');
Attention, xpath() always return an array.

Resources