⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

callback_column weird behavior.



fredconv

fredconv
  • profile picture
  • Member

Posted 06 September 2012 - 10:07 AM

Hi

sorry to bother but i have a new weird behavior for callback_column.

on my project controller:

public function list_items() {
$crud_list = new grocery_CRUD();
$crud_list->set_table('tbl_project');
$crud_list->set_subject('Project');
$crud_list->callback_column('project_code',array($this,'callback_webpage_url'));
$output = $crud_list->render();
$this->result_output($output);
}

and the definition of the callback_webpage_url

public function callback_webpage_url($value, $row){
return '<a href="'.site_url("projects/detail_item/".$row->project_code).'">'.$value.'</a>';

}


my problem is : the projects table "project_code" show a correct link on it but the "edit" link and on the delete link also , in the action section of each row

<a title="Edit Project" href="http://localhost........./projects/list_items/edit/&lt;a href=&quot;http://localhost:8181/backlog/index.php/projects/detail_item/p0&quot;&gt;p0&lt;/a&gt;"><span class="edit-icon"></span></a>



it seems the url passing into the link from my project_code (which is correct) is also passed to the edit link ...
how to avoid this pb please ?

thanks.

victor

victor
  • profile picture
  • Member

Posted 06 September 2012 - 10:40 AM

write please table structure

fredconv

fredconv
  • profile picture
  • Member

Posted 06 September 2012 - 12:43 PM

Hi.

here s my table data structure (really simple)..


1 table tbl_project
##id
project_code
shortname
description
start_time
estimated_time
...many more fields....

1table tbl_sub_projects
##id
name
description
#project_id
owner
.....


What i would like to achieve is to have one first page list of all projects but with only some fields visible, and when i click on one project code link, display first the clicked project with all details and below all the sub projects related to this project ..


thanks

victor

victor
  • profile picture
  • Member

Posted 06 September 2012 - 13:31 PM

Please send me or write the mysql dump with data
I'll try to find the error.
Sorry, my english is bad))

fredconv

fredconv
  • profile picture
  • Member

Posted 10 September 2012 - 08:36 AM

[quote name='victor' timestamp='1346938274' post='3278']
Please send me or write the mysql dump with data
I'll try to find the error.
Sorry, my english is bad))
siptik@mail.ru
[/quote]

Mail send.
Sorry for my late reply.

Thanks for your help.

victor

victor
  • profile picture
  • Member

Posted 10 September 2012 - 13:13 PM

I looked at your code and realized that you can not use callback function for primary fields, because this field will have new value. Link "edit" use the value primary fields.
You can create other primary field , for example `id ` (auto_increment ).
or

This code work fine)))
function get_list(){
$crud = new grocery_CRUD();
$crud->set_table('tbl_project');
$crud->set_subject('Project');
$crud->columns(
// add a new coloumn `code` instead of column `project_code`
'code',
'project_shortname',
'project_name',
...other fields
$crud->callback_column('code',array($this,'callback_webpage_url'));
$output = $crud->render();
$this->load->view('test',$output);
}
public function callback_webpage_url($value, $row){
return '<a href="'.base_url("index.php/functionalities/get_items_from_project/".$row->project_code).'">'.$row->project_code.'</a>';
}

fredconv

fredconv
  • profile picture
  • Member

Posted 10 September 2012 - 13:19 PM

Hi

Thanks for your solution.
Since i can't change the database structure (not mine) i ll simply change the column on which i call the callback :)
from:

$crud->callback_column('project_code',array($this,'callback_webpage_url'));

to

$crud->callback_column('project_shortname',array($this,'callback_webpage_url'));



Thank you :)


PS: Did i miss the info saying the call back should not be called on a primary key ? (ok normally, primary key should not be change :P, and the database strucutre is a bit weird ... *emergency evade process engaged* :D ) )

victor

victor
  • profile picture
  • Member

Posted 10 September 2012 - 13:34 PM

The column `code` no need to create in database. this column is dynamically created. Use my code and you will see this. Structure does not change.
Sorry my English is bad.
If this field is not in the table structure, dynamically create a new column in table list. For this column can use callback function.

fredconv

fredconv
  • profile picture
  • Member

Posted 10 September 2012 - 13:46 PM

Ha ok
I understand now, add a new column for the display, put the project code in it , so i can call the callback function on this new column.
Great .

Thanks for this solution :)