Welcome Guest, Not a member yet? Register   Sign In
How to use a CI class in an existing php file
#1

[eluser]asciiCode[/eluser]
I am trying to integrate code igniter into my website.

I want to use a CI class that I made in a .php script that already exists.

Where do I put the CI class and how to I declare it?

I already tried to put the class directly in the .php script but it said the superclass could not be found.

That makes me think I should declare my class in the libraries folder. But if I do how do I declare that class in my php script?

Remember this script existed before I installed code igniter, so it isn't in the CI folder structure. Do I need to place in in the CI folder structure?

Thanks!
#2

[eluser]Nick_MyShuitings[/eluser]
I would vote for placing the php script within a CI controller. It will be much easier. Its also the way that I have integrated CI with existing applications. I've always tackled it from the code viewpoint of integrating the existing scripts INTO CI's structure MCV style.

That said, you can convert some CI classes into normal PHP classes if you want to take the time to do so, it involves a lot of find and replace, followed by a lot of debugging.
#3

[eluser]umefarooq[/eluser]
hi if you have own your php class, just put that class file in codigniter, application > library folder and call that library with in CI anywhere
Code:
$this->load->library('your_library');

to call in other libraries, and helpers

in helper
$ci = & get_instance();
$ci->load->library('your_library');

in other library
private $ci = '';

create in constructor
$this->ci = & get_instance();
$this->ci->load->library('your_library');
#4

[eluser]Nick_MyShuitings[/eluser]
@asciiCode - please reiterate your question, it seems that umefarooq and I understood it differently.

I read your question to say that you have a php script OUTSIDE of your CI instance that you want to be able to use your CI class.

umefarooq provided excellent guidance on how to add your own class to CI and use it WITHIN CI.
#5

[eluser]asciiCode[/eluser]
I decided to take my php script and incorporate it into the CI MVC convention. Thanks for the help.




Theme © iAndrew 2016 - Forum software by © MyBB