PHP MVC Config class as dependency or with just class constants, accessible from overall?

In my MVC project (PHP 7.1) I have a Config class and a multitude of config files, each of them looking like this:

return [
    'web' => [
        'host' => 'localhost',

At the app entry point I make an instance of the Config class and load all config file arrays in it. The created object is then passed as constructor argument in all classes that needs it:

class AbstractView {

    private $config;

    public function __construct(Config $config) {
        $this->config = $config;

    private function prepareContext() {
        $this->assign('appHost', $this->getConfig()->get('web/host'));


Because it’s quite a “big effort” to pass the Config object quite overall in my app, I thought of implementing aConfig` class with only class constants in it, like:

class Config {

    const WEB_PROTOCOL = 'http';
    const WEB_HOST = 'localhost';


and access them from overall directly with

class AbstractView {

    private function prepareContext() {
        $this->assign('appHost', Config::WEB_HOST);


I wanted to ask: Is this a really good alternative, having in mind that I want to completely avoid static states in my app? Is this alternative a “static” one or absolute not? What about testability (I don’t have any experience with it yet)?

Thank you very much.

Source: stackoverflow-php

php MVC share function across all views

I’m just getting in to using Mini3 MVC framework but am struggling with the concept of where to code a function that is to be used by ALL views.
Mini3 is here btw:

I have a function called auto_version that creates a name for css files based on the modified date/time, so I can call it by <?php echo auto_version('css/style.css');?>

I need to call this on every view, so to me, the place to call the function is in application/view/_templates/header.php.

Where is the best place to code the function though?
Does it go in the Helper class in application/libs/helper.php or elsewhere?

Is it good practice to call a function from a view like this or am I breaking MVC rules?

If I have to call my function in every view controller (e.g. in application/Controller/HomeController.php and SongsController.php), it’s a lot of code replication which doesn’t sit right with me.

Any constructive advice greatfully received!


Source: stackoverflow-php

Laravel controller with modal bootstrap

I use Laravel Framework 5.4 and i need pass parameters from one button that open one Modal that receiving this parameters in myController and return data to myModal, somebody help me?


This button open my searchmodal.blade.php with jquery, it’s Right my href to call myController?

<a href="{{url('myController@search')}}" class="btn btn-success btnsearch">Search</a> 



myController need this parameters and return variables to get in Modal.


public function search(parameter1){

  $customers = Customer::find(parameter1);

  //return my modal or page1?
   return view('searchmodal', compact('customers'));

mymodal.blade.php, how do i get the customers variable from myController?

Source: stackoverflow-php

Notice: Array to string conversion when call method dynamically from array value


include_once "system/libs/Main.php";
include_once "system/libs/FController.php";

$url = $_GET['url'];
$url = rtrim($url,'/');
$url =explode("/", $url);


$ctlr = new $url[0]();


If echo from array index it is ok.
and when I call method directly it also ok.

but when I call method dinamically from array index value it says:
“Notice: Array to string conversion”.

Source: stackoverflow-php

Laravel – only a zero is saved to the database

I have a simple car model with one attribute:


namespace App;

use IlluminateDatabaseEloquentModel;
use IlluminateFilesystemFilesystem;

*   TODO:
*   Property Fotos ausf├╝llen

class Car extends Model
    protected $table = 'cars';

    protected $fillable = ['title'];

    public $timestamps = false;

    *   @var string
    protected $title = NULL;

    *   @var integer
    protected $imagesId = NULL;

    *   @return string
    public function getTitle()
        return $this->attributes['title'];

    *   @param string $title
    *   @return void
    public function setTitle($title)
        $this->attributes['title'] = $title;


This is my store function from the controller:

 * Store a newly created resource in storage.
 * @param  IlluminateHttpRequest  $request
 * @return IlluminateHttpResponse
public function store(Request $request)
    $car = new Car();

    // $car->setTitle($request->title);


However, this is how the entry in the database looks like:

enter image description here

Title is always zero! I also tried it with other models, same.

Source: stackoverflow-php