Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Sphinx 0.1: $SphinxSearchForm / no enabled local indexes to search


Reply


59 Posts   12195 Views

Avatar
Carbon Crayon

Community Member, 598 Posts

29 July 2010 at 8:40am

Edited: 29/07/2010 8:41am

Hi Enclave,

it really depends how your data objets are related to the holder page. If they are attached to a holder page (i.e. managed via a DataObjectManager) then you can use that relation for example:

static $has_one = array(
'ComplaintsHolder' => 'ComplaintsHolder'
);

function Link(){

$Holder = $this->ComplaintsHolder();

$Link = $Holder->Link() . 'retrieve_case/' . $this->ID;

return $Link;

}

I think that should work, perhaps it didn't like constructing the link on return, I vaguely remember having that issue before.

If your DO are not attached to holders directly then you need to fetch the Holder using a DataObject::get() or another method.

Thanks for the advice getting mine working, I will give it a try in the office tomorrow.

Aram

Avatar
Enclave SSC

Community Member, 31 Posts

29 July 2010 at 8:53am

Thanks @aram. As you posted I updated my post.

** I need to somehow call the ID from my page search in this Link function on my dataobject decorator. Then I need to get dataobject by ID. How can I call the ID from the page_controller search function in this link function? ** My total lack of PHP and OO programming is letting me down.

You see via my page search function I am searching using sphinx and finding my dataobjects returned directly to Page_results.ss. They are just not linked correctly :).

Avatar
Carbon Crayon

Community Member, 598 Posts

29 July 2010 at 9:04am

Hi Enclave,

That function I posted should be placed in your DataObject, it will then return the correct link when it is rendered on the Page_results page. As it is rendered the results control loop is inside the DO so the function needs to reference it's own objects ID, hence the $this->ID bit at the end.

I'm pretty sure that is how it's done, but Mark may know better :)

Aram

Avatar
Enclave SSC

Community Member, 31 Posts

29 July 2010 at 9:13am

Edited: 29/07/2010 9:24am

Great @aram. I now understand it 100%.

Although using this, as placed in my DO decorator always only returns the last ID and not the one I want for the specific result:

function Link(){
   $case = DataObject::get_one("DecidedCase");
   return Director::baseURL() . 'cases/' . $case->Type . '/retrieve_case/' . $case->ID;
}

$this->ID returns no ID :(

function Link(){
   $case = DataObject::get_one("DecidedCase");
   $link = $case->Link() . 'cases/' . $this->Type . '/retrieve_case/' . $this->ID;
   return $link;
}

The above throws me a blank page with nothing on it. Something dies but nothing in error log. This should be a simple task and I'm failing :D

Avatar
Carbon Crayon

Community Member, 598 Posts

29 July 2010 at 9:30am

Hi Enclave

this should not be in your decorator, it should be in your actual data object, and you should be using the DataObject::get_one() to get the holder, not the DO itself, we are in the DO so all we need to do to return that is $this.

I think the function in my more recent post is closer to what you want.
You need to grab the page that displays the DO, and then append the rest of the link onto the end of that pages Link() function, which is what that function I wrote did. so using what I understand of your names it should be something like this:

class DecidedCase extends DataObject
{
   static $has_one = array(
      'CaseHolder' => 'CaseHolder'
   );   

   //Function to create the link to THIS particular Object
   function Link(){
      
      //This is the page that can display the DO and which it is accociated
      $Holder = $this->CaseHolder();
      
      $Link = $Holder->Link() . 'retrieve_case/' . $this->ID;
      
      return $Link;
   }

   //Other stuff in the DataObject

}

If you still cant get it to work, paste the code for both the holder and the DO in something like pastie.com.

Aram

Avatar
Enclave SSC

Community Member, 31 Posts

29 July 2010 at 9:47am

Edited: 29/07/2010 10:01am

UPDATE: Thanks a million aram. I got it working!!!

Now just to index files and I am one happy noob :P

Avatar
Carbon Crayon

Community Member, 598 Posts

29 July 2010 at 10:02am

Edited: 29/07/2010 10:04am

EDIT: lol just seen your last post, great news :) Ill let you know if I get mine going!

Hi Enclave,

try this: http://pastebin.com/ci3nSgqH

I removed the relationships altogether as they were not needed (i'm guessing ur using ModelAdmin for managing complaints, then rendering them based on Type?).

So the Link() function grabs a holder based on type then builds the link off that.

Aram

Avatar
Enclave SSC

Community Member, 31 Posts

30 July 2010 at 12:14am

@aram Thanks for all the help, shout if you need any with the sphinx process.

@mark I pasted my DO code here: http://pastebin.com/TkMuT7hL

I still cannot manage to index 'Document' => 'File' on my DecidedCases DO. FileContentCache remains clear. I am not sure if my relationships are setup correctly or whether I am understanding the application of your code incorrectly.