0

I have a website built on the Ushahidi platform that uses the Kohana framework. Currently the site runs on Kohana 2.x.

I would like to grab the report title for each report page on my website. The website in question is a number of "report" pages.

I'm new to code in general and this is my first time coming across a MVC framework. It sounds good though, as far as I can interpret one can pull info out of the db without writing a sql query but rather by calling it within the view itself. Right?

The documentation gives some examples of using Kohana to grab info out of the DB here: https://wiki.ushahidi.com/display/WIKI/Database+access

Here's one of the examples I tried that outputs the expected data: $reportcount = ORM::factory('incident')->count_all();

So, as someone new to this, I wanted to use that snippet of code as a base and edit it to get what I need for my current task. The website in question is a series of "reports" and for each report page I would like to add the report title to a meta description tag in the head.

Here is the code that outputs the report title further down the DOM on a report page:

<h1 class="report-title"><?php
echo html::escape($incident_title);

I cannot find the escape function anywhere to refer to and, since I'm adding this meta tag via a plugin, the function that generates the meta tag exists on a separate script. I tried simply cutting and pasting echo html::escape($incident_title); but as expected the variable $incident_title was not recognized.

Each report page somehow seems to know it's id $incident_id. I know this after experimenting with the following:

$incititle = ORM::factory('incident')->table_column('incident_id');
echo $incititle;

This gave the error message "Invalid method table_column called in Incident_Model"

Then I tried:

$incititle = ORM::factory('incident')
->where('incident_title', 'incident')->find();
echo $incititle;

This just returned the number 10. I was expecting (more hoping) it would return "Hello Ushahidi", the default example report when one installs the Ushahidi platform.

Here is a screen shot of the incidents table: enter image description here

I want the incident_title for each report - "Hello Ushahidi!" in the example report shown in the table.

It seems too that "incident" when used as a parameter in the code I tried above seems to recognize what specific incident is being referred to. So in theory each view should have it's own ID magically stored away somewhere, I do not know how but appears to be the case.

How would I grab the incident_title from the incident table for each incident/report?

Doug Fir
  • 19,971
  • 47
  • 169
  • 299
  • In your last piece of code (with `where()` and `find()`), doesn't `$incititle->incident_title` give you the proper result? You might also want to use `var_dump()` instead of `echo` as it is not a simple string (currently) and you're not getting all the information – kero Apr 21 '14 at 12:46
  • Hm. Tried both your suggestions - using echo and var_dump() with $incititle->incident_title. Produced NULL? Does that shed any light? – Doug Fir Apr 21 '14 at 13:39
  • Does `$incititle = ORM::factory('incident',1)->incident_title;` work? – kero Apr 21 '14 at 13:50
  • Yes! Except it shows it on every page, not the particular report page it should be on. What does the 1 do? – Doug Fir Apr 21 '14 at 13:56
  • It is a selector (such as the `where`) meaning you want record with the specified value as `id`. This means that the problem is in your `where` part (I told you to do so for a test case since from your screenshot I know that an element with `id == 1` exists). How are you detecting which particular report you want? – kero Apr 21 '14 at 13:58
  • @kingkero I'm not sure. I looked at the existing reports page that pulls in the report title and only found the snippet I pasted in the post echo html::escape($incident_title);. Is there a particular script that I should be looking in for clues? I had posted on the Ushahidi forum here: https://forums.ushahidi.com/t/grabbing-the-report-description-proper-way/1690 The scrips that she is referencing, if it's any help, are at these gists:https://gist.github.com/anonymous/11144025 and https://gist.github.com/anonymous/11144060 – Doug Fir Apr 21 '14 at 14:18

0 Answers0