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

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.

Related

404 CodeIgniter - Wrong Segments?

I'm a PHP Developer and I've been asked to sort out a project that has been built already in CodeIgniter. I hadn't used CodeIgniter before so I did a couple of tutorials to get up to speed.
The problem I'm having is when I download the project zip off GitHub, and install it, I get a CodeIgniter 404 page.
I debugged it to what I think is the source. In /system/Router.php
If I put this line of code print_r($segments); die(); at the beginning of the _validate_request function in /system/Router.php, it prints this output:
Array ( [0] => site2 [1] => index.php [2] => about )
The URL is
http://127.0.0.1/site2/index.php/about
BUT
If I put the same piece of code in a fresh install of CodeIgniter, I get this:
Array ( [0] => welcome [1] => index )
Now. It seems as though the site I'm working on has a certain way of routing that I don't understand. Has anyone else come across this? Am I just being a n00b? I really hope I am
In codeigniter segmenting starts after your base_url.
$config['base_url'] = 'http://www.test.com/testsite/index.php';
So your segment should start after baseurl
Url: http://www.test.com/testsite/index.php/welcome/index/product/vehicle/14
Then Your segment would be
1st welcome (Controller name)
2nd index (function name)
3rd product
4th vehicle
5th 14

Why can't an anonymous user see the xhprof link at the bottom if permission is set?

