Better way to do things

Hello PHPHelp,

I am a PHP developer, I have developed few applications and CMS for last one year. My question is which method is better to have different pages to add, edit, delete and listing content or have all of them in one single pages. For example we have tiny CMS application that only manages the news section, so on the administration part which will be better method;

  1. Create one page for listings records newslistings.php, another page to add records add_news.php, another page to edit record edit_news.php and a final page to delete them delete_news.php. in my sense it will make the code very simple less use of ‘if else statement’ the server will take less time to execute.

OR

  1. Put all the Listings record, add, edit and delete in one single page news.php; in that case the code will be complected, lots of ‘if else’ statement as I need to check which functions is need to be called; I guess for the server it will take a lot of time to execute the code.

I used both this way but I am confused which one is the better way to use.

Thanks a lot
Zakiur

Hi,

According to me the best way would be method 2. To avoid the overload on server due to if else, what you can do is GET the action (add, update, delete) from the url and create different functions for them (function add, function delete, function update) and call them directly based on what action you’re getting from url.

As mentioned above use the $_GET function when the page loads:

[php]
If (isset($_GET[‘page’])) { $Page = $_GET[‘page’]; } Else { $Page = ‘index’; }
$File = ‘./{$Page}.php’
If (!file_exists($File)) { $Page = ‘index’; }

Include($File);
[/php]

Hi,

I got it, Thanks a lot :slight_smile: .

HI,

Thanks a lot, Its very helpful. Thanks :slight_smile: .

Sponsor our Newsletter | Privacy Policy | Terms of Service