You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/docs/frontend/bareui.md
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,18 +39,18 @@ composer require leafs/bareui
39
39
40
40
:::
41
41
42
-
Once installed, BareUI will be available in your Leaf app on the `bareui()` method. This makes it easy to use BareUI from anywhere in your app.
42
+
Once installed, BareUI will be available in your Leaf app on the `template()` method. This makes it easy to use BareUI from anywhere in your app.
43
43
44
-
```php
45
-
app()->bareui()->render('welcome');
44
+
```php:no-line-numbers
45
+
app()->template()->render('welcome');
46
46
```
47
47
48
48
## Configuring BareUI
49
49
50
50
BareUI doesn't require any real configuration to work, but you need to tell it where to look for your templates. You can do this using the `config()` method. If you are using Leaf MVC, this has already been done for you in the `config/view.php` file, so you can skip this step.
51
51
52
-
```php
53
-
app()->bareui()->config('path', './views');
52
+
```php:no-line-numbers
53
+
app()->template()->config('path', './views');
54
54
```
55
55
56
56
This will tell BareUI to look for templates in the `views` directory in your project. Now that BareUI knows where to look for templates, you can start writing your templates.
@@ -82,8 +82,8 @@ BareUI templates are regular PHP files, so you can create your templates using P
82
82
83
83
Once you have your template, you can render it using the `render` method. This method takes in the name of the template to render and an array of data to pass to the template.
84
84
85
-
```php
86
-
echo app()->bareui()->render('welcome');
85
+
```php:no-line-numbers
86
+
echo app()->template()->render('welcome');
87
87
```
88
88
89
89
When rendering a template, you don't need to include the `.view.php` extension in the template name. BareUI automatically adds it for you when it looks for the template file. So, you only need to pass the name of the template without the extension, and BareUI will handle the rest!
@@ -118,15 +118,15 @@ This is an empty HTML page with a PHP tag that echoes a variable. On its own, th
118
118
To pass data to this `$name` variable, you can pass an array of data as the second argument to the `render()` method. This array should contain the same keys as the variables you want to use in the template.
119
119
120
120
```php
121
-
echo app()->bareui()->render('welcome', [
121
+
echo app()->template()->render('welcome', [
122
122
'name' => 'Something',
123
123
]);
124
124
```
125
125
126
126
This will render the template and replace the `$name` variable with the value `'Something'`. You can pass as many variables as you want to the template, and they will all be available in the template file. These values can be anything from strings to arrays, objects, or even functions.
127
127
128
128
```php [app.php]
129
-
echo app()->template->render('products', [
129
+
echo app()->template()->render('products', [
130
130
'items' => [
131
131
['name' => 'Item 1'],
132
132
['name' => 'Item 2'],
@@ -197,7 +197,7 @@ BareUI supports all the control structures you'd expect in a templating engine.
197
197
198
198
As you guessed, any valid PHP code can be used in BareUI templates. This means you can use any PHP function, class, or method in your templates. This makes BareUI a powerful templating engine that can handle any task you throw at it.
199
199
200
-
## Sub-templates
200
+
## Sub-templates/Partials
201
201
202
202
Sub-templates are templates that are included in other templates. This allows you to break your templates into smaller, more manageable pieces that can be reused across multiple templates. This is a great way to keep your templates DRY and avoid repeating yourself.
Copy file name to clipboardExpand all lines: src/docs/frontend/blade.md
+9-5Lines changed: 9 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,9 +25,13 @@ This video by The Net Ninja will help you get started with blade.
25
25
26
26
## Setting Up
27
27
28
-
Blade comes with Leaf MVC out of the box, fully configured and ready to use. However, if you're using Leaf Core, you'll need to set up Blade yourself. Don't worry, it's pretty easy. All you need to do is install Blade, configure it to match your project's setup, and you're good to go.
28
+
::: info Blade + Leaf MVC
29
29
30
-
You can install Leaf Blade with the Leaf CLI:
30
+
Blade comes with Leaf MVC out of the box, fully configured and ready to use. However, if you're using Leaf Core, you'll need to set up Blade yourself.
31
+
32
+
:::
33
+
34
+
You can install Leaf Blade using the Leaf CLI:
31
35
32
36
::: code-group
33
37
@@ -43,7 +47,7 @@ composer require leafs/blade
43
47
44
48
After this, you just need to inform Leaf of Blade's existence:
45
49
46
-
```php
50
+
```php:no-line-numbers
47
51
app()->attachView(Leaf\Blade::class);
48
52
```
49
53
@@ -87,7 +91,7 @@ This should look pretty familiar if you know HTML (of course you do). The only d
87
91
88
92
Remember we set up Blade earlier? Now we can use it to render our Blade views. Here's how you can render the `hello.blade.php` view we created earlier:
Copy file name to clipboardExpand all lines: src/docs/frontend/third-party.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,7 @@ composer require smarty/smarty
20
20
21
21
Once installed, you need to tell Leaf about your engine. Leaf will try to cache your engine for future use. You can do this using the `attachView()` method on the app instance:
22
22
23
-
```php
23
+
```php:no-line-numbers
24
24
app()->attachView(Smarty::class);
25
25
```
26
26
@@ -48,7 +48,7 @@ Unlike Leaf Core, Leaf MVC comes with a view manager that makes Leaf aware of an
48
48
49
49
The first step is to head over to your `public/index.php` file and attach Smarty to Leaf:
Copy file name to clipboardExpand all lines: src/docs/frontend/vite.md
+22-6Lines changed: 22 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -73,16 +73,32 @@ Once you've installed Vite, you can start loading your assets using the the `vit
73
73
74
74
Here's an example of how you can load a CSS file:
75
75
76
-
```php
76
+
::: code-group
77
+
78
+
```blade:no-line-numbers [Blade]
79
+
{{ vite('css/app.css') }}
80
+
```
81
+
82
+
```php:no-line-numbers [BareUI]
77
83
<?php echo vite('css/app.css'); ?>
78
84
```
79
85
86
+
:::
87
+
80
88
You can also load multiple assets at once by passing in an array of assets:
81
89
82
-
```php
90
+
::: code-group
91
+
92
+
```blade:no-line-numbers [Blade]
93
+
{{ vite(['app.css', 'app.js']) }}
94
+
```
95
+
96
+
```php:no-line-numbers [BareUI]
83
97
<?php echo vite(['app.css', 'app.js']); ?>
84
98
```
85
99
100
+
:::
101
+
86
102
The `vite()` helper function will automatically load the correct assets depending on the environment. In development, it will load the assets from the vite server with Hot Module Replacement, while in production, it will load the assets from the build folder.
87
103
88
104
## Vite Config
@@ -108,7 +124,7 @@ export default defineConfig({
108
124
109
125
The Leaf Vite plugin requires an array of entry points for your application. These may be JavaScript or CSS files, and include preprocessed languages such as TypeScript, JSX, and Sass. You don't need to pass all your assets here, just the entry points.
110
126
111
-
Besides the Vite config file, you can also configure the server component for Vite. With this, you can set a couple of defaults for your assets.
127
+
Besides the Vite config file, you can also configure the server component to set a few defaults for Vite. This is is only necessary if you are NOT using Leaf MVC. You can configure the server component by calling the `config` method on the `Vite` class:
112
128
113
129
```php
114
130
\Leaf\Vite::config([
@@ -119,11 +135,9 @@ Besides the Vite config file, you can also configure the server component for Vi
119
135
120
136
Unlike the `vite.config.js` file, this configuration is done in PHP and is completely optional.
121
137
122
-
Once again if you're using Leaf MVC or if you installed Vite using the `view:install` command, this is done for you automatically.
123
-
124
138
## Running Vite
125
139
126
-
Vite comes with a development server that you can use to serve your assets. This is true for the Leaf Vite integration as well. This is a bit different from the traditional way of serving assets with PHP because you need to run a separate server for your assets. You can start your Vite server by running:
140
+
Vite comes with a development server that you can use to serve your frontend assets. This is a bit different from the traditional way of serving assets with PHP because you need to run a separate server for your assets. You can start your Vite server by running:
127
141
128
142
::: code-group
129
143
@@ -147,6 +161,8 @@ yarn && yarn dev
147
161
148
162
This will install the necessary dependencies and start your Vite server. You don't need to do anything with the Vite server, just keep it running in the background and Leaf will take care of the rest.
149
163
164
+
**You need to keep the Vite server running in a separate terminal window while you work on your project.**
165
+
150
166
## Adding Aliases
151
167
152
168
Vite allows you to set up aliases for your assets. This can be done by adding an `alias` key to your vite config. For example, to set up an alias for the `@` symbol, you can do:
Copy file name to clipboardExpand all lines: src/docs/mvc/controllers.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -54,7 +54,7 @@ You can have as many methods as you want in your controller. Each method should
54
54
55
55
After defining a controller with the methods that you will use to handle your routes, you need to tell Leaf when to load a controller and which method to call. You can do this by defining a route in your `app/routes/` directory, and then calling the method in the controller that should handle the route. Here's an example:
56
56
57
-
```php
57
+
```php:no-line-numbers
58
58
app()->get('/users', 'UsersController@index');
59
59
```
60
60
@@ -83,7 +83,7 @@ You can find the views documentation [here](/docs/frontend/)
83
83
84
84
When you're building web apps, sometimes you need extra functionality when someone visits a route. For example, maybe only logged-in users should be able to see certain pages. To manage this, Leaf lets you add route parameters like middleware to your routes. This feature also works for controllers and uses the same syntax as function route handlers. Here's an example:
@@ -95,7 +95,7 @@ Leaf makes it super easy to set up routes for common actions like creating, read
95
95
96
96
To get started, you can generate a resource controller using the Aloe CLI:
97
97
98
-
```bash
98
+
```bash:no-line-numbers
99
99
php leaf g:controller photos --resource
100
100
```
101
101
@@ -146,7 +146,7 @@ class PhotosController extends Controller {
146
146
147
147
You can then define your routes like this:
148
148
149
-
```php
149
+
```php:no-line-numbers
150
150
app()->resource('/photos', 'PhotosController');
151
151
```
152
152
@@ -164,33 +164,33 @@ This will automatically set up all the routes you need for CRUD operations on th
164
164
165
165
API resource controllers are similar to resource controllers, but they return JSON responses instead of HTML which means that the `create` and `edit` methods are not included. You can generate an API resource controller using the Aloe CLI:
166
166
167
-
```bash
167
+
```bash:no-line-numbers
168
168
php leaf g:controller photos --api
169
169
```
170
170
171
171
You can load the controller in your routes like this:
Allow has a few more shortcuts you can incorporate into your controller generation:
180
180
181
-
```bash
181
+
```bash:no-line-numbers
182
182
php leaf g:controller <ControllerName> -m
183
183
```
184
184
185
185
This command will generate your controller together with a model that corresponds to the controller name. The model will be generated in the `app/models` directory.
186
186
187
-
```bash
187
+
```bash:no-line-numbers
188
188
php leaf g:controller <ControllerName> -t
189
189
```
190
190
191
191
The `-t` flag will generate a controller with a frontend template that corresponds to the controller name. The template will be generated in the `app/views` directory.
0 commit comments