CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> Tips & Solutions

 PHP Namespaces

Print topic Send  topic

Author Message
DataDoIT
Posted: 10/14/2016, 5:50 PM Quote message

When working with namespaces in PHP and CCS, you need to define your use
declarations in the global scope. You'll find use of namespaces often
when working with various API's or SDK's (QuickBooks Online SDK for PHP
for example).

So let's say you want to do something based on an event on a control in
CodeCharge, such as OnValidate for a record form, and you want to use an
external API call that requires namespace constructs. Since the
OnValidate event is in a function within the *_events.php file, you need
to define your 'use' outside of that function's scope, or the parent
scope. Do that at the very top of the *_events.php file you're working
on. Here's a sample of what it'll look like:

<?php
require_once(RelativePath . "/includes/Twilio/autoload.php");
use Twilio\Rest\Client;

//BindEvents Method @1-1034CD09
function BindEvents()
{
global $TestForm;
$TestForm->CCSEvents["OnValidate"] = "TestForm_OnValidate";
}
....

The first two lines are the ones we just inserted, the rest is normal,
CCS generated (greyed out) code that you never want to alter.

From there, you can now work with your custom code in the OnValidate
event (or whatever event you've chosen), such as:

//Custom Code @8-2A29BDB7
// -------------------------

$client = new Client($sid, $token);
....

You can read more about PHP namespaces here:
http://php.net/manual/en/language.namespaces.rationale.php

You'll encounter them a lot in PHP 5.3+ supported API's.

Add new topic Reply to topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

PHP Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright 2003-2004 by UltraApps.com  and YesSoftware, Inc.