Welcome Guest, Not a member yet? Register   Sign In
$psr4 Namespace Paths
#3

(This post was last modified: 02-24-2020, 11:32 AM by captain-sensible.)

i've also been playing with namespace to use things like PHPmailer and my own classes. All i an tell you is what works for me.

So this is my dev structure in a directory called CI located at : /var/www/htdocs

bash-5.0$ tree -f -L 1
.
├── ./CODE_OF_CONDUCT.md
├── ./CONTRIBUTING.md
├── ./DCO.txt
├── ./PHPMailer
├── ./PULL_REQUEST_TEMPLATE.md
├── ./README.md
├── ./Vagrantfile.dist
├── ./admin
├── ./app
├── ./composer.json
├── ./composer.lock
├── ./contributing
├── ./env
├── ./fontawesome
├── ./forms
├── ./gulpfile.js
├── ./license.txt
├── ./node_modules
├── ./package-lock.json
├── ./package.json
├── ./phpunit.xml.dist
├── ./public
├── ./scss
├── ./spark
├── ./stale.yml
├── ./system
├── ./tests
├── ./user_guide_src
└── ./writable


to put it simply PHPMailer is at same level of app

the name space of PHPMailer classes including Exception, SMTP , POP is:
namespace PHPMailer\PHPMailer;

to use PHPMailer from a controller i listed it in app/config/autoload $psrf = [
section as:

'PHPMailer\\PHPMailer'=> ROOTPATH.'PHPMailer/src'

then in a controller called sendmail i used:
Code:
<?php namespace App\Controllers;

use CodeIgniter\Controller;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\OAuth;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\SMTP;

then further down :

$mail = new PHPMailer();
$mail->isSMTP();
$mail->Timeout = 20;
$mail->SMTPDebug = 0;
$mail->Host = 'smtp.gmail.com';

/etc
it successfully sent me an email from a form that submits to controller via POST


so as insiteFX just said everything under app uses ,APP namespace but if you follow my approach you will see that I put PHPMailer outside app and it definitely takes notice .
Reply


Messages In This Thread
$psr4 Namespace Paths - by Gary - 02-24-2020, 05:57 AM
RE: $psr4 Namespace Paths - by InsiteFX - 02-24-2020, 08:55 AM
RE: $psr4 Namespace Paths - by captain-sensible - 02-24-2020, 11:15 AM
RE: $psr4 Namespace Paths - by Gary - 04-13-2020, 12:11 PM



Theme © iAndrew 2016 - Forum software by © MyBB