Your commit message
This commit is contained in:
parent
f9bc85d5f8
commit
88a90e3aa3
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MyProject\Controllers;
|
||||
|
||||
use MyProject\Models\ExampleModel;
|
||||
|
||||
class ExampleController
|
||||
{
|
||||
private ExampleModel $model;
|
||||
|
||||
public function __construct(ExampleModel $model)
|
||||
{
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
public function index(): void
|
||||
{
|
||||
$data = $this->model->getData();
|
||||
$this->render('views/example_view.php', ['data' => $data]);
|
||||
}
|
||||
|
||||
public function show(int $id): void
|
||||
{
|
||||
$item = $this->model->find($id);
|
||||
|
||||
if ($item === null) {
|
||||
$this->notFound();
|
||||
return;
|
||||
}
|
||||
|
||||
$this->render('views/item_view.php', ['item' => $item]);
|
||||
}
|
||||
|
||||
private function render(string $viewPath, array $data): void
|
||||
{
|
||||
extract($data);
|
||||
include $viewPath;
|
||||
}
|
||||
|
||||
private function notFound(): void
|
||||
{
|
||||
http_response_code(404);
|
||||
include 'views/404.php';
|
||||
}
|
||||
}
|
|
@ -1,50 +1,44 @@
|
|||
// src/index.js
|
||||
// Importing React (necessary if using JSX)
|
||||
import React from "react";
|
||||
|
||||
// Example function to add two numbers
|
||||
function add(a, b) {
|
||||
return a + b
|
||||
// Example function using a regular function declaration
|
||||
function multiply(x, y) {
|
||||
return x * y;
|
||||
}
|
||||
|
||||
// Example usage of the add function
|
||||
|
||||
const result = add(5, 10)
|
||||
console.log('The result is:', result)
|
||||
|
||||
// Example object with properties
|
||||
const person = {
|
||||
name: 'John Doe',
|
||||
age: 30,
|
||||
greet: function () {
|
||||
console.log(
|
||||
`Hello, my name is ${this.name} and I am ${this.age} years old.`
|
||||
)
|
||||
},
|
||||
}
|
||||
|
||||
// Call the greet method
|
||||
person.greet()
|
||||
|
||||
// Example of an arrow function
|
||||
const multiply = (x, y) => x * y
|
||||
|
||||
console.log('The product is:', multiply(4, 5))
|
||||
// Example usage of a function
|
||||
let result = multiply(4, 5);
|
||||
console.log("The product is:", result); // Output: The product is: 20
|
||||
|
||||
// Example of a variable declared with let
|
||||
let count = 0
|
||||
let count = 0;
|
||||
for (let i = 0; i < 5; i++) {
|
||||
count += i
|
||||
}
|
||||
console.log('The count is:', count)
|
||||
|
||||
// Example of a variable declared with const
|
||||
const message = 'This is a constant message.'
|
||||
console.log(message)
|
||||
|
||||
// Example of a function with default parameters
|
||||
function greet(name = 'Guest') {
|
||||
console.log(`Welcome, ${name}!`)
|
||||
count += i;
|
||||
}
|
||||
|
||||
// Call the function with and without arguments
|
||||
greet('Alice')
|
||||
greet()
|
||||
console.log("The count is:", count); // Output: The count is: 10
|
||||
|
||||
// Example of a variable declared with let (instead of const)
|
||||
let message = "This is a message";
|
||||
console.log(message);
|
||||
|
||||
// Example of a React functional component
|
||||
function Greeting({ name }) {
|
||||
return (
|
||||
<div>
|
||||
<h1>Hello, {name}!</h1>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// Usage of the Greeting component
|
||||
function App() {
|
||||
return (
|
||||
<div>
|
||||
<Greeting name="Alice" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// Export the App component for usage in other parts of the application
|
||||
export default App;
|
||||
|
|
Loading…
Reference in New Issue