1

Hi I have a doubt about how to call a function which is defined in normal core php file. Now i want to call this function in controller of Codeigniter application.

What i mean is for example there is a function named with getdetails() in test.php in some directory. Now there is a codeIgniter application which has controller email.php.

Now i want to call getdetails() function in email.php.

Can anyone help me with some ideas.

4
  • Is this not pretty much exactly the same question you asked here: stackoverflow.com/questions/tagged/codeigniter ? Commented Nov 7, 2012 at 17:19
  • If it is procedural, easy way is make it a helper file. Didn't you create a library earlier? Commented Nov 7, 2012 at 17:19
  • No actually i tried in that but that works fine in normal but the function i need to use contains code which works on zend framework. That i can't load in the codeigniter..... Commented Nov 7, 2012 at 17:27
  • Rewrite it, you're going to cause yourself all kinds of grief trying to include code from one framework inside another. Commented Nov 7, 2012 at 18:25

2 Answers 2

4

Build your own helper, save this as test_helper.php in your application helpers folder:

function getdetails($paramater1, $parameter2){
    echo "test";
}

Then load it within your controller:

$this->load->helper('test');

And you can use it as this everywhere it's loaded:

getdetails();
Sign up to request clarification or add additional context in comments.

3 Comments

I can't write again function totally. I had already a pre built function on server which wrote on zend framework. Now i wanna call that function in my codeIgniter controller........
There is no magic, these are different frameworks. You might need to translate it once unfortunately. Try to include Zend functions functions in this helper only so you cna use the function maybe? But I'm pretty sure it would mess everything.
well if you'll still be hosting the zend framework somewhere you could always use a file_get_contents to some page in the zend framework that exclusively will run that function for you....but thats real shady. You should probably just study what the function does and re-write it.
-2

You merely need to include the file before attempting to call the function. include or include_once

2 Comments

with just include you can't access it try once with small example.......you will see whats the problem
codeIgniters helper is a good approach and very simple to have own custom functions. its unnecessary to mix things with include/include_once

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.