Tuesday, June 27, 2017

How to iterate over array in ionize-cms with codeigniter?

Leave a Comment

I'm using Ionize cms for the back end of my site and i want to create my own Tags - for passing data from my own tables. I've followed This tutorial to create custom tags, and by that - passing data to views, but i keep getting error :

Tag missing: demo, scope: .

Here is my view :

<ul>     <ion:demo:details>          <li><ion:detail field="user_name" /></li>     </ion:demo:details> </ul> 

And here are the changes I've added to TagManager.php

 public static $tag_definitions = array     (     // <ion:demo:authors /> calls the method “tag_details”     "demo:details" =>      "tag_details",     "demo:details:detail" =>    "tag_detail",     ); 

I've also tried to create a simple codeigniter controller and pass the data with view() and to do something like :

<ul>    <?php foreach($details as $detail): ?>      <li>      <?php echo $detail['name'] ?>      </li>     <?php endforeach ;?> </ul> 

But i'm getting undefined error of $details...

1 Answers

Answers 1

Got it... changed the tags and now it's good.

<?php   class TagManager_Data extends TagManager  { /**  * Tags declaration  * To be available, each tag must be declared in this static array.  *  * @var array  *  */ public static $tag_definitions = array (     // <ion:demo:authors /> calls the method “tag_authors”     "authors" =>      "tag_authors",     "authors:author" =>    "tag_author",      );      /**      * Base module tag    * The index function of this class refers to the <ion:#module_name /> tag    * In other words, this function makes the <ion:#module_name /> tag    * available as main module parent tag for all other tags defined  * in this class.  *  * @usage  <ion:demo >  *      ...  *    </ion:demo>  *     */    public static function index(FTL_Binding $tag)    {     $str = $tag->expand();      return $str;     }     /**  * Loops through authors  *  * @param FTL_Binding $tag  * @return string  *  * @usage  <ion:demo:authors >  *        ...  *    </ion:demo:authors>  *  */    public static function tag_authors(FTL_Binding $tag) {     // Returned string     $str = '';      // Model load     //self::load_model('demo_author_model', 'author_model');      // Authors array     $authors = [["name"=>'josh',"foo"=>'josh'],     ["name"=>'joshjosh',"foo"=>'josh'],["name"=>'josh',"foo"=>'josh']];      foreach($authors as $author)     {         // Set the local tag var "author"         $tag->set('author', $author);          // Tag expand : Process of the children tags         $str .= $tag->expand();     }      return $str;    }    /**  * Author tag  *  * @param    FTL_Binding    Tag object  * @return    String      Tag attribute or ''  *  * @usage    <ion:demo:authors>  *        <ion:author field="name" />  *       </ion:demo:authors>  *  */ public static function tag_author(FTL_Binding $tag) {     // Returns the field value or NULL if the attribute is not set     $field = $tag->getAttribute('field');      if ( ! is_null($field))     {         $author = $tag->get('author');          if ( ! empty($author[$field]))         {             return self::output_value($tag, $author[$field]);         }          // Here we have the choice :         // - Ether return nothing if the field attribute isn't set or          doesn't exist         // - Ether silently return ''         return self::show_tag_error(             $tag,             'The attribute <b>"field"</b> is not set'         );         // return '';     }     }   } 
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment