laravel doesn't use published views - php

For my Laravel 5.5 project I used filemanager package (elfinder-laravel ) with published and adapted blade views. After awhile I found that default views are used from package folder:
/vendor/barryvdh/laravel-elfinder/resources/views
instead of published views:
/resources/views/vendor/elfinder
I tried to republish views, clear views and cache. But nothing helps, it still uses default package views.
Views in /resources/views/vendor/elfinder exist.
Any idea how to make it work?

Try to edit the service provider file to be like that :
public function boot()
{
$this->loadViewsFrom($this->app->resourcePath('views/vendor/elfinder'), 'elfinder');
}
It is forces the file to use this directory as main view directory instead of changing it.

The question is quite old, but you have to set in the
$this->loadViewsFrom(__DIR__.'/../resources/views', 'courier');
the same package name as in the
$this->publishes([
__DIR__.'/../resources/views' => resource_path('views/vendor/courier'),
]);
(notice both times the courier)
See: https://laravel.com/docs/8.x/packages#overriding-package-views

Related

How to make aliases for Controller of my Laravel custom package

I'm on the way of creating a Laravel package for our internal use, that's why it's not in packagist, and not in vendor/ directory. Instead it's in packages/ directory - a custom directory of ours - a similar approach we used for another package of our internal use.
Issue is, in the blades from the package we used action('MyPackageController#method') to produce links. After publishing the view files to the application the current path of the views are like resources/views/vendor/mypackage/one-directory/index.blade.php.
With a global access to the controller it simply is working:
action('\MyVendor\MyPackage\App\Controllers\MyPackageController#edit', ['id' => $item->id])
But issue is, when I'm trying to impose aliases for the controller[s], they are not working. In config/app.php aliases, I mentioned:
'XYZ' => MyVendor\MyPackage\App\Controllers\MyPackageController::class,
'ABC' => MyVendor\MyPackage\App\Controllers\MyPackageSecondController::class,
and in index.blade.php I tried using:
action('ABC#edit', ['id' => $item->id])
but it's not working. Because it's trying to find the controller in App\Http\Controllers\:
ErrorException (E_ERROR)
Action App\Http\Controllers\ABC#edit not defined. (View: D:\laragon\www\test-laravel\resources\views\vendor\mypackage\one-directory\index.blade.php)
Aren't package controllers be aliased?
PS. I tried clearing all types of caching.
As even after a long time, Martin Bean did not add any answer to the thread, here I'm posting one for future record:
As Martin Bean said in his comment:
You’d used a named route instead of action(): laravel.com/docs/master/routing#named-routes
What I found is: the action() function has its own caveat, it cannot take other namespaces other than App\Http\Controllers. So named route did it for me: route('my_name', ['id' => $item->id]);.
Thanks to Martin Bean for his clue.
First of all, you have to register your routes in the service provider of your package.
boot() {
require __DIR__ . '/Http/routes.php';
}
__DIR__ would point to the root of your package folder. This is assuming your routes are registered in your packages' Http directory. If this is done, make sure you use a unique name for your route and just call your action like so:
action="{{route-name}}"
That's all you have to do.

Is there a way to force Yii2 to reload module assets on every request?

My website is divided into separate modules. Every module has it's own specific css or js files.
Yii's assetManager creates a folder when I first open a page that uses my assets.
Unfortunately if I change something in my files Yii 1.x does not reload my css or js files.
I have to manually delete the web/assets folder. It is really annoying when you are developing the app.
This works when I add a module to the backend folder, but not when I'm creating a module in the vendor folder with my own namespace.
In Yii2 you can append a timestamp to the URLs of assets like this...
return [
// ...
'components' => [
'assetManager' => [
'appendTimestamp' => true,
],
],
];
This won't force the assets to reload on every request but whenever an asset file is changed the URL will change because of the timestamp & that will force the asset to be re-published.
You can set forceCopy = true.
class Assets extends AssetBundle{
public function init()
{
parent::init();
$this->publishOptions['forceCopy'] = true;
}
}
With respect to Yii1.x With assetManager you can do this by setting 'forceCopy' attribute to true in your config file
... copy the asset files and directories even if they already published
before. This property is used only during development stage
See forceCopy documentation here for more info.
Alternatively you can use linkAssets which will not copy the files but create an soft link between your asset files and yours assets directory. You cannot of course use both.
For the second part of the question I am assuming this is in Yii 2.x, you are supposed to use AssetBundles, you can register any namespace bundle from anywhere, you simply register it in the view with some like this
use vendor\myVendorName\myPackageName\assets\AppAsset;
AppAsset::register($this);

