<?php
namespace App\Controllers;
class Account extends BaseController
{
public function index()
{
$data['title'] = 'Аккуант';
return view('account_header_menu, $data);
}
}
index.php
в папке public
в котором будут выводиться изображения: <?php
require __DIR__ . '/functions.php';
$images = getAllImages();
<?php
foreach ($images as $image) {
$imageLink = __DIR__ . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . $image ;
echo '<div><img src="' . $imageLink . '" alt="' . $image. '"></div>';
}
functions.php
в папке public
:/**
* Функция сканирования папки в поиске изображений
*
* @param string $directory
* @return array
*/
function getAllImages(string $directory = __DIR__ . '/images/'): array
{
$images = [];
$ignoreFiles = ['.', '..',];
$files = scandir($directory);
foreach ($files as $file) {
if (in_array($file, $ignoreFiles)) {
continue;
}
$images[] = $file;
}
return $images;
}
images
, которая находится в папке public
/**
* Функция загрузки шаблона
*
* @param string $template Путь до файлов шаблона
* @param mixed[] $data Данные для подстановки в шаблон
* @return string Возвращает готовый код шаблона
*/
function render_template($template, $data = []) {
ob_start();
if (file_exists($template)) {
extract($data);
require($template);
} else {
print('Нет файла шаблона: '.$template);
}
$html = ob_get_clean();
return $html;
}
require_once __DIR__ . '/functions.php';
$header = render_template('templates/header.php', ['title' => 'Главная страница']);
$footer= render_template('templates/footer.php');
$content = render_template('templates/content.php');
$page_layout = render_template('templates/layout.php',
['header' => $header, 'footer' => $footer, 'content' => $content]);
print($page_layout);
<head>
<title><?=$title?></title>
</head>
<!DOCTYPE html>
<html lang="ru">
<?=$header?>
<body>
<?=$content?>
<?=$footer?>
</body>
</html>
$login = filter_var(trim($_POST['login']), FILTER_SANITIZE_STRING);
$password = filter_var(trim($_POST['password']), FILTER_SANITIZE_STRING);
$mysql = new mysqli('localhost', 'root', 'root', 'reg-bd');
if ($mysql->connect_errno) {
exit('Ошибка при соединении с базой данных: ' . $mysql->connect_error);
}
$result = $mysql->query("SELECT * FROM `users` WHERE `login` = '$login' AND `password` = '$password'");
if (!$result)
{
exit('Ошибка при выполнении запроса: ', $mysql->error);
}
$user = $result->fetch_assoc();
setcookie('user', $user['name'], time() + 3600, "/");
//что бы проверить, что в переменно что то есть, можно вывести ее через: var_dump($user)
<?php
require_once 'connect.php';
$h = $_POST['smail'];
var_dump($_POST['smail']);
if (!mysqli_query($connect, "INSERT INTO `soobchenie` (`id`, `otpravit`, `nku`, `avu`, `nkchata`, `forma`, `time`, `prosmotr`) VALUES (NULL, '$h', 'g', 'l', 'l', 'l', 'l', 'l')") {
printf("Ошибка при добавлении в базу данных: %s\n", mysqli_error($connect));
}
?>
Как мне это сделать?
<?php
require_once 'MyString.php';
$mystr = new MyString();
echo $mystr->getString();
$mystr->setString('stop');
echo $mystr->getString();
<?php
class MyString
{
private $string;
public function __construct(string $str = ' start ')
{
session_start();
if (empty($_SESSION['string'])) {
$this->string = $str;
}
}
public function setString(string $str)
{
$this->string = $str;
$_SESSION['string'] = $this->string;
}
public function getString()
{
return $_SESSION['string'] ?? $this->string;
}
}
всё заработает и выведет "start stop", но если обновить страницу то будет тоже самое, а мне хотелось бы чтобы теперь выводило "stop stop"
в моей голове junior - это тот, кто пишет круды и что-то там допиливает в проектах
Я могу сделать какой-нибудь обычный crud с sql, но, видимо этого не достаточно.
Также у меня есть пару книг популярных по этому языку и там тоже нечего взять полезного.
<?php
error_reporting(E_ALL);
if (mail("mymail@gmail.com", "New User", " Name: ".$_POST['name']. "\n" . " Email: ".$_POST['email']. "\n" . "\r\n") {
header('Location: https://example.com/thanks/index.html');
exit();
} else {
die('Ошибка при отправке письма!');
}
мол xampp использовать для нормальной разработки себе дороже
//Создаём XML документ: начало
$date = date("d/M/y H:m:s");
$xml_content = '';
$site_url = 'https://'.$_SERVER['HTTP_HOST'];
$quantity_elements = 0;
$array_pages_uniq = array_unique($array_pages);
foreach($array_pages_uniq as $v)
{
$quantity_elements++;
$xml_content.='
<url>
<loc>'.$site_url.$v['URL'].'</loc>
</url>';
}
//Создаём XML документ: конец
/**
* Функция загрузки шаблона
*
* @param string $template Путь до файлов шаблона
* @param mixed[] $data Данные для подстановки в шаблон
* @return string Возвращает готовый код шаблона
*/
function render_template($template, $data) {
ob_start();
if (file_exists($template)) {
extract($data);
require($template);
} else {
print('Нет файла шаблона: '.$template);
}
$html = ob_get_clean();
return $html;
}
$content = render_template('templates/main.php', ['title' => 'Главная страница');
echo $content;
<html>
<head>
<title><?=$title?></title>
</head>
</html>
что не так?
//Сохраняем файл с помощью PHPExcel_IOFactory и указываем тип Excel
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2016');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>AJAX Send</title>
</head>
<body>
<button id="btn_yes">Btn_yes</button>
<button id="btn_no">Btn_no</button>
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script src="main.js"></script>
</body>
</html>
//"file.php" - Это тот файл на который будем отправлять AJAX запрос
$("#btn_yes").on('click', function() {
$.post("file.php", { btn_yes: "btn_yes"})
.done(function( data ) {
alert( "Сообщение: " + data );
});
});
$("#btn_no").on('click', function() {
$.post("file.php", { btn_no: "btn_no"})
.done(function( data ) {
alert( "Сообщение: " + data );
});
});
if( isset( $_POST['btn_yes'] )) {
echo 'Отправлена кнопка btn_yes';
}
if( isset( $_POST['btn_no'] )) {
echo 'Отправлена кнопка btn_no';
}