Displaying filter from another view

3

I have View where the customer data is shown, and when you click a button, the user is redirected to a page that shows the movements of several clients, so that page contains some filters. So what I need is that when that client clicks on the button and is redirected to the page with the filters, it will filter the items pertaining to it.

For example:

<center><strong>--Simulando--</strong></center><br>
<i>Ao clicar no botão, da 'View', abrirá a página 'Nfse', pertencente à outra controller.</i>
<hr>
<br><br>
<strong><i>VIEW:</i></strong> <br><br>

<table border='1'>
  <tr>
    <th>Cliente</th>
    <th>Cnpj</th>
    <th>Nfes emitidas</th>
  </tr>
  <tr>
    <td>XX SERVICOS</td>
    <td>00000000000100</td>
    <td><center><button>Nfes</button></center></td>
  </tr>
</table>
<br><br>
<i> Ao clicar no botão <button>Nfes</button> será redirecionado para ...</i>
<br><br>

<strong><i>Nfes:</i></strong><br><br>

<input type='text' placeholder='nr.nfe'>
<input type='text' placeholder='cnpj emitente' value='00000000000100'> <small><small>#Este campo deverá vir preenchido#</small></small>
<input type='text' placeholder='dt emissao'>
<input type='button' value='Filtrar'>

<br><br>
<i>Trazendo como resultado esses dados simulados!</i>
<br><br>
<table border='1'>
  <tr>
    <th>Nr.nfe</th>
    <th>cnpj emitente</th>
    <th>dt emissao</th>
  </tr>
  <tr>
    <td>11324</td>
    <td>00000000000100</td>
    <td>31/01/2017</td>
  </tr>
  <tr>
    <td>11323</td>
    <td>00000000000100</td>
    <td>28/01/2017</td>
  </tr>
  <tr>
    <td>11322</td>
    <td>00000000000100</td>
    <td>15/01/2017</td>
  </tr>
</table>

If it's two controller different, I can not find a solution to this, could it collaborate with some idea or correction?

    
asked by anonymous 07.02.2017 / 19:22

2 answers

1

I can collaborate with the following idea:

On your View replace the <button>Nfes</button> element with Helper FormHelper::postLink . It has the following format:

  

FormHelper :: postLink (      string $ title,      mixed $ url = null,      array $ options = array ()     );

     

Creates an HTML link, but accesses the URL using the POST method. Requires JavaScript to be enabled in the browser.

     

This method creates a <form> element. If you want to use this method within an existing form, you must use the inline or block options so that the new form can be rendered outside of the existing form. [ Book Cakephp, 2017 , p. 136].

<!-- File: /app/View/ControllerUm/sua-view.ctp -->
<td class="actions">
    <?php 
        echo $this->Form->postLink(
            __('Nfes'),
            //mixed $url = null 
            array(
                'controller' => 'ControllerDois',
                'action' => 'actionOfWork', 
                ['client_id' => $client['Client']['id']]
            ),
            //array $options = array ()
            array(
                'inline' => true,
                'class' => 'demo'
                //'confirm': "Sua mensagem de confirmação, vem aqui se necessário",
            )
        ); 
    ?>
</td>

The above button will make a post passing the client ID to the specified URL.

<!-- File: /app/Controller/ControllerUn/ControllerDois.php -->
 /**
 * A action no seu ControllerDois que vai receber o post.
 *
 * @return void
 */
 public function actionOfWork() {
    if ($this->request->is('post')) {
        $this->Client->id = $this->request->data['client_id'];
        if (!$this->Client->exists()) {
            throw new NotFoundException(__('Cliente inválido'));
        }

        /** 
         * Aqui você vai usar o seu algoritmo de trabalho da aplicação 
         */

        $dataClientFilter = $this->Client->find('list');
        $this->set(compact('dataClientFilter'));

        /** 
         * Em teoria o CakePHP vai mandar os dados filtrados para serem renderizados 
         * pela View: /app/View/ControllerDois/actionOfWork.ctp. 
         *
         */
    }
 }

If I understood your question well, I believe that it is!

Reference : [Book Cakephp, 2017], Available at: Book Cakephp - FormHelper :: postLink . Access: Apr 05, 2017.

    
05.04.2017 / 18:20
3

From what I understand, you do not know the helpers. They make it easy to implement the code, and do it all for you, passing php data and assembling the html structure with that data. Sorry if I misunderstood.

If you have not tried, you can make a link redirecting to the view of the other controller, passing some parameters referring to the client that should be filtered.

$html->link(/* o botão */, 
    ['controller' => /* o controller */, 
    'view' => /* a view */, 
     $parametro1, 
     $parametro2]);

The controller and view is where you want to redirect the client and if you have more parameters, just put more, separated by commas. Remember that these are the parameters that are available in the function of your controller. I put it generically because I do not know exactly how your structure is. I hope I have helped.

    
04.04.2017 / 13:13