Re: Creating a simple search form

2010-03-22 Thread aveev

Thank you very much Burns, it works now..here's the code:
in people_controller.php
function search() {}
function result() {
if(!empty($this->data)) {

$data =
$this->Person->find('all',array('conditions'=>array('Person.id'=>
$this->data['Person']['id'])));
$this->set('result', $data);
} else {

$this->redirect(array('controller'=>'people','action'=>'search'));
}
}

in search.ctp
create('Person', array('action'=>'result'));

echo $form->input('Person.id',array('type' => 'text'));
echo $form->end('Save');
?>

in result.ctp



Jeremy Burns wrote:
> 
> The variable is being destroyed when you redirect. I would change the
> action to one that finds the data (in your example this is process). Check
> for $this->data. If it's empty there are no search criteria so redirect to
> your search page. If it's not empty, do your find and put the results into
> a variable ($results?). Then have a view called process.ctp (at this
> point, having a function and view called process sounds wrong - 'results'
> sounds more intuitive?). In the view, you can pick up your $results and
> display them.
> 
> Jeremy Burns
> jeremybu...@me.com
> 
> 
> On 20 Mar 2010, at 12:32, aveev wrote:
> 
>> 
>> Hi, I'm new in using cakephp
>> I'm trying to create a simple search form for user table (namely
>> people),where I input the id, and then a page displaying the result will
>> show up...Here's I've come up with:
>> 
>> CREATE TABLE  `people` (
>>  `id` int(10) unsigned NOT NULL auto_increment,
>>  `name` varchar(30) NOT NULL,
>>  `pob` varchar(25) default NULL,
>>  PRIMARY KEY  (`id`)
>> )
>> in search.ctp
>> >  echo $form->create('Person', array('action'=>'search'));
>>  echo $form->input('id', array('type'=>'text'));
>>  echo $form->end('Save');
>> 
>> ?>
>> 
>> in people_controller.php
>> function search() {
>>  if(!empty($this->data)) {
>>  $data =
>> $this->Person->find('all',array('conditions'=>array('id'=>$this->data['Person']['id'])));
>>  $this->set('res',$data);
>>  
>> $this->redirect(array('controller'=>'people','action'=>'process'));
>>  }
>>  }
>> 
>> function process() {}
>> 
>> in process.ctp
>> >  echo $res;
>> ?>
>> when I key in the id in search.ctp and hit save button, the error message
>> displays :
>> Notice (8): Undefined variable: res [APP\views\persons\process.ctp, line
>> 5]
>> 
>> In search function I set the query result to a variable named res, and
>> redirect to another controller action, which is process..From what I've
>> read
>> in the manual, putting set method is the way we pass data to the view so
>> I
>> think it should be ok, but the res variable is not recognized in
>> process.ctp
>> view...
>> Any help would be greatly appreciated...
>> Thanks in advance...
>> 
>> -- 
>> View this message in context:
>> http://old.nabble.com/Creating-a-simple-search-form-tp27954861p27954861.html
>> Sent from the CakePHP mailing list archive at Nabble.com.
>> 
>> Check out the new CakePHP Questions site http://cakeqs.org and help
>> others with their CakePHP related questions.
>> 
>> You received this message because you are subscribed to the Google Groups
>> "CakePHP" group.
>> To post to this group, send email to cake-php@googlegroups.com
>> To unsubscribe from this group, send email to
>> cake-php+unsubscr...@googlegroups.com For more options, visit this group
>> at http://groups.google.com/group/cake-php?hl=en
>> 
>> To unsubscribe from this group, send email to
>> cake-php+unsubscribegooglegroups.com or reply to this email with the
>> words "REMOVE ME" as the subject.
> 
> Check out the new CakePHP Questions site http://cakeqs.org and help others
> with their CakePHP related questions.
> 
> You recei

Re: Creating a simple search form

