Custom php script with global DB

Hey guys,

I found several threads with this but none of them was really helpful. Basicaly:

  • I have an entryPoint thats calling a file - lets say its first.php

  • then I want to call second.php from this first.php - but the second.php is obviously not part of the entryPoint registration - only the first.php is registered…

How can I call global DB from the second.php? I tried several things I found but none of them actually worked (require once etc - it seems I cant load those from a custom php file).

Please let me know I think I am doing something wrong here…

SuiteCRM uses a ton of files that aren’t registered as entry-points, that simply get **require*d by entry-points. The name entry-point says it all, it’s just where you start.

So I don’t think you should be getting any problems using second.php. Maybe it’s better if you just tell us what the error/difficulty is in second.php, It’s probably just some detail you’re missing.

Well the problem is that my entrypoint php (first.php) has ajax javascript and its supposed to call the “second.php”. What I did yesterday is that I registered second.php as another entryPoint and I used this:

<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
global $db;

Now when I call the file from first.php with its adress like this: /crm/custom/second.php then it always returns Not A Valid Entry Point.

When I call it like this: /index.php?entryPoint=second it returns status 302 Found and thats it. No response at all. So I am obviously missing something here :open_mouth:

Sorry to bother you with this :frowning:

Have a look at how it’s done for inline editing, for example:

include/InlineEditing/InlineEditing.php (a bunch of functions to call from the Controller)
include/InlineEditing/inlineEditing.js (client-side code doing the Ajax calls)
modules/Home/controller.php (the server-side processing of the Ajax calls)

I think that you’re missing is the controller aspect.

Hmmm…thanks gonna test it :wink:

I must say that I still don’t get it :frowning:

Are you using a debugger such as PhpStorm or Eclipse, with XDEBUG?

You can’t go very far without one…

Yeah I know… I am mostly a JS developer so PHP is a bit off for me… :frowning: For now I solved the whole thing in a different way. I only use one php file that is registered as entryPoint and in that file I have my php, html and ajax. And the ajax calls do not call another php file, it only calls a php function thats in this file so its all working.

Its OK for my current scripts but not sure what I am gonna do when it gets a bit bigger :smiley: