⚠ 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

ADD_ACTION to an External URL and passing values



jdaganzo
  • profile picture
  • Member

Posted 09 December 2013 - 15:27 PM

I am fairly new to Grocery Crud and I have read the documentation and searched the forum but I am looking to see how I can add an External URL instead of a link to another crud model within my application.  Here is my example:

 

    public function participant()
    {
      $crud = new grocery_CRUD();
      $crud->set_theme('datatables');
      $crud->set_table('participant');
      $crud->where('participant.EVENT_ID',1011);
      $crud->display_as('EVENT_ID','Event');
      $crud->display_as('DIVISION_ID','Division');
      $crud->set_relation('DIVISION_ID','division','{DIVISION_NAME}');
     $crud->set_relation('EVENT_ID','event','{EVENT_NAME}');
     $crud->add_action('Score', '', 'demo/action_more','ui-icon-plus',array($this,'score_participant'));

    }

    public function score_participant($primary_key , $row)
     {
        return redirect("http://www.example.com/add_score.php");
     }

When the PARTICIPANT model renders it wants to immediately redirect to my redirect page. I want to be a link that is external that I will eventually pass the row parameters to a custom external php page.  I have also tried to use SITE_URL, but that doesn't work cause it tries to build the base url for grocery crud with expecting it to go through the controllers.  Can someone give me a tip on how to make it go to a custom non grocery crud link and pass some values of the row to it?  
 
Here is a screen shot of my example.
 
 
 
JD

victor
  • profile picture
  • Member

Posted 09 December 2013 - 21:37 PM

you can add an action to a function which will be redirect to another function( or the other address you want) using id which will be gotten
from the first one.

for example: 

step 1:
add action

step 2:

the function (which you set in the "add action") will get id

step 3:
redirect to the another function or url you want.

sorry for my English


jdaganzo
  • profile picture
  • Member

Posted 11 December 2013 - 11:41 AM

Victor, if you look at my example above.  What you recommended is what I did.  The problem is the redirect in step 3 does not work in regards to the redirect.

 

Step 1:  $crud->add_action('Score', '', 'demo/action_more','ui-icon-plus',array($this,'score_participant'));

Step 2:   public function score_participant($primary_key , $row)

                {
                     return redirect("http://www.example.com/add_score.php");
                 }
Step 3:  The redirect does not work it tries to format the url with the controller of the original app. I need it to not format the url and go to a non GC php page (in my case add_score.php)

briggers
  • profile picture
  • Member

Posted 12 December 2013 - 15:55 PM

hi,

 

you don't want return 

just redirect(...)

public function score_participant($primary_key , $row)
                {
                     redirect("http://www.example.com/add_score.php");
                 }

jdaganzo
  • profile picture
  • Member

Posted 12 December 2013 - 18:08 PM

Hello Briggers,
 
If I do as you suggested now my object PARTICIPANT and the data grid never shows and it automatically goes to the redirect below.
 
  public function participant()
    {
      $crud = new grocery_CRUD();
      $crud->set_theme('datatables');
      $crud->set_table('participant');
      $crud->where('participant.EVENT_ID',1011);
      $crud->display_as('EVENT_ID','Event');
      $crud->display_as('DIVISION_ID','Division');
      $crud->set_relation('DIVISION_ID','division','{DIVISION_NAME}');
     $crud->set_relation('EVENT_ID','event','{EVENT_NAME}');
     $crud->add_action('Score', '', 'demo/action_more','ui-icon-plus',array($this,'score_participant'));

    }

    public function score_participant($primary_key , $row)
    {
       redirect("http://admin.boxtribetracker.com/add_score.php");
    }
Thanks,
Jerson

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 14 December 2013 - 12:54 PM

Hello Jerson,

 

I think what you need is this:

    public function score_participant($primary_key , $row)
     {
        return "http://www.example.com/add_score.php";
     }

So your full code will be something like this:

public function participant()
{
    $crud = new grocery_CRUD();
    $crud->set_theme('datatables');
    $crud->set_table('participant');
    ...
    $crud->add_action('Score', '', 'demo/action_more','ui-icon-plus',array($this,'score_participant'));

}

public function score_participant($primary_key , $row)
{
      return "http://www.example.com/add_score.php";
}

If you need to add some parameters from the table to the URL you can simply do something like this:

public function score_participant($primary_key , $row)
{
  //With the below code you will have the EVENT_ID and the PID as GET parameters to your next request.
  return "http://www.example.com/add_score.php?EVENT_ID=".$row->EVENT_ID."&PID=".$row->PID;
}

I don't know if the fields names are EVENT_ID and PID but you got the point B)

 

If you still having issues, please let me know

 

Cheers

Johnny


jdaganzo
  • profile picture
  • Member

Posted 14 December 2013 - 13:54 PM

Johnny,

 

This worked like a champ!  I knew it was something very simple.  Onward and forward with this RAD project that I am working on.  Thanks for the response and if anybody is reading this thread and hasn't donated do this project....do it now!!!!

 

Regards,

Jerson-


basque
  • profile picture
  • Member

Posted 31 March 2014 - 09:21 AM

I 'm trying to do something like this, but it doesn't show the button for this action. 
 
If i go to "show source code" this button exist, but its not visible in the view...  i'm doing it like you said but i'm not seeing the button. Is this still possible to do?
 
The show, edit and delete has 
 
<span class='XXX'></span>
 
inside the link, my "special" action doesn't have any icon thats why i think i do not see anything, but i don't know how to solve this...
 
 
Edit: OK. I was missing the image
 
$crud->add_action('Score', 'http://www.grocerycrud.com/assets/uploads/general/smiley.png', 'demo/action_more','ui-icon-plus',array($this,'score_participant'));

 


yang
  • profile picture
  • Member

Posted 05 May 2015 - 11:15 AM

 

I 'm trying to do something like this, but it doesn't show the button for this action. 
 
If i go to "show source code" this button exist, but its not visible in the view...  i'm doing it like you said but i'm not seeing the button. Is this still possible to do?
 
The show, edit and delete has 
 
<span class='XXX'></span>
 
inside the link, my "special" action doesn't have any icon thats why i think i do not see anything, but i don't know how to solve this...
 
 
Edit: OK. I was missing the image
 
$crud->add_action('Score', 'http://www.grocerycrud.com/assets/uploads/general/smiley.png', 'demo/action_more','ui-icon-plus',array($this,'score_participant'));

 

 


Alexandra Kampouraki
  • profile picture
  • Member

Posted 08 May 2015 - 15:17 PM

Hello,

 

I am newbie in Codeigniter and Grocery crud. I am trying to do something like this.

I am developing a admin/client panel management area  that is adding editing deleting clients/suppliers, handling their billing information sending them newsletters etc. My question is if there is any way to use grocery crud responsive table but instead of grocery crud edit/add area to redirect to my edit/add pages(view, controller). If there is, how can I do that and what should I change instead?

 

I will really appreciate if you could help me. Thank you for your time.