logo
down
shadow

How to filter associated HABTM data with FriendsOfCake Search for CakePHP 3


How to filter associated HABTM data with FriendsOfCake Search for CakePHP 3

By : trin0042
Date : November 22 2020, 02:59 PM
this will help The available search methods rely on the field being available in the main query (hasMany and belongsToMany associations are being being retrieved in separate queries).
While you could join it in manually in the controller, using a callback- or a finder-filter is probably the better approach, that way you can modify the query in the model layer, and you could easily utilize Query::matching() to filter by associated data.
code :
use Cake\ORM\Query;
use Search\Type\Callback; // This changed in master recently
                          // now it's Search\Model\Filter\Callback

// ...

public function searchConfiguration()
{
    $search = new Manager($this);

    $search
        // ...
        ->callback('painting', [
            'callback' => function (Query $query, array $args, Callback $type) {
                return $query
                    ->distinct($this->aliasField('id'))
                    ->matching('Paintings', function (Query $query) use ($args) {
                        return $query
                            ->where([
                                $this->Paintings->target()->aliasField('id') => $args['painting']
                            ]);
                    });
            }
        ]);

    return $search;

}


Share : facebook icon twitter icon
How do I write data to a HABTM association of a HABTM join table in CakePHP?

How do I write data to a HABTM association of a HABTM join table in CakePHP?


By : user1133988
Date : March 29 2020, 07:55 AM
it helps some times I figured it out. Cake saveAll function works only for directly associated models. Luckily Cake is able to take care of this:
view
code :
echo $form->input('Tags.Tags', array('multiple' => 'multiple', 'options' => $tags));
$this->Experience->saveAll($data, $parameters);
$this->Experience->ExperiencesUser->save($data);
CakePHP HABTM: Editing one item casuses HABTM row to get recreated, destroys extra data

CakePHP HABTM: Editing one item casuses HABTM row to get recreated, destroys extra data


By : tatsuyaoiw
Date : March 29 2020, 07:55 AM
hop of those help? I'm having trouble with my HABTM relationship in CakePHP. , From the CookBook the 1st problem is:
code :
$this->Location->unbindModel(
    array('hasAndBelongsToMany' => array('Department'))
);
How to Filter Associated Data using FriendsOfCake Search plugin for CakePHP 3.1.0

How to Filter Associated Data using FriendsOfCake Search plugin for CakePHP 3.1.0


By : Diman Pukhov
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Simply either do not use aliasField() when you're already supplying the alias
code :
'field' => 'Users.first_name'
'field' => $this->Users->target()->aliasField('first_name')
Unable to install Search plugin for CakePHP by Friendsofcake

Unable to install Search plugin for CakePHP by Friendsofcake


By : prppedro
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , you probably meant to change $this->set('articles', $this->paginate($query)); to $this->set('users', $this->paginate($query)); in your UsersController. Also change class UsersTable extends Cake\ORM\Table in UsersTable to class UsersTable extends Table - there may be more errors like this for you to check in your code with the standard examples for the plugin.
CakePHP Friendsofcake search ajax results

CakePHP Friendsofcake search ajax results


By : Dwayne
Date : March 29 2020, 07:55 AM
I hope this helps . This works if I leave the URL blank and use GET instead of POST - should've thought of that sooner.
code :
echo $this->Form->create('Treasure',['id'=>'myForm']);
...
?>

 <script>
$( "#myForm" ).submit(function( event ) {
   event.preventDefault();
   $.ajax({
     async:true,
     data:$(this).serialize(),
     dataType:"html",
     success:function (data, textStatus) {
       $(".ajax-result").html(data);
     },
     type:"GET"
    });
 </script>
Related Posts Related Posts :
  • Generating all 6 character alphanumeric combinations (upper and lower case)
  • PHP: Swap placeholders in string variable for corresponding defined variable values
  • HTTP request failed! with file get contents
  • How can I manipulate include_once string?
  • Database table not created after running plugin:refresh
  • Sphinx Get Word in Result through PHP API
  • Sending xml via soapclient in PHP
  • PHP class extension - skipping the middle class by calling the parent of the parent
  • Save data from contentEditable div with mysqli
  • Generating a PDF with sequential order images FPDF
  • How to make a request with PHPLeague oAuth2 client?
  • MySQL count rows with two duplicate column values
  • How to send a curl request with pem certificate via PHP?
  • Request error when processing form in controller
  • Can't save xml file content in mysql with fopen/fwrite/fclose (php)
  • Read only Title from a page?
  • PHP - make echo permanent and visible to all viewers
  • composer fails on server with redmine installed
  • Using foreach With Variables on Smarty
  • How do you specify single print blocks when looping through a 'for' loop?
  • PHP: $_FILES returns empty
  • Symfony2 associative array in entity
  • How do I log every output from a PHP script from the command line?
  • How to implement this json feed into a database structure?
  • Codeigniter, windows, xampp, how to use htaccess to get rid of trailing slash?
  • How to disable Navbar and footer in Yii2 other layouts
  • Json not encode my Special Character
  • echo if POST length is low
  • Warning: require_once error
  • What is this code meaning...?
  • Send to /dev/null a PHP function "echo" output
  • How to store post details and timestamp in database?
  • php mysql - search a row and concatenate values of every columns to variable string
  • Write a program to get N number of positive non-zero integers, so that the sum and product of these numbers are equal
  • Running two multi line queries in PHP
  • PHP/ASP Trouble understanding
  • Strict standards notices View/Layout class
  • how to have backwards reference on PHP's regex?
  • Uncaught exception 'RuntimeException' with message 'Unable to load ZF2. Run `php composer.phar install` or define a ZF2_
  • phpDocumentor: DocBlock with @var tags duplicates descriptions
  • how to push an object to an array within an object with PHP
  • Undefined offset error in for loop
  • mysql query logic for fetching data from 3 related tables on certain condition
  • Saving blob video with php
  • SpeckPaypal ZF2 How to edit the CURRENCY CODE?
  • Check ALL $_POST lengths
  • PHP - Recursively set each array element's key to the value of a child element when given the childs key name
  • How to disable the user from entering wrong passwords
  • SilverStripe Custom Email Form - jQuery.ajax not passing variables to server
  • Regular expression to extract Facebook URL's inc vanity
  • Show Calculated Field on SuiteCRM Dashlet
  • Class 'NumberFormatter' not found error in simple PHP program
  • Is it necessary to set values to a variable two times?
  • Scan Barcode - Save Code in SQL Database
  • Fetch MySQLi with custom database (aka, column names for array keys)
  • Symfony2 PagerFantaBundle
  • Wordpress: Restrict file uploads by MIME type
  • Find key in array in a foreach
  • pdo select query wont works with string of letters
  • Check if atleast one character is in mysql row, using php
  • shadow
    Privacy Policy - Terms - Contact Us © animezone.co