Welcome Guest, Not a member yet? Register   Sign In
object of a class... not as a ci library
#1

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

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

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

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

[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();
#5

[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!
#6

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




Theme © iAndrew 2016 - Forum software by © MyBB