Incorrect local path

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
usernick
Registered User
Posts: 7
Joined: Tue Jan 16, 2018 2:35 pm

Incorrect local path

Post by usernick » Wed Aug 29, 2018 11:00 am

I use parameter img_path in 'services.yml':

Code: Select all

parameters:
    my.ext.img_path: '%core.root_path%images/myext/'
services:
    my.ext.controller:
        class: my\ext\controller\main
        arguments:
            - '@my.ext.core.ext.main'
            - '@my.ext.core.ext.other'

    my.ext.core.ext.main:
        class: my\ext\core\ext_main
        arguments:
            ...
            - '%my.ext.img_path%'
            
    my.ext.core.ext.other:
        class: my\ext\core\ext_other
        arguments:
            ...
            - '%my.ext.img_path%'
in routing.yml i have

Code: Select all

my_ext_controller:
    path: /ext/{name}
    defaults: { _controller: my.ext.controller:handle, name: "main" }
in controller\main.php i have

Code: Select all

public function handle($name)
 {
  switch($name)
  {
   case 'main': $this->ext_main->main();
   break;
   case 'other': $this->ext_other->main();
   break;
   default:
   redirect ($this->helper->route('my_ext_controller', array('name' => 'main')));
  }
 }
\core\ext_main.php, \core\ext_other.php

Code: Select all

class ext_main / class ext_other
{
protected $img_path;
...
public function __construct(
...
$img_path
...
)
{
...
$this->img_path 						= $img_path;
...
}
img_path returns path
./images/myext/
regardless of the route of the page

thus, it is valid only in the first case,
http://{my_site}/ext - the 'main' page with default route
(url's directory is '/', and file is 'ext', then img_path points to '/images/myext/')

and not valid in other cases
http://{my_site}/ext/main - the 'main' page with direct access
http://{my_site}/ext/other - the 'other' page
(url's directory is '/ext/', and file is 'main', then img_path points to '/ext/images/myext/')

How do I do this correctly?

User avatar
VSE
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 4707
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman
Contact:

Re: Incorrect local path

Post by VSE » Thu Aug 30, 2018 10:28 pm

For starters:

Code: Select all

parameters:
    my.ext.img_path: '%core.root_path%ext/vendorname/extname/images/'


my_ext_controller:
    path: /{name}
    defaults: { _controller: my.ext.controller:handle, name: "main" }
Dictated but not read.
Official phpBB Extensions My Extensions & MODs
Please do not PM me for support.

Post Reply

Return to “Extension Writers Discussion”

Who is online

Users browsing this forum: No registered users and 7 guests