1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ /**
6+ * Example usage of Ease\TWB4\Panel class
7+ * This demonstrates how to properly use the Panel class from php-ease-twbootstrap4
8+ * and helps fix "Class CardHeader not found" errors in other projects.
9+ */
10+
11+ require_once __DIR__ . '/vendor/autoload.php ' ;
12+
13+ use Ease \TWB4 \Panel ;
14+ use Ease \Html \H3Tag ;
15+ use Ease \Html \PTag ;
16+ use Ease \Html \ATag ;
17+ use Ease \Html \ButtonTag ;
18+
19+ echo "<!DOCTYPE html> \n<html> \n<head> \n" ;
20+ echo "<title>Panel Usage Examples</title> \n" ;
21+ echo "<link href='https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css' rel='stylesheet'> \n" ;
22+ echo "</head> \n<body class='container mt-4'> \n" ;
23+
24+ // Example 1: Basic Panel with header, body and footer
25+ echo "<h2>Example 1: Basic Panel</h2> \n" ;
26+ $ basicPanel = new Panel (
27+ 'Basic Panel Header ' , // heading
28+ 'primary ' , // type (success|warning|info|danger|primary)
29+ 'This is the panel body content. ' , // body
30+ 'Panel footer text ' // footer
31+ );
32+ echo $ basicPanel ->draw ();
33+
34+ echo "<hr class='my-4'> \n" ;
35+
36+ // Example 2: Panel with HTML content
37+ echo "<h2>Example 2: Panel with HTML Content</h2> \n" ;
38+ $ htmlPanel = new Panel ();
39+ $ htmlPanel ->header ->addItem (new H3Tag ('HTML Content Panel ' ));
40+ $ htmlPanel ->body ->addItem (new PTag ('This panel contains HTML elements. ' ));
41+ $ htmlPanel ->body ->addItem (new ATag ('# ' , 'This is a link ' , ['class ' => 'btn btn-info ' ]));
42+ $ htmlPanel ->footer ->addItem (new ButtonTag ('Action Button ' , ['class ' => 'btn btn-success ' ]));
43+ echo $ htmlPanel ->draw ();
44+
45+ echo "<hr class='my-4'> \n" ;
46+
47+ // Example 3: Panel with different types/colors
48+ echo "<h2>Example 3: Different Panel Types</h2> \n" ;
49+
50+ $ types = ['success ' , 'warning ' , 'info ' , 'danger ' ];
51+ foreach ($ types as $ type ) {
52+ $ panel = new Panel (
53+ ucfirst ($ type ) . ' Panel ' ,
54+ $ type ,
55+ "This is a $ type panel with appropriate Bootstrap coloring. " ,
56+ "Footer for $ type panel "
57+ );
58+ echo $ panel ->draw ();
59+ echo "<br> \n" ;
60+ }
61+
62+ echo "<hr class='my-4'> \n" ;
63+
64+ // Example 4: Panel without footer
65+ echo "<h2>Example 4: Panel Without Footer</h2> \n" ;
66+ $ noFooterPanel = new Panel (
67+ 'Panel Without Footer ' ,
68+ 'secondary ' ,
69+ 'This panel has no footer section. ' ,
70+ null // null footer means no footer will be displayed
71+ );
72+ echo $ noFooterPanel ->draw ();
73+
74+ echo "<hr class='my-4'> \n" ;
75+
76+ // Example 5: Adding items programmatically
77+ echo "<h2>Example 5: Adding Items Programmatically</h2> \n" ;
78+ $ programmaticPanel = new Panel ('Dynamic Panel ' );
79+
80+ // Add items to the body
81+ $ programmaticPanel ->addItem (new PTag ('First paragraph added programmatically. ' ));
82+ $ programmaticPanel ->addItem (new PTag ('Second paragraph with different content. ' ));
83+ $ programmaticPanel ->addItem ('<p>You can also add raw HTML strings.</p> ' );
84+
85+ // You can also add to header and footer directly
86+ $ programmaticPanel ->footer ->addItem (new PTag ('Footer added after construction. ' , ['class ' => 'text-muted ' ]));
87+
88+ echo $ programmaticPanel ->draw ();
89+
90+ echo "<hr class='my-4'> \n" ;
91+
92+ // Example 6: Empty panel that gets content conditionally
93+ echo "<h2>Example 6: Conditional Content Panel</h2> \n" ;
94+ $ conditionalPanel = new Panel ('Conditional Content ' );
95+
96+ $ hasData = true ; // This would come from your application logic
97+
98+ if ($ hasData ) {
99+ $ conditionalPanel ->addItem ('<div class="alert alert-success">Data is available!</div> ' );
100+ $ conditionalPanel ->addItem ('<p>Here is your data content...</p> ' );
101+ } else {
102+ $ conditionalPanel ->addItem ('<div class="alert alert-info">No data available.</div> ' );
103+ }
104+
105+ echo $ conditionalPanel ->draw ();
106+
107+ echo "\n</body> \n</html> " ;
108+
109+ /**
110+ * NOTES FOR FIXING "CardHeader not found" ERROR:
111+ *
112+ * 1. The Panel class does NOT use a separate CardHeader class
113+ * 2. Instead, it uses DivTag with 'card-header' CSS class
114+ * 3. Make sure you have the correct namespace: use Ease\TWB4\Panel;
115+ * 4. Ensure composer autoloader is properly loaded
116+ * 5. The Panel extends Card, which extends DivTag
117+ *
118+ * Common fixes:
119+ * - Check if you're trying to use \Ease\TWB4\CardHeader (which doesn't exist)
120+ * - Use \Ease\TWB4\Panel instead
121+ * - If you need just a card header, use: new \Ease\Html\DivTag($content, ['class' => 'card-header'])
122+ *
123+ * Proper usage pattern:
124+ * $panel = new \Ease\TWB4\Panel('Header Text', 'type', 'Body Content', 'Footer');
125+ * $panel->header->addItem('Additional header content');
126+ * $panel->body->addItem('Additional body content');
127+ * $panel->footer->addItem('Additional footer content');
128+ * echo $panel->draw();
129+ */
0 commit comments