strange class with nested {} (PHP) - php

this code is originally from Joomla! custom form. All i want is to get the caption on the field and its body variables to put them in an email. I did var_dump($form) and was surprised with what i saw:
stdClass Object ( [FormId] => 10 [FormName] => contacts [FormLayout] =>{global:formtitle}{error}{name:caption}*{name:body}{name:validation}{name:description}{message:caption}*{message:body}{message:validation}{message:description}{email:caption}*{email:body}{email:validation}{email:description}{Send:caption}{Send:body}{Send:validation{Send:description}]
can anyone tell me how should i access those variables? (eg.{name:caption} {name:body})
Thanks in advance.

That is a normal string containing template variables of some sort.
You would have to parse $object->FormLayout using the correct method - it can probably be found inside Joomla's code somewhere.

This is a php object and cannot be accessed like an array $array["FormLayout"]

Related

Call to member function getResourceId() on non object - Magento CE

Firstly I'd like to apologise in advance if this is a stupid question - Although I have been writing PHP for the last 12 years, I work on bespoke applications and have only been using Magento for the last hour, so I'm clueless on its structure. If possible I'd like to avoid having to dig too much into Magento as the entire reason why I'm using Magento is to save time.
Anyway, the error:
Call to a member function getResourceId() on a non-object in /var/www/[site]/lib/Zend/Acl.php on line 1174
This error occurred after attempting to log in to the administration area immediately after install. The error is in the &_getRules method in lib/Zend/Acl.php.
So, I did a little digging and $resource (the variable it is attempting to call the &_getRules method on) is actually an array - which I found odd as the this is the method definition:
protected function &_getRules(Zend_Acl_Resource_Interface $resource = null, Zend_Acl_Role_Interface $role = null, $create = false){
So, to verify that I wasn't actually losing my mind I wrote the following as the first line of the &_getRules method
if($resource!==null&&!$resource instanceof Zend_Acl_Resource_Interface){
die('<pre>'.print_r($resource,1).' </pre>');
}
Which printed:
Array
(
[G1] => Array
(
[instance] => Mage_Admin_Model_Acl_Role_Group Object
(
[_roleId:protected] => G1
)
[parents] => Array
(
)
[children] => Array
(
[U1] => Mage_Admin_Model_Acl_Role_User Object
(
[_roleId:protected] => U1
)
)
)
[U1] => Array
(
[instance] => bea423c23f6343e2b509fb192a00826f:3EOt7Vo0agtENPH8Wm73EOelgSDoDxYO
[parents] => Array
(
[G1] => Ryan
)
[children] => Array
(
)
)
)
So yeah, i guess my question comes in four parts:
Why doesn't this work out of the box?
Am I just being an idiot?
Why isn't PHP preventing this method from running considering the $resource variable is neither a Zend_Acl_Resource_Interface or null?
How do i fix it?
I should mention that this is a local test site, running on Ubuntu 12.04, Apache 2.4.9 (likely to be nginx in production though), PHP 5.5.12, Magento CE 1.9.0.2.
Thanks in advance,
Ryan
/*************************UPDATE*********************************/
Hi again everyone,
So I've noticed there is a pattern to how this problem/bug/whatever comes around. So, this is my admin url:
http://magento.example.local/admin_system/
If I go to this url, I am able to login and then this issue happens. At this point the url is now
http://magento.example.local/index.php/admin_system/[some_irrelevant_stuff]
So this is where it gets odd. If I then navigate to the original url I am once again redirected to the second url but the beginning of [some_irrelevant_stuff] is /index/denied/ (which I assume is relevant now haha).At this point I am provided the header of the Magento admin panel and I am able to logout.
OK so thats one part of the issue. If I then logout, or if I start my login process at /index.php/admin_system/ then I am able to log in and use the admin area as usual. So, the long and short of it is, I don't know what's going on but I'm hoping this extra info might get me more details.
Thanks for your time,
Ryan
Wow, I am genuinely surprised that nobody had an answer for this. Anyway, the following details are not so much an explanation as to what caused this issue, but a solution to stop it happening.
So, as you'll see from the edit of my question, I noticed that this seemed to have a bizarre connection to the URL and using different URLs to access the admin area (eg. /index.php/admin instead of /admin) caused different errrors. So for this reason, and because having index.php in all my admin area URLs, I took a look into rewriting the admin URLs. This is made available using this plugin: http://www.magentocommerce.com/magento-connect/admin-rewrites.html
If I'm not mistaken, I did not need to make any changes to the RewriteRule(s) that are set by default by magento so following the instructions on the plugin page above should work.
Either way, this appears to resolve the issue so I hope it helps someone having similar issues.

CodeIgniter Session syntax

Can someone quickly help me out with CodeIgniter's syntax. I need to access an array I stored in the session's userdata and I cant figure out the proper syntax.
<?php echo $this->session->userdata['user_session']['first_name']; ?>
gives me this error:
Fatal error: Cannot use object of type stdClass as array
All of the answers given in this Question dont work:
Access array variable in session (CodeIgniter)
This is how you get session data:
echo $this->session->userdata('first_name');
Been a while since I've worked in Codeigniter, but if I can remember correctly, when you store an array like you've stated, you'd call it like this:
$this->session->userdata("user_session")['first_name'];
Let me know if that works?
Or you can store that data to a variable, and call the array that way. Like such:
$data = array("bar" => "the_value");
$this->session->set_userdata("foo", $data);
$foo = $this->session->userdata("foo");
echo $foo["bar"]; //Outputs the_value
Let me know if that helped.
However, just to let you know.. Normally, storing the session data goes as follows:
$this->session->set_userdata("first_name", "value");
Really no need to go and set your own array inside of userdata, because that's generally what the userdata array is for.
I found the proper syntax. Well, at least one way to go about it. #Matt GrubB was the closest and put me on the right track.
$temp_session = $this->session->userdata('user_session');
echo $temp_session->first_name;
Since userdata is an object full of info created when I query my database, the easiest way to access the data is to take it and put it in another temporary array. You then have to stab it. I kept stumbling by trying to do $this->temp_session->first_name or something of the like.

How to get array with PHP on Joomla?

I've been making a Joomla module. I've mostly been successful, but I have one question: how do you get the image_fulltext variable to contain the following?
{"image_intro":"","float_intro":"","image_intro_alt":"","image_intro_caption":"","image_fulltext":"images\/sampledata\/parks\/landscape\/800px_cradle_mountain_seen_from_barn_bluff.jpg","float_fulltext":"","image_fulltext_alt":"Konsultasi belajar","image_fulltext_caption":""}
This functionality can be found inside the PHP library see json_encode and json_decode.

PHP - Using data from url, but not via post nor get

I'm sorry if is a repeated question, but i having trouble with PHP. I'm working with the code of another programer, and he is using php. In one of the pages que get the information from the url, but no via post nor get, but by attaching it to the url and putting / between them, like this:
www.example.com/memorial/31/john
the he uses 31 and john as data. I have no memorial directory, neither a file called memorial.
Is there a way to do this in PHP without a framework, he doesn't seem to be using any libraries either.
The most likely explanation is that he is using an URL rewrite engine, such as Apache's mod_rewrite. This will be doing something like turning the directory parts into GET variables.
You can find that information in the global $_SERVER variable: $_SERVER['REQUEST_URI']. As #Oli mentioned, this is probably through a rewrite engine.
For example if you went to the URL you mentioned (www.example.com/memorial/31/john):
$uriPieces = explode('/',$_SERVER['REQUEST_URI'],'/');
// this gets rid of all of the cases of double-slashes as well as the initial
// and trailing. This is optional, but I will generally prefer it.
$uriPieces = array_filter($uriPieces);
print_r($uriPieces);
Outputs
Array
(
[0] => memorial
[1] => 34
[2] => john
)
If you search your project for REQUEST_URI, you will find where the variables are being set.

accessing array from another page in php

I would like to know how can I access or read the array from another page. I am working on a PHP page which contains the array, and I want to display the content of that array on another PHP page.
For example, I used the following method in a PHP file and I want to get the content of the array in another PHP file. what is the method that is going to receive the array's content in the second page.
<?php
$r = new HttpRequest('http://localhost/sameh.php', HttpRequest::METH_POST);
$r->addPostFields(array("n" => 'heba')) ;
$r->send();
?>
This code is in the first page but I don't know what to write to receive it on the second one.
Maybe my question was not that clear and sorry about that ,, I want to find a way to access the array that is defined inside the HttpRequest() class on another page. So that the array "n" that include value "heba" will be displayed on another.php page. this is what make me thinking that the problem is on how to access the content of the array on the second page.
I tried the session and It sends the array to another page ,, but when I tested with the
httpRequest() method it doesn't send the content of the array "heba" to the second page.
Thanks for your help.
Sounds like this is a job for Sessions.
You can read the complete session guide here
In the script that has the array you can do something like:
session_start();
$_SESSION['array'] = $array;
In the next script you access it similarly:
session_start();
print_r($_SESSION['array']);
Include that file in your php file where you want to use that array. This should solve your issue PHP - How to send an array to another page?
I'm not sure what the HttpRequest class is, but at a guess, it's POSTing variables to the sameh.php file. You should be able to access the variable on the next page by doing this:
echo $_POST['n'];
Which should print "heba".
Note that to work with serialized arrays, you need to use POST as the form's transmission method, as GET has a size limit somewhere around 1024 characters.
I'd use SESSIONs wherever possible.
You can use serialize() and unserialize() on your array to represent it as a string and pass it via POST.

Categories