[Phpslash-devel] Story: listStory() design question
Brought to you by:
joestewart,
nhruby
From: Lars H. <he...@qu...> - 2001-12-13 17:54:31
|
Hi, I'd like to kill the functions "Author::authorSelect", "Topic::topicSelect" and "Section::sectionSelect" and make the select-boxes from "storylist.tpl" template-driven. 1st I thought, I create a function Author::getAllAuthors() which delivers an author_array and I walk through this array in the function Story::listStory(), but then I walk twice through an array (first the db array and then through the author_array. Then I saw, that the objects author, topic and section are only created for building the select boxes. I thought it may be nice to create three functions listAuthor, listTopic, listSection in the class Story which may look like this: --- function listAuthor($author_id) { $q = "SELECT author_id, author_name FROM psl_author ORDER BY author_name"; $this->db->query($q); $this->template->set_block("liststory", "each_author", "authors"); // First entry: All $this->template->set_var(array( "AUTHOR_ID" => "", "AUTHOR_NAME" => "All", "SELECTED" => "" )); $this->template->parse("authors", "each_author", "true"); while ($this->db->next_record()) { $this->template->set_var(array( "AUTHOR_ID" => $this->db->f("author_id"), "AUTHOR_NAME" => $this->db->f("author_name"), "SELECTED" => "" )); if ($this->db->f("author_id") == $author_id) { $this->template->set_var(array( "SELECTED" => "selected=\"selected\"" ); } $this->template->parse("authors", "each_author", "true"); } } --- But it blows up the Story.class. What do you think? Regards, Lars |