CodeIgniter Forums
object of a class... not as a ci library - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: object of a class... not as a ci library (/showthread.php?tid=17029)



object of a class... not as a ci library - El Forum - 03-23-2009

[eluser]Fenix[/eluser]
I am in the process of converting an old project to use PHP objects.

So far this is what my basic class structure looks like:
Code:
class BookSearch
{
     function BookSearch($isbn_search)
     {
          $attribute = 'example';
     }
}

I want to be able to do the following:
Code:
$mybook = new BookSearch(9780596529963);
echo $mybook->attribute; // outputs 'example'

I tried loading the class as a library but that isn't how it should have to work. Can I just include it somehow and create objects like above?


object of a class... not as a ci library - El Forum - 03-23-2009

[eluser]i_like_ponies[/eluser]
Try it like this:

Code:
class BookSearch
{
     var $attribute;
     function BookSearch($isbn_search)
     {
          $this->attribute = 'example';
     }
}



object of a class... not as a ci library - El Forum - 03-24-2009

[eluser]jedd[/eluser]
Hi Fenix. I was looking to create my models as 'real' objects recently - there's a [url="http://ellislab.com/forums/viewthread/108763/"]forum thread on the subject[/url].

I could see the possible benefits of doing this for a model, but hadn't considered it for a controller - what kind of approach are you going to take, can I ask?


object of a class... not as a ci library - El Forum - 03-24-2009

[eluser]Fenix[/eluser]
I go this working last night before I got the last two replies. This approach will make the process much easier to handle. I will be able to do multiple book searches at a time and I will only process exactly what I want. Previously, a book search always returned prices from other stores which took a considerable amount of processing. Now I can have a function do that for me only if needed like so:

Code:
$mybook = new BookSearch(9780596529963); // great book by the way :)
$online_offers = $mybook->stores_array();



object of a class... not as a ci library - El Forum - 07-13-2009

[eluser]Keyur Shah[/eluser]
Hello Fenix,

can you let us know where you ended up placing your class files and how you called it in.

Thanks!


object of a class... not as a ci library - El Forum - 07-13-2009

[eluser]Fenix[/eluser]
if i remember correctly, i just put them in the library folder and included them with include()