i want to build a simple news manager based on a flat file.
Structure of the file: id|title|short text|long text
(At this time, without login)
I want to seperate the logic of adding, deleting and modifiying
news items from the page that contains the form.
For instance, i would have newsadmin.php that contains the
logic of displaying a form to add stuff, modify or delete
and news.php which contains a class that reads the file and
places everyting in an array.
For starters, you would go to newsadmin.php.
This calls a constructor of class News specified in news.php.
Then a function ListNewsItems would be called from news.php
to show all items and make links after the items like this:
<add>
1. title 1 <modify> <delete>
2. title 2 <modify> <delete>
3. title 3 <modify> <delete>
After clicking <delete> of item 1, i would like to show
the full newsitem in the same form as you would use to
add a news item so a person can view it before deleting.
If would do this by setting the link like this:
newsadmin.php?action=delete&newsid=1
newsadmin.php would check for $action and according to
the value do the correct things. in this case,
a form with all the fields would be shown and a delete button.
This is the first problem i encounter:
i need to do 2 things here after a user clicks delete, call the function
DeleteItem from news.php and afterwards go back to newsadmin.
I would prefer not to use the name newsadmin.php in the
news.php file so all stuff stays seperated (if that is possible)
Second problem: since i have
<? php
include "news.php";
$news = new $news = new News;
?>
at the top of newsadmin.php, the whole flatfile would be read
again every time.
I believe there must be more efficient ways of doing this.
Any simple pointers on how one best makes such a simple
admin center would be welcome.
Thanks!