⚠ 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

Post Add Action



epndkempot
  • profile picture
  • Member

Posted 12 April 2013 - 00:32 AM

Hi gentlemen...

 

I want to manage (apply buzz.js) selected row by using add action, but I found its hard to apply my code.

main.php (application\controllers)

 

    public function arrival()
    {
        $crud = new grocery_CRUD();
        $crud->set_table('arrival');
        $crud->columns('origin','airline','flight','schedarrival','actualarrival','termgate','status');
        $crud->fields('origin','airline','flight','schedarrival','actualarrival','termgate','status');
        
        $crud->display_as('actualarrival','Actual Arrival');
        $crud->display_as('schedarrival','Scheduled Arrival');
        $crud->display_as('termgate','Gate');
        $crud->set_relation('origin','airport','city');
        $crud->set_relation('airline','airlines','alname');
        $crud->set_relation('status','statuss','sname');
        $crud->add_action('Announce', '', 'main/announce','play-icon'); //here
  
        $output = $crud->render();
        $this->_example_output($output); 
    }
 
    function announce($id){
        $crud = new grocery_CRUD();
        $crud->set_table('arrival');
        $crud->columns('origin','flight','status');
        $crud->where('id',$id);
        $data = $crud->render();
        $this->load->view('arrival_view.php',$data);  
    }
 
arrival_view.php (application\views)
 
<!DOCTYPE html>
<html lang="en">
<head>    
   <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
</head>
<body>
<?php 
    echo  $output;
?>
</body>
</html>

 

The code works but I cannot get specific values (origin, flight & status) from the $output because the view can only show table result.

I had try make another page contain:

- echo  $output['flight'], it gave error: Illegal string offset

- echo  $output->flight, it gave error: Trying to get property of non-object

 

Is there a way to pass the values to the view page smoothly without having a table?

Feel free to change my approach...

Thank you in advance


epndkempot
  • profile picture
  • Member

Posted 12 April 2013 - 02:19 AM

I just found a 'solution' to pass the value manually

 

config.php (application/config)

$config['index_page'] = ''; // before was index.php

 

main.php

 

    public function arrival()
    {
        $crud = new grocery_CRUD();
        $crud->set_table('arrival');
        $crud->columns('origin','airline','flight','schedarrival','actualarrival','termgate','status');
        $crud->fields('origin','airline','flight','schedarrival','actualarrival','termgate','status');
        
        $crud->display_as('actualarrival','Actual Arrival');
        $crud->display_as('schedarrival','Scheduled Arrival');
        $crud->display_as('termgate','Gate');
        $crud->set_relation('origin','airport','city');
        $crud->set_relation('airline','airlines','alname');
        $crud->set_relation('status','statuss','sname');
        $crud->add_action('Announce', '', '','play-icon',array($this,'play')); //here
  
        $output = $crud->render();
        $this->_example_output($output); 
    }
    
    function play($primary_key , $row)
    {
        return site_url('play.php').'?origin='.$row->origin.'&flight='.$row->flight.'&status='.$row->status;
    }
 
play.php
<!DOCTYPE html>
<html lang="en">
<head>
</head> 
<body>
    <?php
    $or = $_GET['origin'];
    $fl = $_GET['flight'];
    $st = $_GET['status'];
    echo $or;
    echo $fl;
    echo $st;
    ?>
</body>
</html>

 

Please let me know if there is a simpler/shorter method  :)


epndkempot
  • profile picture
  • Member

Posted 12 April 2013 - 04:59 AM

another problem occurs...

when I want to edit the record, the link become http://test/main/arrival/edit/1 (test is the name of site) and give error The requested URL /main/arrival/edit/1 was not found on this server.

I know this is happened because I change $config['index_page'] to ''; which I use to pass value to play.php (test/)

So I return it again $config['index_page'] to 'index.php';

I change this in main.php

    function play($primary_key , $row)

    {
        return site_url('play').'?origin='.$row->origin.'&flight='.$row->flight.'&status='.$row->status; //without .php now
    }
and move play.php to application/controller
 
I click the additional action and it loads play.php, print the result BUT still gives "404 Page Not Found. The page you requested was not found."'s error
 
Any idea why it is happening? How to fix the error?

davidoster
  • profile picture
  • Member

Posted 12 April 2013 - 05:45 AM

Welcome to the forum!

 

Another approach is to try using the callback_column which changes the output of a column data to your specifications and adding it to a dummy column.

 

Another way is to use the $css_class to help you out, 

$crud->add_action('More', '', 'demo/action_more','ui-icon-plus');

where the definition of the $css_class (e.g. ui-icon-plus here) can be used from a jQuery script you include to your page and transforms this hyperlink to anything you like.

 

The first approach is on the server side where the last one is on the client side.


epndkempot
  • profile picture
  • Member

Posted 17 April 2013 - 03:07 AM

Hi david

 

Thanks for your suggestion. I tried the callback_column but it's not what I want.

I tried the second ideas, but found difficulty

$crud->add_action('Announce', '', '','play-icon',array($this,'play'));

 

 

    function play($primary_key , $row)
    {
        return site_url('/play').'?city='.$row->destination.'&flight='.$row->flight.'&status='.$row->status;
    }

 

my $css_class is play-icon, I already register it to flexigrid.css 

 

.flexigrid .play-icon

{
    background:url(images/play.png) no-repeat;
    cursor: pointer;    
    width: 16px;
    height:16px;
    float:right;    
    border: none !important;
    padding:0px !important;    
    padding-bottom:0px !important;        
    margin-left:5px;
    display: block;
}
 
Where should I put the jQuery script?
If main.php, in which position exactly I should put?
Now my url will display like this http://test/index.php/play?city=value&flight=value&status=value (play.php inside the controller), can the jquery scipt make it like http://test/play.php (outside the controller, inside the root folder) ?
 
thank you again...