0

I am having a little trouble when creating my own custom event list using the Eventbrite API.

I can get this to work fine when using the standard example provided here https://github.com/ryanjarvinen/eventbrite.php/blob/master/examples/event-list-example.md, but I would like to customise the layout, as well as pull some additional fields.

Here's what I have when using the above which works fine:

try {
    $events = $eb_client->user_list_events();
} catch ( Exception $e ) {
    // Be sure to plan for potential error cases 
    // so that your application can respond appropriately

    //var_dump($e);
    $events = array();
}

Eventbrite::eventList( $events, 'eventListRow');

However when I attempt to use the additional event list customisation example provided, no data is retrieved. Below is how I have attempted to integrate this:

$events = $eb_client->user_list_events();
$events = array();


return $this->load->view('user_list_events', $events, TRUE);        
$event_list_html = Eventbrite::eventList( $events, $custom_render_function);
return $event_list_html;

My view page is:

$custom_render_function = function($evnt){
$time = strtotime($evnt->start_date);
if( isset($evnt->venue) && isset( $evnt->venue->name )){ 
    $venue_name = $evnt->venue->name;
}else{
    $venue_name = 'online';
}   
$evnt_html = "<div class='eb_evnt_list_item' id='evnt_div_"
            . $evnt->id ."'><span class='eb_evnt_list_date'>"
            . strftime('%a, %B %e', $time) . "</span><span class='eb_evnt_list_time'>" 
            . strftime('%l:%M %P', $time) . "</span><a class='eb_evnt_list_title' href='"
            . $evnt->url."'>".$evnt->title."</a><span class='eb_evnt_list_location'>"
            . $venue_name . "</span></div>\n";
return $evnt_html;
}

I have tried multiple options, such as adding the code above where I have return $this->load->view('user_list_events', $events, TRUE); , but this returns Parse error: syntax error, unexpected '}' or Parse error: syntax error, unexpected '$event_list_html'.

Thanks in advance. Ben

UPDATE

 $events = $eb_client->user_list_events();

 return $this->load->view('user_list_events', Eventbrite::eventList( $events, $custom_render_function), TRUE);
Ben
  • 129
  • 3
  • 12

1 Answers1

0

It looks like you may be erasing the API response by overwriting it with a new empty array:

$events = array();
ʀɣαɳĵ
  • 1,992
  • 1
  • 15
  • 20
  • Thanks Ryan, I still get no results returned, as soon as I switch back to the example on Github I get results returned. Thanks – Ben Dec 30 '12 at 14:48
  • you have two return statements. The first is likely preventing the second from executing. I'd move everything in your view back before the return statements, and then change your return to: `return $this->load->view('user_list_events', Eventbrite::eventList( $events, $custom_render_function), TRUE);` – ʀɣαɳĵ Dec 31 '12 at 18:55
  • thanks Ryan. I now get the following: A PHP Error was encountered Severity: Notice Message: Undefined variable: custom_render_function. The $custom_render_function is within my view page. I have provided an update of the code I am currently using, my view page remains the same. Thanks again. – Ben Jan 02 '13 at 12:23
  • did you relocate all the code in your view, back before the return statements? `Undefined variable: custom_render_function` – ʀɣαɳĵ Jan 02 '13 at 18:13
  • Hi Ryan, sorry I'm a tad confused. I've got the $custom_render_function within the view page called my_events, both are called in the return statement return $this->load->view('my_events', Eventbrite::eventList( $events, $custom_render_function), TRUE);. Before the return statement all i have is $events = $eb_client->user_list_events();. Thanks again – Ben Jan 05 '13 at 16:23
  • I'd take the `$custom_render_function` definition, and remove it from your view code. Instead, it should be placed above the `return` in your other file. This should ensure that the `$custom_render_function` variable is in scope when it's called. I'm not sure how to use your view code, or what information needs to be passed to `$this->load->view()`, but `Eventbrite::eventList( $events, $custom_render_function))` should return a string of HTML. I'd pass the result from that function into your view code, rather than trying to run it from within the view. – ʀɣαɳĵ Jan 05 '13 at 20:37