milesj / utility

[Deprecated] A CakePHP plugin for common utility classes.
MIT License
69 stars 24 forks source link

Sitemap - error on line 1 at column 6: XML declaration allowed only at the start of the document #19

Closed GrahamDodgson closed 10 years ago

GrahamDodgson commented 10 years ago

Seems to generate a space at the start of the XML

<?xml version="1.0" encoding="UTF-8"?>http://localhost:8080/bidup/auctionshourly0.5http://localhost:8080/bidup/auctions/view/12013-11-29T11:24:00+00:00weekly0.9http://localhost:8080/bidup/auctions/view/22013-

Identified that it happens on the first pass thru :

    foreach ($controllers as $controller) {
        App::uses($controller, 'Controller');

        // Don't load AppController's, SitemapController or Controller's who can't be found
        if (strpos($controller, 'AppController') !== false || $controller === 'SitemapController' || !App::load($controller)) {
            continue;
        }
        $instance = new $controller($this->request, $this->response);
        $instance->constructClasses();

        if (method_exists($instance, '_generateSitemap')) {
            if ($data = $instance->_generateSitemap()) {
                $sitemap = array_merge($sitemap, $data);
            }
        }
    }

in the site map controller - but I cannot see why? we do have an admins controller which does not have the generate site map code - this seems to be where its being genreated?

milesj commented 10 years ago

Can you verify that it reaches the view?

https://github.com/milesj/utility/blob/master/View/Sitemap/xml/index.ctp

GrahamDodgson commented 10 years ago

Yes Miles it reaches the view (I placed echo’s in there to determine where the space happens and it happens in the controller before the view). The view information is displayed and if I take it (without the space) and place it in a document it works. Just can’t see why its producing the space….any ideas on where to try debugging the issue would be appreciated!

Graham

From: Miles Johnson [mailto:notifications@github.com] Sent: 10 December 2013 18:12 To: milesj/utility Cc: Graham Dodgson Subject: Re: [utility] Sitemap - error on line 1 at column 6: XML declaration allowed only at the start of the document (#19)

Can you verify that it reaches the view?

https://github.com/milesj/utility/blob/master/View/Sitemap/xml/index.ctp

— Reply to this email directly or view it on GitHubhttps://github.com/milesj/utility/issues/19#issuecomment-30252646.

milesj commented 10 years ago

Do one of the controllers being imported have a space at the end of the file?

GrahamDodgson commented 10 years ago

Miles, I’ve been through every controller and made sure than no spaces exist after the final ‘}’ – I am however still getting the same error?

From: Miles Johnson [mailto:notifications@github.com] Sent: 11 December 2013 18:06 To: milesj/utility Cc: Graham Dodgson Subject: Re: [utility] Sitemap - error on line 1 at column 6: XML declaration allowed only at the start of the document (#19)

Do one of the controllers being imported have a space at the end of the file?

— Reply to this email directly or view it on GitHubhttps://github.com/milesj/utility/issues/19#issuecomment-30344928.

milesj commented 10 years ago

I'm not really sure as it works correctly for me. Do you close your PHP files with ?> or do you leave the tag off? It might be in another file besides the controller.

GrahamDodgson commented 10 years ago

Miles, I’ve been leaving the tag off as bake does but will go thru and end the php files with ?> I’ll also check all the model files as well. Thanks for this.

Graham

From: Miles Johnson [mailto:notifications@github.com] Sent: 12 December 2013 18:16 To: milesj/utility Cc: Graham Dodgson Subject: Re: [utility] Sitemap - error on line 1 at column 6: XML declaration allowed only at the start of the document (#19)

I'm not really sure as it works correctly for me. Do you close your PHP files with ?> or do you leave the tag off? It might be in another file besides the controller.

— Reply to this email directly or view it on GitHubhttps://github.com/milesj/utility/issues/19#issuecomment-30447139.

milesj commented 10 years ago

Ever figure this out?

GrahamDodgson commented 10 years ago

Not yet chap – gone thru and made sure we had ?> at the end of each PHP file – just looks like its placing a space at the front??? More debugging to come ;)

From: Miles Johnson [mailto:notifications@github.com] Sent: 06 January 2014 07:55 To: milesj/utility Cc: Graham Dodgson Subject: Re: [utility] Sitemap - error on line 1 at column 6: XML declaration allowed only at the start of the document (#19)

Ever figure this out?

— Reply to this email directly or view it on GitHubhttps://github.com/milesj/utility/issues/19#issuecomment-31632457.

GrahamDodgson commented 10 years ago

Miles, Yes – found the problem – it was an erroneous space at the front of app controller – all working now! Thanks very much for the help and the Utility!

Graham

From: Miles Johnson [mailto:notifications@github.com] Sent: 06 January 2014 07:55 To: milesj/utility Cc: Graham Dodgson Subject: Re: [utility] Sitemap - error on line 1 at column 6: XML declaration allowed only at the start of the document (#19)

Ever figure this out?

— Reply to this email directly or view it on GitHubhttps://github.com/milesj/utility/issues/19#issuecomment-31632457.

milesj commented 10 years ago

Congrats on finding the space! I'm sure that was extremely tedious.

cbanowsky commented 10 years ago

an easier method to removing that troublesome whitespace: no extra code to bloat your theme either:

http://cameron.ghost.io/fixing-rss-feed-in-wordpress/