Defining a section's name when calling it outside the CMSB

5 posts by 2 authors in: Forums > CMS Builder
Last Post: September 17, 2019   (RSS)


Whenever I call for section within the CMSB I just insert the section name, correct?

For example, if  I want to count the number of record of a section (i.e. "section_name") I run the following script:

echo mysql_count('section_name');

But, what if I want to call the same script outside the CMSB?  Should I define the section's name using the root directory? For example,


Kind regards,

Andreas Lazaris

Hi Andreas,

mysql_count() is a custom function defined within CMSB, so it can't exactly be used "outside" of CMSB. only be used when the viewer library has been loaded on the page. The viewer library is generated by the Code Generator and generally looks something like this:

  // load viewer library
  $libraryPath = 'cmsb/lib/viewer_functions.php';
  $dirsToCheck = ['','../','../../','../../../','../../../../'];
  foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

Are you able to include the viewer library for the script you're writing? If yes, then you can just use the function as normal. If not, you may need to find another way to recreate the functionality - which I also may be able to help with.

Let me know any questions!


Technical Lead

Hi Andreas,

Thanks for sharing the additional info. I think the issue should be fixable - I'll also try to break down how some of these pieces fit together to give you a better understanding of what's going on.

Firstly, the CMSB code is loaded via the viewer library using the code snippet I included in my last reply. In order to use any CMSB-defined functions (such as mysql_count()) this needs to be present at the top of the file and loading correctly. If the loader is present but the script is not working overall, that indicates a directory issue, as you've suspected.

The loader will do its best to try to find the CMSB app folder by trying some different locations, but this does have some limitations. Primarily, it will only look "up" through a directory path, relative to the PHP file. So for example, if you have CMSB installed to "/public_html/registry/cmsb/" the default loader will work for files in "/public_html/registry/" or "/public_html/registry/subfolder/", etc., but not in "/public_html/" or "/public_html/subfolder/".

It is still possible to load the viewer library in alternate paths, but it does require some small modification to the loader. Given the above example, if we wanted to load it in files outside of "/public_html/registry/" then we'd want to change the first line of the loader from this:

  $libraryPath = 'cmsb/lib/viewer_functions.php';

To this:

  $libraryPath = 'registry/cmsb/lib/viewer_functions.php';

Now, there are a lot of small things that could differ for your specific installation, but I hope the above can get you pointed in the right direction. Though if you find you're still having trouble, feel free to send a 2nd-Level Support Ticket ( and I can have a look directly.


Technical Lead

Hi Daniel

Thank you very much. I think I got it. I changed the library path and it seems that it works!!

Thanks again for your assistance. Five stars on support!!!

Kind regards.