#1 2012-04-06 16:14:37

nrafto
Member
From: Everywhere
Registered: 2012-04-06
Posts: 6

Migrate controllers, models and views from codeigniter to ionize cms

Dear all,

I'm new to codeigniter and so far find it extremely usefull for creating web apps. I have created several controllers, models and views in codeigniter but came at a point where a cms was needed in order to create a three level administration menu.

Ionize CMS is perfect for what I need but I have a basic (rookie) question : How do I migate the controllers, the models and the views that I created on Codeigniter to Ionize installation ? Is a simple copy paste from CI to Ionize enough ?


...

Offline

#2 2012-04-07 11:59:41

ukyo
Community Manager
From: Marmaris - Turkey
Registered: 2010-05-19
Posts: 731
Website

Re: Migrate controllers, models and views from codeigniter to ionize cms

Check the demo modules


<ion:ukyo from="Turkey" />
Ionize CMS Türkçe Dil Çeviri Dosyaları | My Github Repositories
Please send your first message to a forum section, not forum users or administration.

Offline

#3 2012-04-08 13:08:00

nrafto
Member
From: Everywhere
Registered: 2012-04-06
Posts: 6

Re: Migrate controllers, models and views from codeigniter to ionize cms

Thanks for your prompt reply ukyo !

I've managed to create new modules following the Demo module and the "http://ionizecms.com/en/news/ionize-creating-a-module" howto guide.

Another question: Do I need to define all my custom db tables to the "config.xml" of the newly created module?

The next step is to load the custom modules to my existing theme.


...

Offline

#4 2012-04-08 18:12:23

ukyo
Community Manager
From: Marmaris - Turkey
Registered: 2010-05-19
Posts: 731
Website

Re: Migrate controllers, models and views from codeigniter to ionize cms

If you define all your custom db tables to "config.xml" next module installation will be easy for you


<ion:ukyo from="Turkey" />
Ionize CMS Türkçe Dil Çeviri Dosyaları | My Github Repositories
Please send your first message to a forum section, not forum users or administration.

Offline

#5 2012-04-08 23:09:17

nrafto
Member
From: Everywhere
Registered: 2012-04-06
Posts: 6

Re: Migrate controllers, models and views from codeigniter to ionize cms

Thanks again ukyo! I see the importance of defining the custom db tables.

What I still haven't found is how to link the modules, that I've created, to a page inside my theme. I.e.I have created a Module (Name: "Photo_albums Module", URI: "photo_albums") and would like to display the content inside my ionize theme's page. Is that possible ?


...

Offline

#6 2012-04-09 14:36:04

ukyo
Community Manager
From: Marmaris - Turkey
Registered: 2010-05-19
Posts: 731
Website

Re: Migrate controllers, models and views from codeigniter to ionize cms

You need to write also tags for your module. And you can create a page "Photo Album" and special view for "Photo Album" page you can use tags inside your view file like :

<ion:photo_album>
     <ion:title />
</ion:photo_album>

<ion:ukyo from="Turkey" />
Ionize CMS Türkçe Dil Çeviri Dosyaları | My Github Repositories
Please send your first message to a forum section, not forum users or administration.

Offline

#7 2012-04-12 00:05:52

nrafto
Member
From: Everywhere
Registered: 2012-04-06
Posts: 6

Re: Migrate controllers, models and views from codeigniter to ionize cms

Thanks again for the guidance ukyo. I've managed to create the tag functions on tags.php file of my module (I renamed it to Photoalbums). I followed the example of "Fancyupload" module.

Inside tags.php :

 public static function index(FTL_Binding $tag)
    {
        // Get the module URI
        include APPPATH . 'config/modules.php';

        $uri = array_search('Photoalbums', $modules);
        
        $tag->expand();
            
        return $tag->parse_as_nested(file_get_contents(MODPATH.'Photoalbums/views/photoalbums/create'.EXT));
    } 

The problem is that i want to pass a variable from the controller to the"create" view (i.e. $private_code_element). How can I do it ?

On plain CodeIgniter I was using it as follows:
controller

 $data_to_view['private_code_element'] = $private_code;  
$this->load->view('photoalbums/create',$data_to_view); 

...

Offline

#8 2012-04-13 10:25:25

kojiroh
Member
Registered: 2011-09-06
Posts: 74
Website

Re: Migrate controllers, models and views from codeigniter to ionize cms

In Ionize, you don't directly pass a variable to the view. Instead, you use the <ion:... /> tags. Since you've already created your tags library, here's what you should do:

1. Assuming you've already created your $private_code, add that to your $tag variable locals in your index function before expanding the tag:

...
$tag->locals->private_code = $private_code;
$tag_expand();
...

2. Create a function to return your private code to your view:

public static function private_code(FTL_Binding $tag) {
   return isset($tag->locals->private_code) ? $tag->locals->private_code : '';
}

3. Include the tag in your view:

<ion:photo_album>
     <p>My private code is <ion:private_code />!</p>
     <ion:title />
</ion:photo_album>

Offline

#9 2012-04-13 10:41:53

ukyo
Community Manager
From: Marmaris - Turkey
Registered: 2010-05-19
Posts: 731
Website

Re: Migrate controllers, models and views from codeigniter to ionize cms

