Variable dans les classes php
Résolu
matdev
Messages postés
28
Statut
Membre
-
matdev Messages postés 28 Statut Membre -
matdev Messages postés 28 Statut Membre -
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
- Vba excel sélectionner une plage de cellules variable ✓ - Forum VB / VBA
- Ajoutez à la liste de contacts ana le goff, inscrite le 27 novembre 2015, dans la catégorie i. puis triez les contacts en les classant : par ordre alphabétique de leur nom de famille (critère principal), puis par date du plus récent au plus ancien (critère secondaire). quel mot apparaît à la verticale dans la colonne "catégorie" entre les lignes 200 et 209 (en-tête compris) ? ✓ - Forum Word
- 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]);
}