Welcome Guest, Not a member yet? Register   Sign In
Which is better? (add->news or news->add)
#1

[eluser]Vi.[/eluser]
I want to ask for advice about PHP application coding pipeline.
I noticed that "add->news" is better but not sure. There are three main action to control content. (add, delete, update)

Which is better for mid-sized project (e-commerce, dating site, commercial site)?

Code:
$this->Main->add("news");
$this->Main->update("news");
or
Code:
$this->News->add();
$this->News->update();
or
Code:
$this->Add->news();
$this->Update->news();
#2

[eluser]überfuzz[/eluser]
Are we talking models? I'd go with the news.php model and add some nice methods; add, edit, etc in that model. Then you'd load it $this->load->model('news'); and use it $this->news->add();

I often go with the what/action approach. If I have methods that are exactly the same for different stuff like news home etc. I sometimes use slightly more dynamic models/methods. $this->load->model('edit'); $this->edit->news(9); and in the model I then have a function to parse whatever needs to be parsed, news, home, etc.

I guess the best way for you is to sit down and a minute or two and see what you need and then see if you come up with a nice structure.
#3

[eluser]Vi.[/eluser]
Thanks for reply and suggestion.
Best way is using all of them with right combination as you do.
#4

[eluser]jedd[/eluser]
Class (noun)
Method (verb)
#5

[eluser]BrianDHall[/eluser]
$this->News->add(); and $this->News->update();, as what is being added or updated often makes a big difference on how you have to handle things. If you end up with News, Comments, Users, Articles, Messages, and more - that would be one hell of a big Main->add() or Add() class. And as adding and updating are often closely related, it can cause a lot of code replication to have an Add() class and an Update() class.

Much better to encapsulate the class/noun, as jedd suggests, and its related functions (methods/verbs). This meshes with MVC and OOP best practices, and doing it any other way will violate everyone else's expectations of how things should be coded, if you should ever want someone else to help with your code or sell your application.
#6

[eluser]Sbioko[/eluser]
The best is variant #2.
#7

[eluser]Thorpe Obazee[/eluser]
[quote author="jedd" date="1257957625"]Class (noun)
Method (verb)[/quote]
+1




Theme © iAndrew 2016 - Forum software by © MyBB