Function to get file from store

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
User avatar
AmzoooJibal
Posts: 35
Joined: 12 Mar 2021, 20:09

Function to get file from store

Post by AmzoooJibal » 01 Jun 2021, 11:10

hello,
i have created a helper file in laravel project with this function that return the file from store like this:

Code: Select all

function file_from_store($path): string
    {
        $context = app('aimeos.context')->get();
        $config = $context->getConfig();
        $baseUrl = $config->get('resource/fs/baseurl');
        $view = new \Aimeos\MW\View\Standard();
        $view->addHelper('encoder', new \Aimeos\MW\View\Helper\Encoder\Standard($view));
        $view->addHelper('content', new \Aimeos\MW\View\Helper\Content\Standard($view, $baseUrl));
        return $view->encoder()->attr($view->content($baseUrl . '/' . $path));
    }
My question is there a sample why to optimize this function because i have instanciate another object maybe there is already existing one . i have tried like this but not working:

Code: Select all

$view = app('aimeos.view')->get();
        $context = app('aimeos.context')->get();
        $config = $context->getConfig();
        $baseUrl = $config->get('resource/fs/baseurl');
        return $view->encoder()->attr($view->content($baseUrl . '/' . $path));

User avatar
aimeos
Administrator
Posts: 8648
Joined: 01 Jan 1970, 00:00

Re: Function to get file from store

Post by aimeos » 03 Jun 2021, 08:41

Normally, something like this should work:

Code: Select all

function file_from_store($path): string
{
	$view = app('aimeos.view')->get();
	return $view->encoder()->attr($view->content$path));
}
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
AmzoooJibal
Posts: 35
Joined: 12 Mar 2021, 20:09

Re: Function to get file from store

Post by AmzoooJibal » 03 Jun 2021, 18:02

i get an exception with get(), i searched in project i have found view object is instantieted like this:

app( 'aimeos.view' )->create( $context, $tmplPaths, $langid ) ?

User avatar
aimeos
Administrator
Posts: 8648
Joined: 01 Jan 1970, 00:00

Re: Function to get file from store

Post by aimeos » 04 Jun 2021, 05:56

You are right, in then it's:

Code: Select all

function file_from_store( $path ): string
{
	$context = app('aimeos.context')->get();
	$langId = $context->getLocale()->getLanguageId();
	$paths = app('aimeos')->get()->getCustomPaths( 'client/html/templates' );
	$view = app('aimeos.view')->create( $context, $paths, $langId );

	return $view->encoder()->attr( $view->content( $path ) );
}
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
AmzoooJibal
Posts: 35
Joined: 12 Mar 2021, 20:09

Re: Function to get file from store

Post by AmzoooJibal » 04 Jun 2021, 17:05

Yeh Great it work as expected, thank you ;)

Post Reply