';
201 |
202 | return $html;
203 | }
204 |
205 | private function generateSearchForm() {
206 | if (!$this->searchForm) {
207 | return '';
208 | }
209 |
210 | return '';
214 | }
215 | }
216 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | This is free and unencumbered software released into the public domain.
2 |
3 | Anyone is free to copy, modify, publish, use, compile, sell, or
4 | distribute this software, either in source code form or as a compiled
5 | binary, for any purpose, commercial or non-commercial, and by any
6 | means.
7 |
8 | In jurisdictions that recognize copyright laws, the author or authors
9 | of this software dedicate any and all copyright interest in the
10 | software to the public domain. We make this dedication for the benefit
11 | of the public at large and to the detriment of our heirs and
12 | successors. We intend this dedication to be an overt act of
13 | relinquishment in perpetuity of all present and future rights to this
14 | software under copyright law.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 | OTHER DEALINGS IN THE SOFTWARE.
23 |
24 | For more information, please refer to
25 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Bootstrap 5 Navigation Menu Generator
2 |
3 | ## Table of Contents
4 | 1. [Introduction](#introduction)
5 | 2. [Features](#features)
6 | 3. [Requirements](#requirements)
7 | 4. [Installation](#installation)
8 | 5. [Usage](#usage)
9 | 6. [Configuration Options](#configuration-options)
10 | 7. [Examples](#examples)
11 | 8. [Customization](#customization)
12 | 9. [Contributing](#contributing)
13 | 10. [License](#license)
14 |
15 | ## Introduction
16 |
17 | The Bootstrap 5 Navigation Menu Generator is a PHP class that simplifies the process of creating dynamic, responsive navigation menus for websites using Bootstrap 5. It provides a flexible and easy-to-use interface for generating customizable navigation bars with support for dropdown menus, search forms, and active item highlighting.
18 |
19 | ## Features
20 |
21 | - Dynamic generation of Bootstrap 5 compatible navigation menus
22 | - Support for dropdown menus (multi-level)
23 | - Customizable brand/logo section
24 | - Light and dark theme options
25 | - Fixed positioning (top or bottom)
26 | - Responsive design with customizable breakpoints
27 | - Search form integration
28 | - Icon support (compatible with Bootstrap Icons or other icon libraries)
29 | - Dynamic active item highlighting based on current URL
30 | - Custom CSS class support for additional styling
31 |
32 | ## Requirements
33 |
34 | - PHP 7.0 or higher
35 | - Bootstrap 5 CSS and JS files
36 | - (Optional) Bootstrap Icons or another icon library for menu item icons
37 |
38 | ## Installation
39 |
40 | 1. Download the `BootstrapNavGenerator.php` file.
41 | 2. Place it in your project directory where you keep your PHP classes.
42 | 3. Include the file in your PHP script:
43 |
44 | ```php
45 | require_once 'path/to/BootstrapNavGenerator.php';
46 | ```
47 |
48 | ## Usage
49 |
50 | Here's a basic example of how to use the Bootstrap 5 Navigation Menu Generator:
51 |
52 | ```php
53 | setBrand('My Website', '/');
58 | $nav->addMenuItem('Home', '/');
59 | $nav->addMenuItem('About', '/about');
60 | $nav->addMenuItem('Services', '/services', [
61 | ['label' => 'Web Design', 'url' => '/services/web-design'],
62 | ['label' => 'SEO', 'url' => '/services/seo']
63 | ]);
64 | $nav->addMenuItem('Contact', '/contact');
65 |
66 | echo $nav->generateMenu();
67 | ?>
68 | ```
69 |
70 | ## Configuration Options
71 |
72 | ### Setting the Brand
73 | ```php
74 | $nav->setBrand('My Website', '/', 'path/to/logo.png');
75 | ```
76 |
77 | ### Changing the Theme
78 | ```php
79 | $nav->setTheme('dark'); // or 'light'
80 | ```
81 |
82 | ### Fixed Positioning
83 | ```php
84 | $nav->setFixed('top'); // or 'bottom'
85 | ```
86 |
87 | ### Container Type
88 | ```php
89 | $nav->setContainer('lg'); // 'fluid', 'sm', 'md', 'lg', 'xl', 'xxl'
90 | ```
91 |
92 | ### Expansion Breakpoint
93 | ```php
94 | $nav->setExpandPoint('md'); // 'sm', 'md', 'lg', 'xl', 'xxl'
95 | ```
96 |
97 | ### Adding a Search Form
98 | ```php
99 | $nav->addSearchForm('Search our site...');
100 | ```
101 |
102 | ### Adding Custom Classes
103 | ```php
104 | $nav->addCustomClass('my-custom-navbar');
105 | ```
106 |
107 | ## Examples
108 |
109 | ### Full Example with All Features
110 |
111 | ```php
112 | setBrand('My Website', '/', 'path/to/logo.png');
117 | $nav->setTheme('dark');
118 | $nav->setFixed('top');
119 | $nav->setContainer('lg');
120 | $nav->setExpandPoint('md');
121 | $nav->addMenuItem('Home', '/', [], 'bi bi-house');
122 | $nav->addMenuItem('About', '/about', [], 'bi bi-info-circle');
123 | $nav->addMenuItem('Services', '/services', [
124 | ['label' => 'Web Design', 'url' => '/services/web-design', 'icon' => 'bi bi-brush'],
125 | ['label' => 'SEO', 'url' => '/services/seo', 'icon' => 'bi bi-search']
126 | ], 'bi bi-gear');
127 | $nav->addMenuItem('Contact', '/contact', [], 'bi bi-envelope');
128 | $nav->addSearchForm('Search our site...');
129 | $nav->addCustomClass('custom-navbar');
130 |
131 | echo $nav->generateMenu();
132 | ?>
133 | ```
134 |
135 | ## Customization
136 |
137 | You can further customize the navigation menu by extending the `BootstrapNavGenerator` class or by modifying the existing methods to suit your specific needs.
138 |
139 | ## Contributing
140 |
141 | Contributions to improve the Bootstrap 5 Navigation Menu Generator are welcome. Here's how you can contribute:
142 |
143 | 1. **Reporting Issues**: If you find a bug or have a suggestion for improvement, please open an issue in the GitHub repository. Provide as much detail as possible, including steps to reproduce the issue if applicable.
144 |
145 | 2. **Submitting Pull Requests**: If you'd like to contribute code:
146 | - Fork the repository
147 | - Create a new branch for your feature or bug fix
148 | - Make your changes
149 | - Submit a pull request with a clear description of the changes
150 |
151 | 3. **Improving Documentation**: If you notice areas where the documentation could be improved or expanded, feel free to suggest changes.
152 |
153 | 4. **Sharing Ideas**: If you have ideas for new features or improvements, open an issue to discuss them.
154 |
155 | Before making significant changes, it's a good idea to open an issue to discuss the proposed changes with the maintainers.
156 |
157 | Please ensure that your contributions adhere to:
158 | - The existing code style
159 | - Best practices for PHP and Bootstrap 5
160 | - Proper documentation of new features or changes
161 |
162 | By contributing to this project, you acknowledge that your contributions will be released under The Unlicense, effectively placing them in the public domain.
163 |
164 | Thank you for helping to improve the Bootstrap 5 Navigation Menu Generator!
165 |
166 | ## License
167 |
168 | This project is licensed under The Unlicense - see the [UNLICENSE](UNLICENSE) file for details.
169 |
170 | This means that you are free to do whatever you want with this software. You can use it, modify it, distribute it, or sell it without any restrictions. The authors have released it into the public domain, dedicating all their rights to the work to the public domain worldwide.
171 |
172 | For more information about The Unlicense, visit [https://choosealicense.com/licenses/unlicense/](https://choosealicense.com/licenses/unlicense/).
173 |
174 | ---
175 |
176 | For more information or support, please open an issue in the GitHub repository.
177 |
--------------------------------------------------------------------------------