PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, January 22, 2022

[FIXED] Add Dependency to Slim 3 Framework

 January 22, 2022     composer-php, php, slim     No comments   

Issue

I'm new using Slim 3 Framework. I want to add this dependency faisalman/simple-excel-php. I installed via Composer but I don't know how to use it in my Controller. Do I need to add it to the container?

This is my composer.json file:

"require": {
    "slim/slim": "^3.8",
    "slim/php-view": "^2.2",
    "slim/twig-view": "^2.2",
    "illuminate/database": "^5.4",
    "faisalman/simple-excel-php": "^0.3.15"
},
"autoload":{
    "psr-4":{
        "App\\":"app"
    }
}

My project Structure is

  1. App

    1.1. Controllers

  2. Bootstrap

    2.1 app.php (here i instanse my app)

  3. vendor

Solution

Having done a composer require faisalman/simple-excel-php, you now have the library installed in your application and available via autoload.

The next step is using it.

There is no direct need to integrate this library into the Slim DI container or worry about the bootstrap file. You can follow the example in the library's readme and instantiate directly:

use SimpleExcel\SimpleExcel

$excel = new SimpleExcel('CSV');
$excel->parser->loadFile('test.csv');

in whatever file makes the most sense for your project.



Answered By - Rob Allen
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing