⚠ 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

Force default, edit or delete state



fredconv
  • profile picture
  • Member

Posted 18 September 2012 - 09:35 AM

Hi

Is it possible to force a grocery render in edit mode by default ?
Currently I m using GC for displaying a SQL VIEW. but since i can edit a SQL view, i want to still have a link in one of the field of the grid to be able to edit one of the table my view is using

for example: i have 3 tables (projects, sub_projects, users) linked together with joins. (1 to n link, projects to sub_projects and sub_projects to users) but since i want some added or calculated fields that are calculated in the database etc...i use a view to display all on big grid with the informations i want.

How can i add an EDIT link on the project name field that would be the same as if i click on a EDIT link from the projects table that i would have rendered if i was not displaying the VIEW grid ?

i was going to try creating a new grocery_crud object refering to the table projects and open it in the edit mode.

and when i push the update or the back to list , the page owould come back to the VIEW grid instead of the Projects grid..

i know it s possible, instead of a view display to use a big table with join rules and set relations, but i was wondering if it s possible to do it that way.

Hope i m clear enough

Thanks

midnigther
  • profile picture
  • Member

Posted 18 September 2012 - 18:55 PM

http://www.grocerycrud.com/documentation/options_functions/callback_column

fredconv
  • profile picture
  • Member

Posted 19 September 2012 - 07:49 AM

Hi

Thanks for this help

But i did know how to add a link on a specific column :)
let s say, in my projects controller, i have a projects_view method with grocery object pointing to projects_view view. with a project code. when i click edit on a row edit link, it calls a function , with a grocery object refering to projects_table. I want to reach the edit page just as if i ve click on a edit link in a grocery object refering to the projects_tables.

here's my code:


function get_list_from_projects_view(){

$crud = new grocery_CRUD();
$crud->set_table('view_project');
$crud->unset_operations(); // it s a view

$crud->callback_column('project_name',array($this,'callback_projectedit_link'));

$output = $crud->render();

$this->load->view($output);
}


and the function:


function callback_projectedit_link($value, $row){

return ('<a href="'.base_url("index.php/projects/index/edit/".$row->project_code).'">'.$value.'</a>');
}


but i want the edit link to act as if i clicked on an edit link from this grid (in the same controller) where i would have passed the project code (so force the edit state from this object

function get_list_from_projects_table($code){
$crud = new grocery_CRUD();
$crud->set_table('table_projects',$code);
$crud->where('project_code',)
$output = $crud->render();
$this->load-view($output);
}


any idea ?

thanks

fredconv
  • profile picture
  • Member

Posted 25 September 2012 - 12:57 PM

Hi

this will i htink also help Chris on his topic

Displaying a crud view of a view_project_table that is referring to a project_table and concatenate with subproject_table
but when i clicked add -> using the create form from the crud ojbject referring to the project_table only ... so only call the edit / delete / create form of the crud object, not the grid list.

Thanks

Amit Shah
  • profile picture
  • Member

Posted 16 May 2013 - 20:18 PM

Well there is another scenario you can have

 

I found it interesting and i thought of sharing with you guys. May be this can help you too.

 

There was a requirement where i was interested to use grocery crud edit function for updating a users profile. It seemed trickey but then it was easy with redirections

            $crud = new grocery_CRUD();
            
            $crud->unset_add();
            $crud->unset_delete();
            $crud->unset_list();
//the above ensures the the user is not permitted to do anything but edit
            $crud->unset_back_to_list();
//The above ensures the user is left on the same page after edit / update and have no other actions.
            
//Here was the trick. Identify if the operation was Unknown / List then redirect it the users 
//profile update page
            $state_code = $crud->getState();
            if($state_code == 'unknown' || $state_code == 'list') {
                redirect("users/my_profile/edit/" . $this->user_id);
            }
//Now comes for security. Check if the primary key used for edit is not the same as of the user then
//show him error - do not allow the user to end up editing other users profile            
            $segment_object = $crud->getStateInfo();
            $primary_key = $segment_object->primary_key;
            if($primary_key != $this->user_id) {
                show_error("Sorry you are not authorized to access this page.");
            }

Well hope this is a useful little trick that i managed to build. And you guys can take good advantage of the same.