Skip to content
This repository has been archived by the owner on Jan 25, 2021. It is now read-only.

Customising folder paths breaks Panel behaviour #447

Closed
huntie opened this issue Apr 30, 2015 · 18 comments
Closed

Customising folder paths breaks Panel behaviour #447

huntie opened this issue Apr 30, 2015 · 18 comments
Assignees
Labels
Milestone

Comments

@huntie
Copy link

huntie commented Apr 30, 2015

Hey all,

I've had an issue with Panel not loading and presenting a blank page after configuring paths in $kirby->roots and $kirby->urls to tweak my project folder structure according to the documentation.

site.php

<?php

$kirby = kirby();

// Custom roots
$kirby->roots->avatars = $kirby->roots()->index() . DS . 'assets' . DS. 'img' . DS . 'avatars';
$kirby->roots->thumbs = $kirby->roots()->index() . DS . 'assets' . DS. 'img' . DS . 'thumbnails';

// Custom URLs
$kirby->urls->avatars = $kirby->urls()->index() . '/assets/img/avatars';
$kirby->urls->thumbs = $kirby->urls()->index() . '/assets/img/thumbnails';

I've tried other folder locations and isolating one set of changes at a time, but _any_ path modification seems to break the Panel, and each time the referenced directories were present and correct.

When inspecting the blank Panel page with site.php active it is trying to load assets from a different URL:

http://localhost/projects/kirby-starter/panel/panel/assets/css/panel.css (with path changes)
http://localhost/projects/kirby-starter/panel/assets/css/panel.css (normal)

For some reason there is an additional panel/ in the path. Interestingly, if I then visit http://localhost/projects/kirby-starter/panel/panel/, part of the Panel markup does load.

As a first-party plugin, these global configuration changes ought not to break things :\ and I would prefer not hacking to fix this, as I have Panel included as a Git submodule. Also I'd hope that subsequent uploads through the Panel will respect the updated paths.

Many thanks.

Original Kirby forum question ↗

@distantnative distantnative added this to the 2.1 milestone May 5, 2015
@distantnative
Copy link

I'm not too sure how to fix this, but I got the following:

The error can be traced back to the kirby()->urls()->index() function in kirby/kirby/urls.php:

  public function index() {

    if(isset($this->index)) return $this->index;

    if(r::cli()) {
      return $this->index = '/';
    } else {
      return $this->index = url::base() . preg_replace('!\/index\.php$!i', '', server::get('SCRIPT_NAME'));
    }

  }

In case of your custom folder setup, $this->index is not set and, thus, the first if fails. Also the second one fails, so we end in the else-part.

Now I am wondering if it would be a solution to also preg_replace a potential panel/ part or if it should rather be required to define $kirby->urls->index in a custom site.php, no matter if multi-domain or not, @bastianallgeier?

@bastianallgeier
Copy link
Contributor

Right now this is only fixable if you set the $kirby->urls->index manually before defining the other urls. It's more complicated to auto-detect this than it seems, so I'm postponing this for now.

@huntie
Copy link
Author

huntie commented May 9, 2015

Thanks guys for addressing this. I've set $kirby->urls->index explicitly now and all is good for the time being — would be great if the base URL is automatically handled later though :)

@malvese
Copy link
Contributor

malvese commented Jun 24, 2015

Glad I found this issue, I lost a couple hours trying to figure out what was going wrong. If this can't be fixed in the next release, may I suggest adding to the docs that we have to set $kirby->urls->index?
In the meantime, thank you for providing this solution!

@distantnative distantnative removed this from the 2.2 milestone Nov 10, 2015
@Ventricule
Copy link

I also lost a couple hours searching what was wrong ! Definitly it will be nice to add the fix to the doc, in custom folder documentation page.

@dionysiusmarquis
Copy link

+1

@bnomei
Copy link

bnomei commented Mar 3, 2016

would be nice to use config and not setting it hardcoded. am i missing something?

config.localhost.php

c::set('url', 'http://localhost:8888');

i added this to my custom site.php

$kirby = kirby();
// $kirby->urls->index = c::get('url'); // does not work
$kirby->urls->index = 'http://localhost:8888';
$kirby->roots->content = $kirby->roots()->index() . DS . 'data'; // changing the directory
$kirby->urls->content = $kirby->urls()->index() . DS . 'data'; // changing the url

@JimmyRittenborg
Copy link
Contributor

@bnomei how about something along the lines of

