Hi all,
As my demo project start growing, I have to start thinking in reuse the same code I need in several different places. In standard PHP we move this code to libraries/classes and "include" them.
I guess here we have to use nuProcedure and/or nuRunProcedure.
I see nuProcedure returns the code as string to eval it, and nuRunProcedure executes directly this procedure.
Would like to know the "nuStandard" way to reuse code and "send params/receive data" from this code inside procs (returns? hash cookies?). There are ways to put several functions and reuse from one procedure? Main advantages/disavantadges between nuProc and nuRunProc? It's better to use a procedure for each function? What suggestions are about all of this?
Thanks.
Welcome to the nuBuilder Forums!
Join our community by registering and logging in.
As a member, you'll get access to exclusive forums, resources, and content available only to registered users.
Join our community by registering and logging in.
As a member, you'll get access to exclusive forums, resources, and content available only to registered users.
Tips for PHP code reutilization? Topic is solved
-
- nuBuilder Team
- Posts: 4562
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 76 times
- Been thanked: 528 times
- Contact:
Re: Tips for PHP code reutilization?
Hi,
I have a set of PHP functions that I use across multiple forms, which are stored in an external PHP file.
To organise these, you can create e.g. a ‘libs’ folder in the nuBuilder root directory and place your PHP file(s) in this folder.
In nuconfig.php, search for the setting "$nuConfigIncludePHP" and include them like:
Example of external php file: mylib1.php:
I have a set of PHP functions that I use across multiple forms, which are stored in an external PHP file.
To organise these, you can create e.g. a ‘libs’ folder in the nuBuilder root directory and place your PHP file(s) in this folder.
In nuconfig.php, search for the setting "$nuConfigIncludePHP" and include them like:
Code: Select all
$nuConfigIncludePHP = ['../libs/mylib1.php','../libs/mylib1.php'];
Code: Select all
<?php
function myfunction($param) {
// do something here
}
-
- nuBuilder Team
- Posts: 4562
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 76 times
- Been thanked: 528 times
- Contact:
Re: Tips for PHP code reutilization?
Oh, of course, you are right.
nuRunQuery can be run there in that functions too I guess? or what include we must do?
Thanks.
nuRunQuery can be run there in that functions too I guess? or what include we must do?
Thanks.
-
- nuBuilder Team
- Posts: 4562
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 76 times
- Been thanked: 528 times
- Contact:
Re: Tips for PHP code reutilization?
Yes, nuRunQuery() can be used directly, there's no need to include the nu-core files again.