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

Friday, April 22, 2022

[FIXED] How to get another model data in cakephp without relation?

 April 22, 2022     cakephp, cakephp-2.3     No comments   

Issue

I have two table patients and diagnosis in patients add form I am trying to search diagnosis list for making a cart.Here they have no any relation. Output like this

enter image description here

I have tried bellow code for search this item

In patients/add

 <?php
   echo $this->Form->input('Search',array( 'class'=>'form-control','label' => false,'placeholder'=>'Search Diagnosis Name By Name','id'=>'search','style'=>"border:1px solid gray;"));
 ?>

Then I have applied bellow jquery code.

$('#search').keyup(function(){
            var value=$('#search').val();

            $.get("<?php echo   Router::url(array('controller'=>'Patients','action'=>'dsearch'));?>",{search:value},function(data){
                                $('.search_data').html(data);
            });
      });

In patients controller I have written bellow method,I have used loadModel in here but it's not working.

public function dsearch()
    {
            $this->loadModel('Diagnosi');
            if(isset($this->request->query['search'])){
            $search = $this->request->query['search'];
        }
        else{
                $search = '';
            }
        $this->Paginator->settings = array(
            'conditions' => array('Diagnosi.name LIKE' => "%$search%"),
            'limit'=>4
        );
        $this->set('diagnosis',$this->Paginator->paginate());
    }

Here it's searching name field from diagnosis if there have a relation.How I can search this without using relation model.


Solution

$this->set('diagnosis',$this->Paginator->paginate('Diagnosi'));


Answered By - Salines
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

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