CodeIgniter Forums

Full Version: including a script into controller: include 'script.php'; is it possible?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[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"?

El Forum

[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.

El Forum

[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?

El Forum

[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.

El Forum

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