I set the permissions so that anonymous users can see xhprof but I can't seem to see the link at the bottom of the page when the page loads. I am able to view the page /admin/reports/xhprof/ as anonymous but just can't get the link to appear. I am sure it isn't hidden because I can't find it in Firebug.
I tried flushing the cache and running cron but still no luck.
I added a print_r to the following part of the xhprof code and I get some weird character response. So it leads me to believe that it is a problem somewhere with drupal_register_shutdown_function.
function xhprof_boot() {
// Initialize XHProf.
if (xhprof_xhprof_enable()) {
print_r(drupal_register_shutdown_function('xhprof_shutdown'));
}
}
I get a response of weird characters:
Array ( [0] => Array ( [callback] => xhprof_shutdown [arguments] => Array ( ) ) )
����r�H�0xmE�;T��mI� <��d�=�N�[��d�n�F(��##It��{���#���ͣ̓lfU�D$(QRwR�%�CfVVVfVV֫����?�쐞
�7�ɻ��[$� ��Ba�|�|xs~x����]JJ�b��s�#��������u�����n�:��l�Q���G�P���<-�
.....
.....
Fatal error: Call to undefined function drupal_get_path_alias() in
.../includes/common.inc on line 2250
Weird thing is I do have an older database of my site and the problem doesn't happen. Only happens on my production database copy of my site.
I tried commenting out every function that calls drupal_register_shutdown_function or register_shutdown_function but I can't seem to find what is causing the problem on my site.
I was able to fix my issue by going to Configuration -> Development and unchecking "Compress cached pages". This way I able to clear the cache and view the page as anonymous and see the link.
If I try to view the page the second time (since it is cached). I get this error below: Fatal error: Call to undefined function url() in .../sites/all/modules/xhprof/xhprof.module on line 190. I think that the xhprof was just meant to be viewed on on uncached pages.

php scripts that suddently stops working - where to start looking?

If someone doesn't feel like reading the whole explanation, you can skip to the last 2 paragraphs where I have the actual question
So I have this bunch of websites made with CakePHP. In one of the pages (this is the same for all the websites), I load an XML file and process its contents (using the XML helper). This has been working for quite some time. Now, suddenly, it doesn't work anymore in any of the websites (and the code hasn't changed a bit), it gives an "error opening file".
At the same time, another script of those websites (which has nothing to do with the previous one, it's plain PHP, outside the cakephp "area") has stopped working too. In this case, it's a scripts that creates a connection with a video hosting provider (Fliqz) and retrieves the URL of a video given a video id. Suddently, it throws an error something like "session was not created" (the script creates some sort of session with Fliqz' server to get the URL).
All this sounds very weird, I know. The first thing I've done, after checking that the code is correct, is call 1&1 (the hosting provider) and ask if they have made any change in the server. They said that they changed to PHP5 a few months ago (which I was aware of, and everything was working fine after that change), but that they haven't changed anything else.
My question would be, is there anything I can do to figure out what is causing these problems? For example, I found some post of someone saying that his hosting had restricted some functionality that allowed external connections. Or in another post I saw a suggestion about doing this: echo file_get_contents("http://google.com/") and I got an error, meaning that some setting wasn't right. I even tried to use simplexml_load_file (instead of the XMl helper) in the page where I load the XML file and didn't work, giving another error...
I would like to know, if a PHP setting is causing this, which one could it be, so I can look at it and call again 1&1 to tell them what they need to change (if there's anything to change). Otherwise, how in the world can something just stop working?
Thank you for any advice! It is much appreciated!
EDIT: detailed explanation of errors
1. Error related to the XML not loading using CakePHP's XML helper
This is the code I use (which used to worked perfectly):
$completeurl = '/full/path/to/file/myfile.xml';
App::import('Xml');
$xml =& new XML($completeurl);
$this->list = Set::reverse($xml);
I don't get any error or warning. If I debug $xml, I get this:
Xml Object
(
[__parser] =>
[__file] =>
[__rawData] =>
[__header] =>
[__tags] => Array
(
)
[version] => 1.0
[encoding] => UTF-8
[name] => #document
[namespace] =>
[namespaces] => Array
(
)
[value] =>
[attributes] => Array
(
)
[children] => Array
(
)
[__parent] =>
)
If I debug $this->list I get an empty array. Before this problem, I would get an associative array with all the information of the XML file, perfectly structured. Oh, and the XML file is the same it used to be, and I've revalidated it just in case giving no errors.
2. Error related to XML file not loading using simplexml_load_file()
This is the code I've tried with "regular" php (without using any CakePHP helper):
$file = '/full/path/to/file/myfile.xml';
if(!$xml = simplexml_load_file($file))
exit('Failed to open '.$file);
And this are the errors (warnings):
Warning (2): simplexml_load_file() [function.simplexml-load-file]: URL file-access is disabled in the server configuration [APP/plugins/icd_discovery/webroot/videos.php, line 29]
Warning (2): simplexml_load_file(http://discovery.ingles100.com/icd_discovery/xml/videos_unidades.xml) [function.simplexml-load-file]: failed to open stream: no suitable wrapper could be found [APP/plugins/icd_discovery/webroot/videos.php, line 29]
Warning (2): simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "http://discovery.ingles100.com/icd_discovery/xml/videos_unidades.xml" [APP/plugins/icd_discovery/webroot/videos.php, line 29]
If I put a relative path for the file, I just get the last warning, but still not loading it.
** 3. Error related to script to load URL of hosted videos in Fliqz**
The page that contains this script is totally unrelated to the previous ones (meaning that the code there doesn't affect the code here). We use the following script (provided by Fliqz) to request the URL of our videos hosted there:
include_once '../fliqz/dlMetrics.php';
// initializing new session
$videoID = '123123123';
$applicationID = '456456456';
$uniqueID = null;
// create a new fliqzDownload Object
$metricsObj = new dlMetrics();
// get new session, using Application ID from Account:
$sessionID = $metricsObj->newSession($applicationID,NULL,NULL,NULL,$uniqueID);
// show server time when new session was created:
$start = $metricsObj->getSessionStart();
// Get asset location (note: must use dashes in asset ID example: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
$video_URL = $metricsObj->initLoad($videoID);
By doing this, we would get the URL of the video in the $video_URL variable. Again, this used to work perfectly. Suddenly, it doesn't.
So is it a coincidence that all this things stop working? I think that something has changed somewhere. Not the code, I'm the only one who touches that. The PHP version changed a while ago, and everything was working fine. Something in the server? 1&1 says that they didn't, or at least the person I talked to. If I have to call back, I would like to be able to point a little better where do I think the problem might be coming from, that's why I need you help guys!
Again, thanks for any advice!
Create a file called php.ini with the following content:
allow_url_fopen = ON
and place it in the same folder (or folders) as those scripts.

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.

Spoon-library acts different on localhost then on webhosting

I have a problem regarding the spoon-library (www.spoon-library.com). I have a folder with subfolders, each subfolder is a 'reference' from my dad his company. (although its translated to my native language). Each of the 'reference' subfolder contains images.
I am reading the names of al subfolders and the images that are in that specific folder and save it to an array. With the use of spoon-library i am nesting these in template variable in my tpl files. So basically I print the <h2></h2> with the project's title (the subfolder name), and all his images (so that they can be viewed through lightbox).
On my localhost and my website (provider A) it works, but when i upload it to my dad his hosting (provider B) it doens't work.
ex.
http://davyloose.be/electroloose/projecten.php -> it works.
http://electro-loose.be/projecten.php -> it doens't work.
The code is identical.
Example of the array with the data that i get through the folders (note, i get the same data on both webspace):
Array (
[0] => Array (
[title] => Apotheek Beerlandt
[images] => Array (
[0] => Array ( [url] => beerlandt 2.JPG )
[1] => Array ( [url] => beerlandt 3.JPG )
[2] => Array ( [url] => beerlandt 1.JPG )
)
)
)
This is entered in the following 'html' code (template file):
{iteration:referenties}
<h2>{$referenties.title}</h2>
<div id="imageslide">
{iteration:referenties.images}
<img src="/images/referenties/{$referenties.title}/thumbs/{$referenties.images.url}" />
{/iteration:referenties.images}
</div>
{/iteration:referenties}
Note: references in my native language is 'referenties'.
It seems that on my dad his webhosting a '.' changed to '->', although i'm not really sure (as in 'I can't believe that).
The php version on my localhost and my webhosting are PHP5.3.5, the version on my dad his hosting is 5.1.2.
I hope you guys can help me out on this one :).
PS: I know i can fix this with the use of an sql database. And i'm going to do that in the near future, but for now i just want to know why this error is occurring.
Thanks in advance!
Edit: I just enabled the display_errors in my php.ini and now i see the following error 'Notice: Undefined variable: count in /var/www/html/test/spoon/template/compiler.php on line 913' (and also on some other lines). Still, it's a mystery why it works on my localhost and not on my dad his host.
I'm the author of Spoon Library. I believe the issue lies with the differences in the PHP versions. The $count parameter that the notices are talking about were added in PHP5.1, but for some reason they don't seem to work exactly as expected in the PHP version on your dad's host.
I'd recommend to try and get the hosting to use at least PHP5.2, because there are another few issues that might occur within other spoon packages because of this.
If you need any more help you can always find me on twitter(#spoonlibrary) or e-mail me (davy#spoon-library.com)

Categories