Welcome Guest, Not a member yet? Register   Sign In
Using Vendor Libraries Best Practices
#1

I have tried searching for an existing answer but I have not found one. Feel free to point me to any previously answers I missed. Also, if this belongs somewhere else please let me know and I will move it.
I am trying to use packages located in the "vendor" folder; at the same level as the "app" folder in the directory tree. So far as I can tell these should be autoloaded when the program starts but I cannot access them.
My controller (LoadController) is designed to send data from a web app into Hubspot CRM; at the head I am using the following:
Code:
<?php namespace App\Controllers;

use App\Controllers\BaseController;
use App\Models\Contacts;
use App\Models\ContactXref;
use App\Models\MainModel;
use App\Models\Tickets;

use HubSpot\Factory;
...
        $simplePublicObjectInput = new HubSpot\Client\Crm\Tickets\Model\SimplePublicObjectInput([
89             'properties' => $input_properties
90         ]);
when I run the program I get the following error message:

Quote:"Class 'App\Controllers\HubSpot\Client\Crm\Tickets\Model\SimplePublicObjectInput' not found"

Is there something I am missing, or am I just not understanding how to use these packages? I feel as if there is something fundamental I am missing, or the site itself is mis-configured.

Mostly I think I am just doing something dumb.
Reply
#2

You just don't understand PHP's namespaces.

Not
 $simplePublicObjectInput = new HubSpot\Client\Crm\Tickets\Model\SimplePublicObjectInput([
But
 $simplePublicObjectInput = new \HubSpot\Client\Crm\Tickets\Model\SimplePublicObjectInput([

You wrote `HubSpot\Client\Crm\Tickets\Model\SimplePublicObjectInput` in the namespace `App\Controllers`. So it is interpreted as App\Controllers\HubSpot\Client\Crm\Tickets\Model\SimplePublicObjectInput.
Reply
#3

I have been working with PHP namespaces since they were introduced in 2009; pretty sure I have a handle on them.

Thanks for the extra set of eyes though, I completely missed the leading backslash.

As I said, just a dumb mistake on my part.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB