IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Boucle MVC [PHP 7]


Sujet :

Langage PHP

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    143
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2004
    Messages : 143
    Points : 49
    Points
    49
    Par défaut Boucle MVC
    Bonjour je suis en train de faire un systeme de liste de contenu avec une fonction
    En fait on genere des bloc d'article
    La premeiere boucle liste les blocs a créer et la seconde les articles
    dans mon helper
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    	public static function getCustomlist(&$params)
    	{
    		$list_customblocks = $params->get('add_customblock');
    		if ($list_customblocks){
    		$db = JFactory::getDbo();
    		// Liste les blocs regroupant des articles
    		foreach( $list_customblocks as $list_customblocks_idx => $customblock ){
    			$queryCustomlist = 'SELECT a.id, a.title, b.name , a.catid, a.created, a.created_by, a.modified, a.modified_by, a.featured FROM #__content  AS a LEFT JOIN #__users AS b ON a.created_by = b.id WHERE catid= '. $customblock->catidlist .' AND state = 1 ORDER BY modified DESC LIMIT '. (int) $params->get('count');
    			$db->setQuery( $queryCustomlist );
    			$itemsCustomlist = $db->loadObjectList();
                            // créer la liste des article pour un bloc
    			foreach ($itemsCustomlist as &$itemCustomlist) {
    				$itemCustomlist->link = JRoute::_('index.php?option=com_content&task=article.edit&id='.$itemCustomlist->id);
    			}
    			$customblock->listitems = $itemCustomlist;
    		}
    	}
    		return $list_customblocks;
    	}
    Puis dans template
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    <?php
    foreach( $listCustomlist as $listCustomlist_idx => $customblock ) : ?>
    <?php var_dump($customblock) ; ?>
    <div class="block <?php echo $customblock->catidlist; ?> well well-small"  style="width:<?php echo $customblock->width; ?>%">
       <h3 class="module-title nav-header">
       <i class="fa fa-user"></i>
       <?php echo JText::_($customblock->nameblockcustom); ?> : </h3>
       <?php		$show_all_link = 'index.php?option=com_content&filter_category_id='.$customblock->catidlist; ?>
       <div style='text-align:right;'>
       <a href='<?php echo $show_all_link ?>' class='adminlink'>
       <?php
       echo JText::_( 'MOD_DASHBOARD_ALL' );
       echo "</a></div>";	?>
       <div class="row-striped" style="height:<?php echo $forceheightblock; ?>">
          <table class="table table-hover">
             <thead>
                <tr>
                <th><?php echo JText::_( 'MOD_DASHBOARD_TITLE' ); ?></th>
                <?php if ($customblock->displautblock) : ?><th><?php echo JText::_( 'MOD_DASHBOARD_AUTHOR' ); ?></th><?php endif; ?>
                <?php if ($customblock->displdateblock) : ?><th><?php echo JText::_( 'MOD_DASHBOARD_DATE' ); ?></th><?php endif; ?>
                </tr>
             </thead>
    		<?php var_dump($itemsCustomlist) ; ?>
    				<?php foreach ($itemsCustomlist as $customblock) :?>
             <tbody>
                <tr>
                <td>
                   <a href="<?php echo $customblock->listitems->link; ?>"><?php echo $customblock->listitems->title; ?>
                   <i class="icon-large icon-edit"></i></a>
                </td>
                <?php if ($customblock->displautblock) : ?><td>
                   <span class="small">
                      <i class="icon-user"></i>
     
                      <small class="hasTooltip" title="" data-original-title="<?php echo JHtml::tooltipText('MOD_DASHBOARD_MODIFIED_BY')." ". $customblock->listitems->name; ?>"><?php echo $customblock->listitems->name;?> </small>
                   </span>
                </td>
                <?php endif; ?>
                <?php if ($customblock->displdateblock) : ?>
                <td>
                <span class="small">
                   <i class="icon-calendar"></i> <?php echo JHtml::date($customblock->listitems->modified, 'd M Y'); ?>
                </span>
                </td>
                <?php endif; ?>
             </tr>
          <?php endforeach; ?>
                      </tbody>
          </table>
    </div>
    </div>
    <?php endforeach; ?>
    Le soucis c'est qu'il ne me renvoi qu'un article par bloc et pas les X articles et je séche
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    var_dump($itemsCustomlist)
    dans mon helper est ok renvoit bien la liste des articles mais que depuis le helper
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    var_dump($itemsCustomlist)
    dans mon template me renvoi bien 1 bloc avec 1 seul article dedans.....
    je ne capte pas pourquoi ...
    Merci par avance

  2. #2
    Expert éminent sénior
    Avatar de rawsrc
    Homme Profil pro
    Dev indep
    Inscrit en
    Mars 2004
    Messages
    6 142
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Dev indep

    Informations forums :
    Inscription : Mars 2004
    Messages : 6 142
    Points : 16 545
    Points
    16 545
    Billets dans le blog
    12
    Par défaut
    Salut,

    tu n'aurais pas oublié un s à $itemCustomlist; :
    remplace $customblock->listitems = $itemCustomlist; par
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $customblock->listitems = $itemsCustomlist;
    C'est pour ça qu'il faut vachement gaffe quand on manipule des noms de variables tellement proches...

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    143
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2004
    Messages : 143
    Points : 49
    Points
    49
    Par défaut
    des fois il faut des lunettes !
    Merci

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [SimpleXML] Google Maps, Problème d'encoding dans une boucle
    Par yahn dans le forum Bibliothèques et frameworks
    Réponses: 1
    Dernier message: 23/09/2006, 19h40
  2. Réponses: 2
    Dernier message: 28/08/2006, 13h16
  3. Problème de SCANF dans une boucle WHILE
    Par FidoDido® dans le forum C
    Réponses: 4
    Dernier message: 30/12/2005, 17h42
  4. [Conception] Problème de test dans une boucle while
    Par Cyrius dans le forum PHP & Base de données
    Réponses: 2
    Dernier message: 26/11/2005, 18h07
  5. Problème avec TNMSMTP dans une boucle.
    Par Orgied dans le forum Web & réseau
    Réponses: 3
    Dernier message: 07/04/2004, 10h19

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo