In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
Most people do not understand the knowledge points of this article, "what is the command of a custom template in php laravel?" so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "what is the command of a custom template in php laravel".
1. Create a ToJsServiceProvider
Namespace App\ Providers; use App\ Helpers\ ToJs\ ToJs; use Illuminate\ Support\ Facades\ Blade; use Illuminate\ Support\ ServiceProvider; class ToJsServiceProvider extends ServiceProvider {/ * Bootstrap the application services. * * @ return void * / public function boot () {/ /} / * * Register the application services. * * @ return void * / public function register () {$this- > app- > singleton ('tojs', function () {return new ToJs ();}); / * The block of code inside this directive indicates * the chosen javascript variables. * / Blade::directive ('tojs', function () {return';});}}
2. The ToJs method mainly operates on the array.
Namespace App\ Helpers\ ToJs; use Illuminate\ Support\ Arr; class ToJs {protected $data = []; public function put (array $data) {foreach ($data as $key = > $value) {$this- > data [$key] = value ($value);} return $this;} public function get ($key = null, $default = null) {if (! $key) return $this- > data Return Arr::get ($this- > data, $key, $default);} public function forget ($keys) {Arr::forget ($this- > data, $keys); return $this;}}
3. Declare facade
Namespace App\ Helpers\ ToJs\ Facades; use Illuminate\ Support\ Facades\ Facade; class ToJsFacade extends Facade {/ * Get the registered name of the component. * * @ return string * / protected static function getFacadeAccessor () {return 'tojs';}}
4. Add serviceProvider to the config array
Providers add
\ App\ Providers\ ToJsServiceProvider::class
Aliases add
'ToJs' = >\ App\ Helpers\ ToJs\ Facades\ ToJsFacade::class
5. To facilitate calling, you can write a helper method
If (! function_exists ('to_js')) {/ * Access the javascript helper. * / function to_js ($key = null, $default = null) {if (is_null ($key)) {return app ('tojs');} if (is_array ($key)) {return app (' tojs')-> put ($key);} return app ('tojs')-> get ($key, $default);}}
Call to_js (['username'= >' test']) where the PHP code requires it
The blade template can be rendered on the page directly through @ tojs.
The above is the content of this article on "what are the commands for customizing templates in php laravel?" I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.