2010-03-20 Thread Jeremy Burns
The variable is being destroyed when you redirect. I would change the action to 
one that finds the data (in your example this is process). Check for 
$this->data. If it's empty there are no search criteria so redirect to your 
search page. If it's not empty, do your find and put the results into a 
variable ($results?). Then have a view called process.ctp (at this point, 
having a function and view called process sounds wrong - 'results' sounds more 
intuitive?). In the view, you can pick up your $results and display them.

Jeremy Burns
jeremybu...@me.com


On 20 Mar 2010, at 12:32, aveev wrote:

> 
> Hi, I'm new in using cakephp
> I'm trying to create a simple search form for user table (namely
> people),where I input the id, and then a page displaying the result will
> show up...Here's I've come up with:
> 
> CREATE TABLE  `people` (
>  `id` int(10) unsigned NOT NULL auto_increment,
>  `name` varchar(30) NOT NULL,
>  `pob` varchar(25) default NULL,
>  PRIMARY KEY  (`id`)
> )
> in search.ctp
>echo $form->create('Person', array('action'=>'search'));
>   echo $form->input('id', array('type'=>'text'));
>   echo $form->end('Save');
> 
> ?>
> 
> in people_controller.php
> function search() {
>   if(!empty($this->data)) {
>   $data =
> $this->Person->find('all',array('conditions'=>array('id'=>$this->data['Person']['id'])));
>   $this->set('res',$data);
>   
> $this->redirect(array('controller'=>'people','action'=>'process'));
>   }
>   }
> 
> function process() {}
> 
> in process.ctp
>echo $res;
> ?>
> when I key in the id in search.ctp and hit save button, the error message
> displays :
> Notice (8): Undefined variable: res [APP\views\persons\process.ctp, line 5]
> 
> In search function I set the query result to a variable named res, and
> redirect to another controller action, which is process..From what I've read
> in the manual, putting set method is the way we pass data to the view so I
> think it should be ok, but the res variable is not recognized in process.ctp
> view...
> Any help would be greatly appreciated...
> Thanks in advance...
> 
> -- 
> View this message in context: 
> http://old.nabble.com/Creating-a-simple-search-form-tp27954861p27954861.html
> Sent from the CakePHP mailing list archive at Nabble.com.
> 
> Check out the new CakePHP Questions site http://cakeqs.org and help others 
> with their CakePHP related questions.
> 
> You received this message because you are subscribed to the Google Groups 
> "CakePHP" group.
> To post to this group, send email to cake-php@googlegroups.com
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
> http://groups.google.com/group/cake-php?hl=en
> 
> To unsubscribe from this group, send email to 
> cake-php+unsubscribegooglegroups.com or reply to this email with the words 
> "REMOVE ME" as the subject.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Creating a simple search form

2010-03-20 Thread aveev

Hi, I'm new in using cakephp
I'm trying to create a simple search form for user table (namely
people),where I input the id, and then a page displaying the result will
show up...Here's I've come up with:

CREATE TABLE  `people` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `name` varchar(30) NOT NULL,
  `pob` varchar(25) default NULL,
  PRIMARY KEY  (`id`)
)
in search.ctp
create('Person', array('action'=>'search'));
echo $form->input('id', array('type'=>'text'));
echo $form->end('Save');

?>

in people_controller.php
function search() {
if(!empty($this->data)) {
$data =
$this->Person->find('all',array('conditions'=>array('id'=>$this->data['Person']['id'])));
$this->set('res',$data);

$this->redirect(array('controller'=>'people','action'=>'process'));
}
}

function process() {}

in process.ctp

when I key in the id in search.ctp and hit save button, the error message
displays :
Notice (8): Undefined variable: res [APP\views\persons\process.ctp, line 5]

In search function I set the query result to a variable named res, and
redirect to another controller action, which is process..From what I've read
in the manual, putting set method is the way we pass data to the view so I
think it should be ok, but the res variable is not recognized in process.ctp
view...
Any help would be greatly appreciated...
Thanks in advance...

-- 
View this message in context: 
http://old.nabble.com/Creating-a-simple-search-form-tp27954861p27954861.html
Sent from the CakePHP mailing list archive at Nabble.com.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.