Its possible to use also directly pass a variable. but its making ionize slow.


<ion:ukyo from="Turkey" />
Ionize CMS Türkçe Dil Çeviri Dosyaları | My Github Repositories
Please send your first message to a forum section, not forum users or administration.

Offline

#10 2012-04-13 21:37:09

nrafto
Member
From: Everywhere
Registered: 2012-04-06
Posts: 6

Re: Migrate controllers, models and views from codeigniter to ionize cms

Thanks a lot kojiroh and ukyo! That worked for me! I also realized that is much better to move the code from the controller to the tags library. Is that approach correct?

Furthermore, I would like to ask if I can call the helper functions inside the tags i.e.:

$ci =  &get_instance();
$ci->load->helper('form');
$ci->load->library('form_validation');

And after the above, to actually perform the validations:

$ci->form_validation->set_rules('album_name', 'Album Name', 'required');
$ci->form_validation->set_rules('description', 'Album Description', 'required');
$ci->form_validation->set_rules('privacy', 'privacy', 'required');
$ci->form_validation->set_rules('private_code', 'Private Code', 'required');

Is it possible and and good in terms of design ?


...

Offline

#11 2012-04-14 00:28:50

ukyo
Community Manager
From: Marmaris - Turkey
Registered: 2010-05-19
Posts: 731
Website

Re: Migrate controllers, models and views from codeigniter to ionize cms

Check the simpleform module for form validation an other things will help you


<ion:ukyo from="Turkey" />
Ionize CMS Türkçe Dil Çeviri Dosyaları | My Github Repositories
Please send your first message to a forum section, not forum users or administration.

Offline

#12 2012-04-24 22:26:32

nrafto
Member
From: Everywhere
Registered: 2012-04-06
Posts: 6

Re: Migrate controllers, models and views from codeigniter to ionize cms

Thanks for the tips! After configuring the "Simpleform" module, I've managed create the form that I wanted and write the required data to the database.

My problem now is that I don't know how to pass an object (or an array) to the tag.

I.e.

1. Inside my users tag I define an object called $output which consists of two arrays.

public  function users(FTL_Binding $tag)
{    
....
$output = $ci->my_crud->render();
$tag->locals->output_tag = $output;
$tag->expand();
}

2.I define the output_tag which should return the $output object

public static function output_tag(FTL_Binding $tag) {
      
        return isset($tag->locals->output_tag) ? $tag->locals->output_tag : '';
}

3. I call the output_tag inside my view :

<ion:users>
    <ion:output_tag/>
</ion:users>

I get the following error :
A PHP Error was encountered
Severity: 4096
Message: Object of class stdClass could not be converted to string
Filename: ftl/parser.php
Line Number: 159

Can you help me pass the object in the view via tag ?


...

Offline

#13 2012-04-24 23:09:21

kojiroh
Member
Registered: 2011-09-06
Posts: 74
Website

Re: Migrate controllers, models and views from codeigniter to ionize cms

It is possible that Ionize needs arrays to work with tags so you might want to convert your DB objects to arrays via row_array or result_array.

Edit: Disregard the above, I totally missed the point.

You can't directly pass an object or an array to the view using tags. What you have to do is define more nested tags. For example, if you have an array called "car" with two keys, "color" and "year", you would have to create 3 tags: car, car_color and car_year. The first one should set a local variable for your car and expand the tag; while the other ones should return the corresponding keys of the local car variable. I can't write a code example right now but I hope this much can help you.

Last edited by kojiroh (2012-04-24 23:20:54)

Offline

#14 2012-04-25 13:50:34

ukyo
Community Manager
From: Marmaris - Turkey
Registered: 2010-05-19
Posts: 731
Website

Re: Migrate controllers, models and views from codeigniter to ionize cms

Quick way to get data from array to tag :

/**
     * @usage    <ion:users>
     *              <ion:user field="your_field_name" />
     *         </ion:users>
     */
    public static function user(FTL_Binding $tag) {
        $field = (isset($tag->attr['field']) ) ? $tag->attr['field'] : FALSE;

        if ($field) {
            if (!empty($tag->locals->user[$field]))
                return self::wrap($tag, $tag->locals->user[$field]);
        }

        return '';
}

<ion:ukyo from="Turkey" />
Ionize CMS Türkçe Dil Çeviri Dosyaları | My Github Repositories
Please send your first message to a forum section, not forum users or administration.

Offline

#15 2012-04-25 17:39:06

kojiroh
Member
Registered: 2011-09-06
Posts: 74
Website

Re: Migrate controllers, models and views from codeigniter to ionize cms

I also got a new idea while thinking over this: you serialize your object or array and return that value, and then unserialize it on your view. It's not a very nice approach and I'm not sure if it'll work, but it just might.

Last edited by kojiroh (2012-04-25 17:40:01)

Offline

What's Ionize ?

Ionize is an Open Source Content Management System created by webdesigners for webdesigners.

Created and maintained by Partikule and Toopixel, Ionize wants to be the easiest and most powerful CMS.

Can I help ?

Because talent is nothing without involvement, we are looking for motivated coders and webdesigners to join the project team.

Resources

Website : ionizecms.com
Documentation : doc.ionizecms.com

Development : Ionize on GitHub
Translations : Ionize Translations