Variable dans les classes php
Résolu
matdev
Messages postés
26
Date d'inscription
Statut
Membre
Dernière intervention
-
matdev Messages postés 26 Date d'inscription Statut Membre Dernière intervention -
matdev Messages postés 26 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
je rencontre actuellement un petit problème pour définir une variable étant un tableau contenant différentes valeur à utiliser en fonction d'un paramètre dans une classe php.
J'ai bien défini ma classe j'accède correctement à mes fonctions par contre j'utilise pour ces fonctions un paramètre me permettant de savoir la période sur laquelle ma fonction doit se concentrer.
Par rapport au paramètre passé à la fonction, je fais référence à un tableau pour compléter mes requetes sql.
Voici le tableau
Comment faire pour ne pas avoir à définir mon tableau dans chaque fonction mais de manière générale à ma classe php
J'ai essayé ceci mais je récupère null dans mon affichage de page.
Merci pour votre aide
je rencontre actuellement un petit problème pour définir une variable étant un tableau contenant différentes valeur à utiliser en fonction d'un paramètre dans une classe php.
J'ai bien défini ma classe j'accède correctement à mes fonctions par contre j'utilise pour ces fonctions un paramètre me permettant de savoir la période sur laquelle ma fonction doit se concentrer.
Par rapport au paramètre passé à la fonction, je fais référence à un tableau pour compléter mes requetes sql.
Voici le tableau
$where=array( "J"=>" and created=now()", "J-1"=>" and created=subdate(now(),INTERVAL 1 DAY)", "S"=>" and week(created)=week(now()) and year(created)=year(now())", "S-1"=>" and week(created)=week(subdate(now(),INTERVAL 1 WEEK)) and year(created)=year(subdate(now(),INTERVAL 1 WEEK))", "M"=>" and month(created)=month(now()) and year(created)=year(now())", "M-1"=>" and month(created)=month(subdate(now(),INTERVAL 1 MONTH)) and year(created)=year(subdate(now(),INTERVAL 1 MONTH))", "M-2"=>" and month(created)=month(subdate(now(),INTERVAL 2 MONTH)) and year(created)=year(subdate(now(),INTERVAL 2 MONTH))", "T"=>" and quarter(created)=quarter(now()) and year(created)=year(now())", "T-1"=>" and quarter(created)=quarter(subdate(now(),INTERVAL 1 QUARTER)) and year(created)=year(subdate(now(),INTERVAL 1 QUARTER))", "T-2"=>" and quarter(created)=quarter(subdate(now(),INTERVAL 2 QUARTER)) and year(created)=year(subdate(now(),INTERVAL 2 QUARTER))", "T-3"=>" and quarter(created)=quarter(subdate(now(),INTERVAL 3 QUARTER)) and year(created)=year(subdate(now(),INTERVAL 3 QUARTER))", "A"=>" and year(created)=year(now())", "A-1"=>" and year(created)=year(subdate(now(),INTERVAL 1 YEAR))", "A-2"=>" and year(created)=year(subdate(now(),INTERVAL 2 YEAR))" );
Comment faire pour ne pas avoir à définir mon tableau dans chaque fonction mais de manière générale à ma classe php
J'ai essayé ceci mais je récupère null dans mon affichage de page.
<?php class MyLib_Util { var $where=array( "J"=>" and created=now()", "J-1"=>" and created=subdate(now(),INTERVAL 1 DAY)", "S"=>" and week(created)=week(now()) and year(created)=year(now())", "S-1"=>" and week(created)=week(subdate(now(),INTERVAL 1 WEEK)) and year(created)=year(subdate(now(),INTERVAL 1 WEEK))", "M"=>" and month(created)=month(now()) and year(created)=year(now())", "M-1"=>" and month(created)=month(subdate(now(),INTERVAL 1 MONTH)) and year(created)=year(subdate(now(),INTERVAL 1 MONTH))", "M-2"=>" and month(created)=month(subdate(now(),INTERVAL 2 MONTH)) and year(created)=year(subdate(now(),INTERVAL 2 MONTH))", "T"=>" and quarter(created)=quarter(now()) and year(created)=year(now())", "T-1"=>" and quarter(created)=quarter(subdate(now(),INTERVAL 1 QUARTER)) and year(created)=year(subdate(now(),INTERVAL 1 QUARTER))", "T-2"=>" and quarter(created)=quarter(subdate(now(),INTERVAL 2 QUARTER)) and year(created)=year(subdate(now(),INTERVAL 2 QUARTER))", "T-3"=>" and quarter(created)=quarter(subdate(now(),INTERVAL 3 QUARTER)) and year(created)=year(subdate(now(),INTERVAL 3 QUARTER))", "A"=>" and year(created)=year(now())", "A-1"=>" and year(created)=year(subdate(now(),INTERVAL 1 YEAR))", "A-2"=>" and year(created)=year(subdate(now(),INTERVAL 2 YEAR))" ); public function comptaentres($type){ Zend_Debug::dump($this->where[$type]); }
Merci pour votre aide
A voir également:
- Variable dans les classes php
- Easy php - Télécharger - Divers Web & Internet
- Expert php pinterest - Télécharger - Langages
- Php alert ✓ - Forum PHP
- Ouvrez cette page. dans le code de la page, modifiez la couleur de fond de la classe .pix. un code de 4 chiffres doit apparaître dans la grille. lequel ? ✓ - Forum Programmation
- Variable d'environnement temp - Forum Word
1 réponse
class MyLib_Util { private static $where=array( "J"=>" and created=now()", "J-1"=>" and created=subdate(now(),INTERVAL 1 DAY)", "S"=>" and week(created)=week(now()) and year(created)=year(now())", "S-1"=>" and week(created)=week(subdate(now(),INTERVAL 1 WEEK)) and year(created)=year(subdate(now(),INTERVAL 1 WEEK))", "M"=>" and month(created)=month(now()) and year(created)=year(now())", "M-1"=>" and month(created)=month(subdate(now(),INTERVAL 1 MONTH)) and year(created)=year(subdate(now(),INTERVAL 1 MONTH))", "M-2"=>" and month(created)=month(subdate(now(),INTERVAL 2 MONTH)) and year(created)=year(subdate(now(),INTERVAL 2 MONTH))", "T"=>" and quarter(created)=quarter(now()) and year(created)=year(now())", "T-1"=>" and quarter(created)=quarter(subdate(now(),INTERVAL 1 QUARTER)) and year(created)=year(subdate(now(),INTERVAL 1 QUARTER))", "T-2"=>" and quarter(created)=quarter(subdate(now(),INTERVAL 2 QUARTER)) and year(created)=year(subdate(now(),INTERVAL 2 QUARTER))", "T-3"=>" and quarter(created)=quarter(subdate(now(),INTERVAL 3 QUARTER)) and year(created)=year(subdate(now(),INTERVAL 3 QUARTER))", "A"=>" and year(created)=year(now())", "A-1"=>" and year(created)=year(subdate(now(),INTERVAL 1 YEAR))", "A-2"=>" and year(created)=year(subdate(now(),INTERVAL 2 YEAR))" ); public function comptaentres($type){ Zend_Debug::dump(self::$where[$type]); }