You are here: Re: Recursion(?) in My Class « PHP Programming Language « IT news, forums, messages
Re: Recursion(?) in My Class

Posted by burgermeister01@gmail.com on 09/20/07 14:15

On Sep 18, 8:06 am, Sanders Kaufman <bu...@kaufman.net> wrote:
> NoDude wrote:
> > Why would you create a new publication in the edit method? Can't you
> > have a separate method that's called addPublication? You may know not
> > to call EditPublication (at least untill some time hass passed and you
> > forget), but imagine my (or any person's) surprise when I one day take
> > over this application, use this class and edit is actually used for
> > create.
>
> That wasn't real, live code.
> It was just a representation of a concept.
> The actual code file is a couple of hundred lines long.
>
> But the reason why I think I need a new Publication object is because
> it's a web page that lets you edit other web pages. Thus the current
> object isn't the one you're editing, but rather the one you're viewing.
>
> I (think I) want to create a new instance of the publication object,
> because I'm editing a whole different publication.
>
> I think this is called MVC - Model View Controller, but I don't know why.

Sanders,

I'm admittedly a bit confused by your question, so I'm not sure if
what I'm about to say will help you at all, but here goes.

Firstly, I concur with NoDude that it is a bit misleading to have an
instantiation of a class in an edit method. I'm assuming these
publications that you speak of are being coordinated with a database,
and therefore I think good solution to your problem may be a design
pattern known as Active records. Check it out: http://en.wikipedia.org/wiki/Active_record
A way that I implement this concept in PHP all the time is like this:
put a parameter in your class constructor called $id and have it
default to NULL like so

funciton Publication($id = NULL)

You will then want to pull a record from the DB or instantiate a new
class based on the value of $id. So when you go to your edit page,
just pass in the appropriate parameter to the constructor, make any
edits that need to happen to class members ($title, $article) and when
you're done, call the SavePublication() method. Of course you can now
remove the $id parameter from your SavePublication() signature because
that value has already been stored in the class.

Anyways, I hope I'm not rambling on about some concept you already
know, and furthermore I hope this concept can help you with your
problem.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация