I have created a JSON for the dynamic folders.
code for dynamic folders is :
- Code: Select all
<?php require_once( 'couch/cms.php' ); ?>
<cms:template title='Add Employee/Member' order='1' clonable='1' dynamic_folders='1'>
<cms:editable name='contact' label='Contact Details' type='group' order='1' />
<cms:editable name='mob_o' label='Mobile (Official)' type='text' group='contact' />
<cms:editable name='mob_p' label='Mobile (Personal)' type='text' group='contact' />
<cms:editable name='tel_o' label='Landline (Office)' type='text' group='contact' />
<cms:editable name='tel_r' label='Landline (Residence)' type='text' group='contact' />
<cms:editable name='address' label='Postal Details' type='group' order='2' />
<cms:editable name='address_o' label='Address (Office)' type='textarea' no_xss_check='1' group='address' />
<cms:editable name='address_r' label='Address (Residence)' type='textarea' no_xss_check='1' group='address' />
<cms:editable name='online' label='Online Details' type='group' order='3' />
<cms:editable name='email_o' label='Email (Official)' type='text' group='online' />
<cms:editable name='email_p' label='Email (Personal)' type='text' group='online' />
</cms:template>
<?php COUCH::invoke(); ?>
Now I generated a JSON for only the Parent departments as:
- Code: Select all
<?php require_once( '../couch/cms.php' ); ?>
<cms:content_type 'application/json'/>
{
"departments" :
[
<cms:set department_count='0' />
<cms:folders masterpage='emp.php' order='asc' depth='1'>
{
"deptId" : "<cms:show k_folder_id />",
"deptName" : "<cms:show k_folder_title />",
"hasChild" : "1"
}
<cms:incr department_count />
<cms:if department_count!=k_total_folders> , </cms:if>
</cms:folders>
]
}
<?php COUCH::invoke(); ?>
that gives a n output as:
- Code: Select all
{
"departments": [
{
"deptId": "1",
"deptName": "Development",
"hasChild": "1"
},
{
"deptId": "11",
"deptName": "Management",
"hasChild": "1"
},
{
"deptId": "3",
"deptName": "Research & Development",
"hasChild": "1"
},
{
"deptId": "2",
"deptName": "Sales",
"hasChild": "1"
}
]
}
I then created a now JSON output for the Child Departments using the code:
- Code: Select all
<?php require_once( '../couch/cms.php' ); ?>
<cms:content_type 'application/json'/>
{
"childDept" :
[
<cms:set child_department_count='0' />
<cms:folders masterpage='emp.php' order='asc' depth='1'>
<cms:if k_folder_immediate_children >
<cms:folders masterpage='emp.php' order='asc' childof=k_folder_name depth='1'>
{
"deptId" : "<cms:show k_folder_id />",
"deptName" : "<cms:show k_folder_title />"
}<cms:if "<cms:not k_paginate_bottom/>"> , </cms:if>
</cms:folders>
</cms:if>
</cms:folders>
]
}
<?php COUCH::invoke(); ?>
and that generates the following output, which is has an error. the out put is:
- Code: Select all
{
"childDept" :
[
{
"deptId" : "6",
"deptName" : "Android"
} , {
"deptId" : "5",
"deptName" : "Dot Net"
} , {
"deptId" : "4",
"deptName" : "PHP"
} ,
{
"deptId" : "13",
"deptName" : "Development"
} , {
"deptId" : "14",
"deptName" : "Research & Development"
} , {
"deptId" : "12",
"deptName" : "Sales"
} ,
{
"deptId" : "10",
"deptName" : "Products"
} ,
{
"deptId" : "9",
"deptName" : "Mobile Application"
} , {
"deptId" : "8",
"deptName" : "Webportal"
} , {
"deptId" : "7",
"deptName" : "Website"
} ,
]
}
0
THE PROBLEM:1. There is a comma appearing at the last entry:
} , {
"deptId" : "7",
"deptName" : "Website"
} ,
How can I stop it!
2. a ')' (zero) appears at the end of the json. How to stop its auyout? How to stop it?