PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, January 16, 2022

[FIXED] cakephp: plumSearch - Changing filter's label in parameters

 January 16, 2022     cakephp, cakephp-3.x, plugins     No comments   

Issue

Using PlumSearch plugin, it is mentioned in its documentation that we can modify 'label':

formConfig: Contains Form::input $options settings like class, input type, label name...

In my controller/initialize(), I need to change the label of some fields ("IP Address" instead of "Ip Adress", "Status" instead of "Asset Status"):

public function initialize()
{
parent::initialize();

$parameters = [
    ['name' => 'serial_number', 'className' => 'Input'],
    ['name' => 'model_number', 'className' => 'Input'],
    ['name' => 'ip_address', 'label' => 'IP Address', 'className' => 'Input'],
];
if ($this->request->param('action') == 'reportFacility') {
    $statuses = $this->AssetsAssignations->AssetStatuses->find('list')->order(['name' => 'asc']);
    $this->set(compact('asset_statuses'));
    $parameters = [
        ['name' => 'asset_status_id', 'className' => 'Select', 'label' => 'Status',
            'finder' => $statuses
        ],
    ];
}   elseif ($this->request->param('action') == 'reportClient') {
    $clients = $this->AssetsAssignations->Clients->find('list')->order(['last_name' => 'asc', 'first_name' => 'asc']);
    $this->set(compact('clients'));
    $parameters = [
        ['name' => 'client_id', 'className' => 'Select', 'label' => 'Client',
            'finder' => $clients
        ],
    ];
} elseif ($this->request->param('action') == 'reportRoom') {
    $rooms = $this->AssetsAssignations->Rooms->find('list')->order(['name' => 'asc']);
    $this->set(compact('rooms'));
    $parameters = [
        ['name' => 'room_id', 'className' => 'Select', 'label' => 'Room',
            'finder' => $rooms
        ],
    ];
}
$this->loadComponent('PlumSearch.Filter', ['parameters' => $parameters]);

}`

The code above did not work for labels.

I was told to use the following code:

 $inputOptions = [
        'search' => [
            'placeholder' => __('Type to search...'),
            'class' => 'form-control',
            'label' => 'Search'
        ]
    ];
    $this->set(compact('inputOptions'));

but I failed to determine where and how in my code.

Any help please ?


Solution

simply you have to add it to the $parameters array this way

$parameters = [
    /* other fields here */
    [
        'name' => 'ip_address', 
        'className' => 'Input', 
        'formConfig' => ['label' => 'IP Address']
    ],
];


Answered By - arilia
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing