registration.php から SignupクラスをTwigを使って読み込もうとしているのですが、上手くいきません。
フォルダの階層
●registration.phpの階層
/var/www/html/Portfolio/public_html/registration_form.php
●SignupがあるSignup.phpの階層
/var/www/html/Portfolio/lib/Controller/Signup.php
エラー内容
Fatal error: Uncaught Error: Class 'MyApp\Controller\Signup' not found in /var/www/html/Portfolio/public_html/registration_form.php:7 Stack trace: #0 {main} thrown in /var/www/html/Portfolio/public_html/registration_form.php on line 7
registration.php
php
1<?php 2 3require_once('../config/config.php'); 4// Composerで作成されたautoload.phpを読み込む 5require_once('../vendor/autoload.php'); 6 7$app = new MyApp\Controller\Signup(); 8 9$app->run(); 10 11 12 13 14 15 16// 17// Twig 18// 19 20 21 22// Twig_Loader_Filesystem と Twig instance の生成を読み込む 23require_once('../config/twig.php'); 24 25 26 27// render 28echo $twig->render('registration_form.html', array( 29 30 'name' => $name, 31 'email' => $email, 32 'password' => $password, 33 'tel' => $tel, 34 'prefectures' => $prefectures, 35 'hobby' => $hobby, 36 'gender' => $gender, 37 'contact' => $contact, 38 'check_result' => $check_result 39 40 41 ) 42); 43
Signup.php
php
1<?php 2 3namespace MyApp\Controller; 4 5class Signup extends \MyApp\Controller { 6 7 public function run() { 8 9 if ($this->isLoggedIn()) { 10 11 header('Location:' . SITE_URL . '/login_users.php'); 12 exit; 13 14 } 15 16 if ($_SERVER['REQUEST_METHOD'] === 'POST') { 17 18 $this->postProcess(); 19 20 } 21 } 22 23 24 protected function postProcess() { 25 26 // Eメールのvalidate 27 try { 28 29 $this->_validate(); 30 31 } catch(\MyApp\Exception\InvalidEmail $e) { 32 33 $this->setErrors('email', $e->getMessage()); 34 35 } catch(\MyApp\Exception\InvalidPassword $e) { 36 37 $this->setErrors('password', $e->getMessage()); 38 39 } 40 41 $this->setValues('email', $_POST['email']); 42 $this->setValues('password', $_POST['password']); 43 44 45 if ($this->hasError()) { 46 47 return; 48 49 } 50 } 51 52 53} 54
/var/www/html/Portfolio/composer.json
{ "name": "twig/twig", "type": "library", "description": "Twig, the flexible, fast, and secure template language for PHP", "keywords": ["templating"], "homepage": "http://twig.sensiolabs.org", "license": "BSD-3-Clause", "authors": [ { "name": "Fabien Potencier", "email": "fabien@symfony.com", "homepage": "http://fabien.potencier.org", "role": "Lead Developer" }, { "name": "Twig Team", "homepage": "http://twig.sensiolabs.org/contributors", "role": "Contributors" }, { "name": "Armin Ronacher", "email": "armin.ronacher@active-4.com", "role": "Project Founder" } ], "support": { "forum": "https://groups.google.com/forum/#!forum/twig-users" }, "require": { "php": ">=5.3.3" }, "require-dev": { "symfony/phpunit-bridge": "~3.3@dev", "symfony/debug": "~2.7", "psr/container": "^1.0" }, "autoload": { "psr-0" : { "Twig_" : "lib/" }, "psr-4" : { "MyApp\" : "lib/", "MyApp\Controller\" : "lib/Controller/" } }, "extra": { "branch-alias": { "dev-master": "1.35-dev" } } }
lib/Controller.php (コントローラーの共通の処理)
<?php namespace MyApp; class Controller { }
どのように解決をしたらよろしいでしょうか?
ご教授いただけると嬉しいです。
回答1件
あなたの回答
tips
プレビュー