Giter Site home page Giter Site logo

ciasie_lebonsandwich's Introduction

Micro-framework SLIM

Erreurs fréquentes

Ecriture de corps de requête

function ( $rq, Response $rs, $args) {
	$rs = $rs->withStatus(201);
	$rs->getBody()->write(json_encode($o)) ;
	return $rs ;  
}

⚠️ Le flag retourné par $rs->getBody()->write() est en fait un flag qui dit si l'écriture s'est bien passée.

Comment reproduire l'erreur :

/* Retourne donc true ou false au lieu du résultat de l'écriture du body comme on s'y attendrait */

function ( $rq, Response $rs, $args) {
	$rs = $rs->withStatus(201) ;
	$rs = $rs->getBody()->write(json_encode($o)) ;
	return $rs ; 
}

Aucun message d'erreur retourné

Il faut définir displayErrorDetails à true (false par défaut) dans un fichier config ou en début de main. On doit la définir à false en mode développement.

$configuration = [
    'settings' => ['displayErrorDetails' => true,
	'dbconf' => '/conf/db.conf.ini' ]];

$c = new \Slim\Container($configuration);
$app = new \Slim\App($c);

// récupérer le conteneur :
$container = $app->getContainer();
$prod = $container['settings']['displayErrorDetails'] ; 

Accéder au container

On peut accéder au container dans les routes via $this, ce n'est pas possible en dehors :

$configuration = [
	'settings' => [
		'displayErrorDetails' => true, // Mettre à false pour déployer l'api en mode production
		'dbconf' => function ($c) {
			return parse_ini_file(__DIR__ . '/../src/app/conf/commande.db.conf.ini');
		}
	]
];

$c = new \Slim\Container($configuration);
$app = new \Slim\App($c);

$this["settings"]["dbconf"] // RIEN IMPOSSIBLE

$app->get(
	'/commandes/',
	function (Request $req, Response $resp, $args): Response {
		$this // container
		$ctrl = new TD1CommandController($this);
		return $ctrl->listCommands($req, $resp, $args);
	}
);

Appel de fonctions dans le container de dépendances

Le container de dépendances appelle les fonctions au moment où on demande la clé associée.

⚠️ Les fonctions dans la config du container qui sont en deuxième niveau ne sont pas éxecutées !

$configuration = [
	'settings' => [
		'displayErrorDetails' => true, // Mettre à false pour déployer l'api en mode production
		/* Pas Appelée
		'dbconf' => function ($c) {
		return parse_ini_file(__DIR__ . '/../src/app/conf/commande.db.conf.ini');
		}
		*/
	],
	/* Appelée
		'dbconf' => function ($c) {
		return parse_ini_file(__DIR__ . '/../src/app/conf/commande.db.conf.ini');
		}
	*/
];

$db = new Illuminate\Database\Capsule\Manager();
$db->addConnection($c->dbconf); /* configuration avec nos paramètres */
[...]
```# CIASIE_LeBonSandwich

ciasie_lebonsandwich's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.