Adding a view to Slim Views Framework with composer

I am writing a PHP template system for Slim, I have it working fine, but it is necessary to install the view file Ets.php in the correct existing location:
vendor/slim/views/Slim/Views/Ets.php
Whilst I can do it manually of course this defeats the object of composer. I was wondering if I can do it with https://getcomposer.org/doc/articles/custom-installers.md but I am having trouble following the guide as it and others only really talk about installing outside of the vendor directory.
Why do you want the views to get installed in the same place?
Have a look into http://docs.slimframework.com/#Custom-Views
You just need to extend the Slim\View. An example taken from the docs
class CustomView extends \Slim\View
{
public function render($template)
{
return 'The final rendered template';
}
}
and integrate in to slim like
$app = new \Slim\Slim(array(
'view' => new CustomView()
));
NB : Don't forget to do the autoload the classes required.

How to load view from alternative directory in Laravel 4

In my Laravel 4 application's root directory, I have a folder themes. Inside the themes folder, I have default and azure.
How can I access view from this themes/default folder in a specific route.
Route::get('{slug}', function($slug) {
// make view from themes/default here
});
My directory structure:
-app
--themes
---default
---azure
I need to load views from localhost/laravel/app/themes/default folder. Please explain this.
This is entirely possible with Laravel 4. What you're after is actually the view environment.
You can register namespace hints or just extra locations that the finder will cascade too. Take a look here
You'd add a location like so:
View::addLocation('/path/to/your/views');
It might be easier if you namespace them though, just in case you have conflicting file names as your path is appended to the array so it will only cascade so far until it finds an appropriate match. Namespaced views are loaded with the double colon syntax.
View::addNamespace('theme', '/path/to/themes/views');
return View::make('theme::view.name');
You can also give addNamespace an array of view paths instead of a single path.
Here I am not accessing my project from public folder. Instead of this I am accessing from project root itself.
I have seen a forum discussion about Using alternative path for views here. But I am little confused about this.The discussed solution was,
You'd add a location like,
View::addLocation('/path/to/your/views');
Then add namespace for theme,
View::addNamespace('theme', '/path/to/themes/views');
Then render it,
return View::make('theme::view.name');
What will be the value for /path/to/ ?
Can I use the same project in different operating system without changing the path?
Yes, we can do this using the following,
Put the following in app/start/global.php
View::addLocation(app('path').'/themes/default');
View::addNamespace('theme', app('path').'/themes/default');
Then call view like the default way,
return View::make('page');
This will render page.php or page.blade.php file from project_directory/app/themes/defualt folder.
I've developed a theme package for laravel 5 with features like:
Views & Asset seperation in theme folders
Theme inheritence: Extend any theme and create Theme hierarcies
Try it here: igaster/laravel-theme
\View::addLocation($directory); works fine but the new right way to do it is using loadViewsFrom($path, $namespace) (available on any service provider).

Loading lib from plugin - cakephp

I have a plugin and inside the plugin I have a Lib folder.
Like this:
Lib/Billing/CMS/CMS.php
How can I use the CMS class inside CMS.php on my controller? Not my plugin controller, but a controller on my application.
EDIT: Cake version is 2.3
So, from your short information one can only guess...
Your plugin is "Billing"?
Your files are
APP/Plugin/Billing/Lib/CMS/CMS.php (class CMS)
APP/Plugin/Billing/Lib/Billing.php (class Billing)
You include classes always the same, using App::uses().
Then its
App::uses('CMS', 'Billing.CMS'); // Filename, Plugin.Package
and
App::uses('Billing', 'Billing.Lib'); // Lib as package namespace here due to lack of a proper one
I do not have to point out, that you need to load your plugin first, right?
Using CakePlugin::load()/loadAll()

Categories