You want to make search, it result code contain with registration and
paginate right ? seems you must learn about containable behavior.
In CodesController
$codeId = $this->Codes->find('list',array('conditions'=>
array("MATCH(Code.name) AGAINST('$input' IN BOOLEAN
MODE)"),'fields'=>'Code.id'));
$this->paginate = $this->Code->paginateSearch();
$this->set('codes',$this->paginate('Code',array('Code.id'=>$codeId)));
In CodeModel :
var $actsAs = array('Containable');
/**
* Pagination search result
* PhotoAlbums controller -> search()
* @return Array
*/
function paginateSearch($id = array())
{
$this->recursive = '0';
$result = array(fields'=>'Code.id,Code.name',
'contain' =>
array('RegistrationCodes'=>array(
'fields'=>array('RegistrationCodes.id,RegistrationCodes.code_id,RegistrationCodes.registration_id'),
)),
'limit' => 10
);
return $result;
}
Regards,
yodi
On Fri, 2009-04-17 at 12:30 -0700, Chez17 wrote:
> I am trying to create a search function and paginate the results. For
> all the standard fields, this is an easy task. I have one situation
> that is causing me a ton of headaches and any help you can give is
> most appreciated. Here is the setup:
>
> Registrations
> - hasMany RegistrationCodes
>
> RegistrationCodes
> -belongsTo Registration
> -belongsTo Code
> -this table has the fields registration_id and code_id
>
> Codes
> -hasMany RegistrationCodes
>
> So most registrations have no more than 2 codes, the code it self is
> stored in the codes table, and information about the codes is stored
> in the registration codes table(ex: type of code, registration_id,
> etc...). There are a lot of pirated codes so it makes sense to store
> the code once and keep track of the info and linking in the
> registration codes table.
>
> I am searching over the standard fields in Registrations, name, email,
> phone, etc... and the only field I'm searching for that is outside the
> table is the code. Now I want to be able to enter a code in the search
> bar and have the results lumped in with all the other results, but I
> am having huge issues doing this. Since cake doesn't automatically
> enter in the table from hasMany results I need to do some cake magic.
> This doesn't work:
>
> $conditions[] = array('Code.code LIKE' => $this->data['Registration']
> ['search']."%");
>
> I have looked in to containbles but I'm not sure I understand this at
> all. I also thought of trying to do stuff in the beforeFind method but
> I can't find any good help on that. Would this help with pagination?
> Is it possible to create temporary fields in the Registration table
> and populate it with the codes? Then search over that?
>
> Can someone point me in the right direction here, I am very lost and
> need help. Any help is most appreciated.
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---