D
D
Dmitry Baskakov2018-09-29 10:22:38
PHP
Dmitry Baskakov, 2018-09-29 10:22:38

How to organize classes?

The site has pages:

  • Page 1
  • Page 2

In both, you need to get data from the database, but always in different ways. Those. methods will always be different and their generalization will create cumbersome code
. And here are 2 ideas:
  • Create mysql namespace and add classes there
  • Create namespace with page names and add mysql class

But both options look bad.
How it is possible to organize it with a minimum of connections to a DB and the minimum crutches?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Seva Shpun, 2018-09-29
@dmitrybascacov

Create a method, pass parameters to the argument of this method, or whatever you need for the page you need.
PS. To work with the database, I recommend using redbeanphp.com

A
Alexander Pushkarev, 2018-09-29
@AXP-dev

It's not very clear what the problem is. Use models for this

Code example
class PageController extends Controller
{
  public function news()
  {
    $news = News::where('active', 1)->first();

    return view('news', ['news' => $news]);
  }

  public function contacts()
  {
    $social = [/* ... */];
    
    return view('contacts', ['social' => $social]);
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question