$kirby = kirby();
// $kirby->urls->index = url::scheme() . '://' . server::get('HTTP_HOST');
$kirby->urls->index = server::get('REMOTE_HOST'); // if this doesn't output protocol and port (can't remember), you could instead try HTTP_HOST and stitch it together with protocol and port 
$kirby->roots->content = $kirby->roots()->index() . DS . 'data'; // changing the directory
$kirby->urls->content = $kirby->urls()->index() . DS . 'data'; // changing the url

@bnomei
Copy link

bnomei commented Mar 3, 2016

when entering url:
http://localhost:8888/panel

REMOTE_HOST does nothing to fix it
http://localhost:8888/panel/panel/login

HTTP_HOST duplicates the output
http://localhost:8888/localhost:8888/panel/login

in both cases root does work correctly
http://localhost:8888/

do i need the custom site.php in both / and /panel/ ?
https://github.com/getkirby/panel/blob/master/index.php#L8
https://github.com/getkirby/panel/blob/master/index.php#L19

lukasbestle added a commit that referenced this issue Jul 5, 2016
Previously the Panel would break if `kirby()->urls()->index()` was called (not set!) inside the `site.php` file for custom folder setups. The reason behind this is that the `index()` method caches its result and then the Panel's `index.php` would think that the URL has been set manually and not apply the URL fix.

This commit together with getkirby/kirby#477 fixes this behavior by checking instead if the URL has been detected or really set manually. This is a more reliable approach here.
@lukasbestle
Copy link
Member

There is now finally a fix for this, see #887. Please test if my code changes for both the Panel and Kirby (see getkirby/kirby#477) work for you. This will then be included in the next Kirby release.

lukasbestle added a commit that referenced this issue Jul 6, 2016
…etup

Fix #447: Proper support for custom folder setup
@lukasbestle
Copy link
Member

The fix for this will be included in Kirby 2.3.1. You don't need to manually set the index URL anymore with the fix.

@erikfriberg
Copy link

erikfriberg commented Jul 12, 2016

Still seems like you need to define $kirby->urls->index manually in order to get image previews and image links to work in panel.

Urls turns into this:
http://mydomain.com/api/panel/../content/home/20160608-oeo/dscf3444.jpg

when they should really be:
http://mydomain.com/api/../content/home/20160608-oeo/dscf3444.jpg
which is a problem if you intend to leave the content folder in the parent directory

@lukasbestle
Copy link
Member

lukasbestle commented Jul 13, 2016

Could you please post your site.php so that I can test with your setup? I couldn't reproduce this after fixing this issue.

@erikfriberg
Copy link

erikfriberg commented Jul 13, 2016

This is my site.php

<?php

$kirby = kirby();

// changing the directory
$kirby->roots->content = $kirby->roots()->index() . '/content';

// changing the url
$kirby->urls->content = $kirby->urls()->index() . '/content';

//change thumbnail folder
$kirby->roots->thumbs = $kirby->roots()->index() . '/../render/assets/thumbs';
$kirby->urls->thumbs  = $kirby->urls()->index() . '/../render/assets/thumbs';

I moved back the content folder so it was still in the same folder as my site.php but it wouldn’t make a difference.

@lukasbestle lukasbestle modified the milestones: 2.3.2, 2.3.x Jul 18, 2016
lukasbestle added a commit that referenced this issue Jul 25, 2016
The last fix in Kirby 2.3.1 fixed only parts of the issue. If users get the value of $kirby->urls()->index() inside the site.php, the URL would still be incorrect.

By moving the fix directly into the Kirby Url class, it is applied immediately.
lukasbestle added a commit to getkirby-v2/kirby that referenced this issue Jul 25, 2016
@lukasbestle
Copy link
Member

You are right. I apparently only fixed parts of this issue in Kirby 2.3.1.
The new fix should work. Could you please test the version from the develop branches of the Kirby and Panel repos?

@erikfriberg
Copy link

erikfriberg commented Aug 8, 2016

Hi again!
Sorry for the delay (vacation).
Everything seems to be working as it should now in the latest developer branches!
Awesome!

(and sorry for my two deleted posts since I clearly forgot about what was the problem in the first place :-p)

@lukasbestle
Copy link
Member

Thanks for your reply. The fix is already in the latest Kirby release, Kirby 2.3.2. :)

@erikfriberg
Copy link

Tested there too now, works perfect! 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

10 participants