### Implement Reusable Search Endpoint with SearchAction - PHP
Source: https://context7.com/ethercap/yii2-ledap/llms.txt
This PHP code defines a 'search' action within a Yii2 controller using the `ethercap\ledap\actions\SearchAction`. It allows for configurable search functionality with options for filtering by ID, keyword search, custom query processing, defining output data format, and enabling result caching. The example shows how to use it for searching users.
```php
[
'class' => 'ethercap\ledap\actions\SearchAction',
'searchModel' => [
'class' => 'ethercap\ledap\models\SearchModel',
'idName' => 'user_id', // Query parameter name for ID filtering
'keyName' => 'search_term', // Query parameter name for keyword search
],
'processQuery' => function($searchModel) {
$query = User::find();
// Apply ID filter if provided
if (!empty($searchModel->id)) {
$query->andWhere(['id' => $searchModel->id]);
}
// Apply keyword search if provided
if (!empty($searchModel->keyword)) {
$query->andWhere(['like', 'username', $searchModel->keyword]);
}
return $query;
},
'dataConfig' => ['id', 'text' => 'username'], // Output format: id and text fields
'enableCache' => true, // Enable result caching
'cacheTime' => 300, // Cache for 5 minutes
],
];
}
}
// Usage: GET /user/search?search_term=john&user_id[]=1&user_id[]=2
// Returns: {"code":0,"data":[{"id":1,"text":"john_doe"},{"id":2,"text":"john_smith"}]}
```
--------------------------------
### Register AppAsset for Yii2 Application Initialization
Source: https://context7.com/ethercap/yii2-ledap/llms.txt
Registers the main application asset bundle, AppAsset, which loads the ledap-init.js configuration file and sets up the request handling framework. It also loads Bootstrap themes and Font Awesome icons. This bundle configures a global request handler with error handling, theme settings, WebDataProvider, and CSRF token handling.
```php
{
// Success callback - result.code === 0
this.$alert("Saved successfully!");
this.loadList();
}, (error) => {
// Error callback - result.code !== 0
this.$alert(error.message);
});
}
}
});
```
--------------------------------
### LedapAsset: Load Core Vue.js and Ledap Framework Bundle in Yii2
Source: https://context7.com/ethercap/yii2-ledap/llms.txt
Asset bundle that loads the Ledap framework library, which bridges Yii2 and Vue.js. It registers Vue.js and the Ledap JavaScript library, enabling the use of Vue components and data handling within Yii2 applications.
```php
[
'class' => 'ethercap\ledap\actions\SearchAction',
'searchModel' => [
'class' => 'ethercap\ledap\models\SearchModel',
'idName' => 'user_id', // Query parameter name for ID filtering
'keyName' => 'search_term', // Query parameter name for keyword search
],
'processQuery' => function($searchModel) {
$query = User::find();
// Apply ID filter if provided
if (!empty($searchModel->id)) {
$query->andWhere(['id' => $searchModel->id]);
}
// Apply keyword search if provided
if (!empty($searchModel->keyword)) {
$query->andWhere(['like', 'username', $searchModel->keyword]);
}
return $query;
},
'dataConfig' => ['id', 'text' => 'username'], // Output format: id and text fields
'enableCache' => true, // Enable result caching
'cacheTime' => 300, // Cache for 5 minutes
],
];
}
}
```
```
--------------------------------
### JsHelper: Register JavaScript Files by Route in Yii2
Source: https://context7.com/ethercap/yii2-ledap/llms.txt
Helper for automatically registering JavaScript files based on the current controller route with cache busting. It ensures that the correct JavaScript files are loaded for specific views and handles versioning using file modification timestamps.
```php
[\ethercap\ledap\assets\LedapAsset::class],
]);
// Automatically registers: /js/post/index.js?v=1702714020 (with file modification timestamp)
// Custom configuration
JsHelper::register($this, [
'url' => 'custom/path', // Custom route instead of current controller route
'base' => '/static/js', // Custom base path (default: /js)
'depends' => [
\ethercap\ledap\assets\LedapAsset::class,
\yii\web\JqueryAsset::class,
],
], 'unique-key');
// For a controller at admin/user/index:
JsHelper::register($this);
// Looks for: @webroot/js/admin/user/index.js
// Registers: @web/js/admin/user/index.js?v=timestamp
// Only registers if the JavaScript file exists at the expected path
```
--------------------------------
### Register UploadAsset for Yii2 File Uploads
Source: https://context7.com/ethercap/yii2-ledap/llms.txt
Registers the UploadAsset bundle for handling file uploads with Vue components. It provides an upload-file component that can be configured with an upload URL, maximum file size, and accepted file types. The component supports success and error event handlers for managing upload feedback and updates the bound model with the uploaded file's URL.
```php
```
--------------------------------
### Register ColorPickerAsset for Yii2 Color Selection
Source: https://context7.com/ethercap/yii2-ledap/llms.txt
Registers the ColorPickerAsset bundle for color selection functionality in forms. This allows users to select colors using a color picker component, which can be bound to a Vue data property. The selected color can then be used for styling elements, as demonstrated with a background color preview.
```php
Preview: {{ brandColor }}
```
--------------------------------
### Register BootstrapVue Asset Bundle for Yii2
Source: https://context7.com/ethercap/yii2-ledap/llms.txt
Registers the BootstrapVue asset bundle to integrate Bootstrap 4 components as Vue.js components. It loads Bootstrap 4 CSS, Vue.js, and Bootstrap-Vue JS/CSS from a CDN. This enables the use of components like b-card, b-form, b-table, and b-pagination in Vue templates.
```php
Submit
Edit
Delete
```
--------------------------------
### Gii Generator Registration
Source: https://context7.com/ethercap/yii2-ledap/llms.txt
This section explains how yii2-ledap integrates with Yii2's Gii module to provide custom code generators for Vue.js-based CRUD interfaces.
```APIDOC
## Bootstrap Integration and Gii Generator Registration
### Description
The Bootstrap class automatically registers custom Gii generators when the Gii module is available, enabling code generation for Vue-based CRUD interfaces.
### Configuration Example
```php
['ledap'],
'modules' => [
'gii' => [
'class' => 'yii\gii\Module',
// After bootstrap, ledapCrud and ledapAjaxCrud generators are automatically available
],
],
];
```
### Available Generators
- **ledapCrud**: Standard Vue+Bootstrap CRUD generator.
- **ledapAjaxCrud**: AJAX-based Vue+Bootstrap CRUD generator.
### Access
Access Gii at: `http://yourapp.com/gii`
Select "Ledap Crud Generator" or "Ledap Ajax Crud Generator" from the generator list.
```
--------------------------------
### Register DatePickerAsset for Yii2 Date Selection
Source: https://context7.com/ethercap/yii2-ledap/llms.txt
Registers the DatePickerAsset bundle for date selection functionality in forms. It enables the use of a date-picker component for single date selection or date range selection. The component supports custom date formats and can be integrated into Vue templates.
```php
```
--------------------------------
### SearchModel: Handle Standardized Search Parameters in Yii2
Source: https://context7.com/ethercap/yii2-ledap/llms.txt
A base model for handling search requests with ID and keyword filtering, designed for select2-style components. It extends Yii2's SearchModel to provide common search functionalities and allows for custom rules and query modifications.
```php
search(Yii::$app->request->queryParams, function($model) {
$query = Product::find();
if (!empty($model->id)) {
$query->andWhere(['id' => $model->id]);
}
if (!empty($model->keyword)) {
$query->andWhere(['like', 'name', $model->keyword]);
}
if (!empty($model->category)) {
$query->andWhere(['category' => $model->category]);
}
if (isset($model->price_min)) {
$query->andWhere(['>=', 'price', $model->price_min]);
}
if (isset($model->price_max)) {
$query->andWhere(['<=', 'price', $model->price_max]);
}
return $query;
});
return $this->renderApi('search', ['dataProvider' => $dataProvider]);
}
```
--------------------------------
### Register Gii Generators with Bootstrap - PHP
Source: https://context7.com/ethercap/yii2-ledap/llms.txt
This snippet demonstrates how to configure your Yii2 application to automatically register custom Gii generators provided by the yii2-ledap extension. Ensure the 'ledap' bootstrap component is listed in your application's configuration. This makes 'Ledap Crud Generator' and 'Ledap Ajax Crud Generator' available in the Gii module.
```php
['ledap'],
'modules' => [
'gii' => [
'class' => 'yii\gii\Module',
// After bootstrap, ledapCrud and ledapAjaxCrud generators are automatically available
],
],
];
// The Bootstrap class registers two generators:
// 1. ledapCrud - Standard Vue+Bootstrap CRUD generator
// 2. ledapAjaxCrud - AJAX-based Vue+Bootstrap CRUD generator
// Access at: http://yourapp.com/gii
// Select "Ledap Crud Generator" from the generator list
```
--------------------------------
### Generator: Custom Gii CRUD for Vue.js Interfaces in Yii2
Source: https://context7.com/ethercap/yii2-ledap/llms.txt
Extends Yii2's built-in CRUD generator to create Vue.js-based interfaces with automatic JavaScript file generation. This allows for rapid development of RESTful APIs and corresponding Vue frontends.
```php
'app\models\Post',
'controllerClass' => 'app\controllers\PostController',
'baseControllerClass' => '\\ethercap\\apiBase\\Controller',
'viewPath' => '@app/views/post',
'jsPath' => '@app/web/js', // JavaScript files location
'moduleId' => 'admin', // Optional module ID
'searchModelClass' => 'app\models\PostSearch',
]);
// Generated files structure:
// controllers/PostController.php - Controller with CRUD actions
// views/post/index.php - Vue-based list view
// views/post/view.php - Vue-based detail/form view
// views/post/index.api - API response template for list
// views/post/view.api - API response template for detail
// web/js/admin/post/index.js - Vue app for list page
// web/js/admin/post/view.js - Vue app for detail/form page
// The generator automatically:
// - Creates REST-style CRUD operations
// - Generates Vue components with Bootstrap UI
// - Sets up data providers and search models
// - Configures routing with optional module support
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.