Witam, mam problem z autoloadingiem i namespace'ami.
Poniżej kod:
* index.php
<?php http://www.php.net/session_start(); require 'vendor/autoload.php'; use View\Template\First\Template; use Shop\User; use Shop\SessionsAndCookies; $template = new Template; $template -> siteStart(); $user = new User; $sac = new SessionsAndCookies; http://www.php.net/echo' Zalogowany? '. $user -> isLogged(); http://www.php.net/echo'<br><br>'; http://www.php.net/print $_SESSION['logged']; http://www.php.net/print $_SESSION['email']; http://www.php.net/print'<br>'; http://www.php.net/print $sac -> getSession('logged'); http://www.php.net/print $sac -> getSession('email'); $product = new Product; $category = new Categories; $category -> set('name', 'Main', 1); $template -> siteEnd();
{ "autoload": { "psr-4": { "Shop\\": "class", "View\\": "view" } } }
<?php namespace View\Template\First; class Template { private $title; private $footer; public function __construct($TypeOfView = null) { $this -> title = 'Shop'; $this -> footer = ''; $this -> logotype = ''; $this -> view = $TypeOfView; } public function menu() { $db = new Database; $db -> query('SELECT * FROM categories WHERE visibility = 1 ORDER BY name ASC'); $result = $db -> fetchAll(); return $result; } public function siteStart() { http://www.php.net/echo' <!DOCTYPE html> <html> <html lang="pl-PL"> <head> <meta charset="utf-8"> <meta name="description" content="..."> <meta name="keywords" content="..."> <link rel="stylesheet" href="View/Template/First/css/style.css"> <title>'.$this -> title.'</title> <!-- [if lt IE 9]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"> <![endif--> </head> <body> <header> <section class="logo"> Nazwa strony </section> <section class="basket"> Koszyk: ( x ) </section> <nav> <ul> <li><a href="Index/">Strona główna</a></li> <li><a href="">O nas</a></li> <li><a href="">Pomoc</a></li> <li><a href="">Kontakt</a></li> </nav> </header> <aside> <ul class="menu">'; if($this -> view == 'Admin') { $directory = 'Class/Admin/'; $files = http://www.php.net/array_diff(scandir($directory), http://www.php.net/array('..', '.')); foreach($files as $file) { http://www.php.net/echo '<a href="admin?action='.http://www.php.net/trim($file,'.php').'"">'.http://www.php.net/trim($file, '.php').'</a></br>'; } } else { $menu = $this->menu(); foreach ($menu as $r) { http://www.php.net/echo'<li><a href="Products?category='.$r['name'].'">'.$r['name'].'</a></li>'; } } http://www.php.net/echo' </ul> '; if(http://www.php.net/isset($_SESSION['logged']) && $_SESSION['logged'] == true && !http://www.php.net/empty($_COOKIE['logged'])) { http://www.php.net/echo'<br>panel<br><br><a href="Admin/">Panel admina</a><Br> <a href="User?action=logout">Wyloguj</a><br>'; } else { http://www.php.net/echo'<br> <a href="User/">Zaloguj się</a><br> <a href="User?action=register">Zarejestruj się</a><br> '; } http://www.php.net/echo' </aside> <main> '; } public function siteEnd() { http://www.php.net/echo' </main> <footer> '.$this -> footer.' </footer> </body> </html> '; } } ?>
Mało napisałeś o tej klasie Database ale być może wystarczy \Database.
Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)