Welcome Guest, Not a member yet? Register   Sign In
including a script into controller: include 'script.php'; is it possible?
#1

[eluser]Dariusz-Gdynia[/eluser]
I need to include some code (some functions) into controller. It's not used every time so there is no need to have it all the time.

Example:

Code:
function abc ($z){
if ($z==1)
    include 'somescript.php';
}

My questions are:
Where can I put my 'somescript.php' and what path should I give in "include"?
Is there something similar to "include"?
#2

[eluser]GSV Sleeper Service[/eluser]
you can put somescript.php anywhere in your php include path (see phpinfo() for details) - or you can just specify the full path in your include statement. eg include('/foo/bar/somescript.php')

'include_once', 'require' and 'require_once' are similar to include. 'require' will raise a fatal error if the file is not found, 'include' will just raise a warning.
#3

[eluser]KeyStroke[/eluser]
Why don't you just put that script's code in a function or a class (as a library) and start calling it whenever you need it?
#4

[eluser]Dariusz-Gdynia[/eluser]
GSV Sleeper Service: very thanks, but should I give the path from where my index.php is?

i.e.
include 'system/application/includes/somescript.php' ?

KeyStroke: The reason is that I have already written the code and i just want to use cut->paste; it is much easier.
#5

[eluser]xwero[/eluser]
you can use the APPPATH constant to limit your typing




Theme © iAndrew 2016 - Forum software by © MyBB