简体   繁体   English

覆盖Laravel 4 Package视图

[英]Override Laravel 4 Package view

I want to create my custom CMS and I'd like to create a user package in which I will have a controller with showProfile() function. 我想创建我的自定义CMS,我想创建一个用户包,其中我将有一个带有showProfile()函数的控制器。 But the problem is I'd like to easily edit this profile view. 但问题是我想轻松编辑此配置文件视图。 So I want to know if there is a way to create cascade view. 所以我想知道是否有办法创建级联视图。 Like if there is no file in app/views/ then vendor/vendor/package/src/views will be loaded. 就像app / views /中没有文件一样,那么将加载vendor / vendor / package / src / views。 I hope you got this idea :) 我希望你有这个想法:)

EDIT: 编辑:

I managed to make it work. 我设法让它发挥作用。 I had to register new namespace for views in my ServiceProvider. 我必须在ServiceProvider中为视图注册新的命名空间。 I put this code to ServiceProvider: 我将此代码放到ServiceProvider:

\View::addNamespace('cmscore',array(app_path()./'views/packages/zaalbarxx/cmscore');

Where zaalbarxx/cmscore is vendor/package and cmscore is a namespace I can use later in controller like View::make('cmscore::index'). 其中zaalbarxx / cmscore是vendor / package而cmscore是一个命名空间,我稍后可以在控制器中使用,比如View :: make('cmscore :: index')。 I added this code in boot() method BEFORE $this->package() so this way app/views are prioritized over package/views. 我在boot()方法BEFORE $ this-> package()中添加了这个代码,所以这样app / views就优先于包/视图。 Works brilliant. 作品精彩。

这已经成为可能了,但是默认情况下结构是查看vendor/package-name/src/views ,但是如果在app/views/packages/package-name/中有相应的选择。

As stated, you should be able to load package views already. 如上所述,您应该能够加载包视图。

However, you can add more view locations in the array found in app/config/view.php . 但是,您可以在app / config / view.php中找到的数组中添加更多视图位置。

Additionally view paths can be added at run-time with the addLocation() method found in the FileViewFinder class. 此外,可以使用FileViewFinder类中的addLocation()方法在运行时添加视图路径。

Using that method that in a service provider would look like: 使用服务提供程序中的方法:

$app['view.finder']->addLocation('/path/to/views');

Or anywhere in your app: 或者您应用中的任何位置:

App::make('view.finder')->addLocation('/path/to/views');

Also note, I answered this question on cacheing view output recently, which might help you see how extending some portions of the View package might work if you choose to go down that route. 另请注意,我最近在缓存视图输出时回答了这个问题 ,这可能会帮助您了解如果您选择沿着该路线延伸,扩展View包的某些部分可能会如何工作。

You don't need to program this behavior in, if you read the laravel code you will see that this is built in... 您不需要编写此行为,如果您阅读了laravel代码,您将看到它内置于...

Packages by default will first look in and app/views/packages/package-name/ (all in lowercase! even if package or author have caps! goes unnoticed on windows and then on linux you will bump your head against the wall! ) 默认情况下,包将首先查看app/views/packages/package-name/ (全部为小写!即使包或作者有上限!在Windows上不被注意,然后在linux上你会撞到墙上!)

and if the customer app view doesn't exist the package views will load from the package itself inside: vendor/author/package-name/src/views 如果客户应用程序视图不存在,则包视图将从包本身加载: vendor/author/package-name/src/views

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM