Monday, October 31, 2011

Re: Implementing a search functionality

I didn't search there. I used another little know search engine called Joogle (or something like that): http://cakedc.com/downloads/view/cakephp_search_plugin

Jeremy Burns
Class Outfit

http://www.classoutfit.com

On 31 Oct 2011, at 13:30, Yves S. Garret wrote:

I looked in the book on cakephp.org and didn't find the search behavior.  Do you mean some other book?  Did I miss what you're describing?

On Fri, Oct 28, 2011 at 10:38 PM, Jeremy Burns | Class Outfit <jeremyburns@classoutfit.com> wrote:
The answer (again) is in the error message. 'set' is a controller function and you are using it in a behaviour. set 'sets' a variable in the controller and passes it to the view. Here's the chain of events:

- user clicks a link or submits a form to a specified url
- that url is routed to a controller action (/controller/action/[parameters])
- the controller action does the stuff you tell it to
- this usually means calling some model functions, in your case the search method of the Provider model
- the model can use a behaviour method, in your case the search method of the Searchable behaviour (when a behaviour is attached to a model its methods are available as if they were native to the model)
- the model/behaviour performs database activity/business logic and returns variables to the calling controller function (note: 'return')
- the controller function receives those variables and 'sets' them ready for the view
- the controller then renders the view (generally of the same name as the controller action)
- the view renders html and can refer to the variables set and passed by the controller

Your code is not doing this.

Yves - can I recommend that you read the Cookbook? Amongst other things there is a really good Searchable behaviour out there that will do what you need.

Jeremy Burns
Class Outfit

http://www.classoutfit.com

On 28 Oct 2011, at 22:11, Yves S. Garret wrote:

This is the structure of my folder tree and all of the pertinent files:
app\
  controllers\
    providers_controller.php [  http://bin.cakephp.org/view/1496172779  ]
  models\
    behaviors\
      searchable.php [  http://bin.cakephp.org/view/1269850925  ]
    provider.php [  http://bin.cakephp.org/view/1936681668  ]
  views\
    providers\
      view_admit_lookup.ctp [  http://bin.cakephp.org/view/1887805610  ]

The issue that I'm having is that when I try to search (say the word Smith), I get this error:

Fatal error: Call to undefined method SearchableBehavior::set() in D:\Inetpub\wwwroot-clinical\pythia-admit-lookup\app\models\behaviors\searchable.php on line 4

I find this confusing.  I'm already setting the last_name in my view... so shouldn't it be grabbing that info?

On Tue, Oct 25, 2011 at 3:00 PM, Yves S. Garret <yoursurrogategod@gmail.com> wrote:
Jeremy, thanks for your help.  I'll take the time to go through the blog tutorial at the moment.  I was kind of forced into this development process with little prep work or understanding of what's going on (the same would be to have you write a project in APL :-] ).

I'll get back to this thread after learning more about how Cake works and what it is capable of.


On Tue, Oct 25, 2011 at 2:30 PM, Jeremy Burns | Class Outfit <jeremyburns@classoutfit.com> wrote:
Your controller function sets variables and passes them to a view of the same name as the function. In your case, your function is called search_admit_lookup, so it will try to render a view called search_admit_lookup. That view will contain the logic to present whatever variables are set in the function and passed to the view. You can use whatever html you want in the view.


Jeremy Burns
Class Outfit

http://www.classoutfit.com

On 25 Oct 2011, at 18:23, Yves S. Garret wrote:

It does not.  What I would like to do is to output the search results on a table right below the text box and search button.

Gonna look into that now.

On Tue, Oct 25, 2011 at 12:46 PM, Jeremy Burns | Class Outfit <jeremyburns@classoutfit.com> wrote:
The clue is in the error. Does that view exist? Your bin paste shows view_admit_lookup.ctp, not search_admit_lookup.ctp.


Jeremy Burns
Class Outfit

http://www.classoutfit.com

On 25 Oct 2011, at 17:34, Yves S. Garret wrote:

Well, as annoying as it sounds, I just cleaned up the mess that was my previous implementation.

When I run the search, I'm getting this error:

Error: The view for ProvidersController::search_admit_lookup() was not found.

Error: Confirm you have created the file: D:\Inetpub\wwwroot-clinical\pythia-admit-lookup\app\views\providers\search_admit_lookup.ctp

Notice: If you want to customize this error message, create app\views\errors\missing_view.ctp


I got a meeting that I need to be at, I'll have a look after about 2 hours (hopefully it ends by then).


On Tue, Oct 25, 2011 at 11:38 AM, Jeremy Burns | Class Outfit <jeremyburns@classoutfit.com> wrote:
It's OK....

Yup - looks better now, and you are right you are setting the provider variable - I was looking at the wrong function. ^^

So are you all in the clear now?


Jeremy Burns
Class Outfit

http://www.classoutfit.com

On 25 Oct 2011, at 16:26, Yves S. Garret wrote:

Oh, wait, God that was one hell of a copy/paste goof.  Sorry about that.

provider.php (Model):
providers_controller.php (Controller):
view_admit_lookup.ctp (View):


On Tue, Oct 25, 2011 at 11:07 AM, Jeremy Burns | Class Outfit <jeremyburns@classoutfit.com> wrote:
OK - but you still haven't applied all of the changes I outlined.

This line in your controller:
  1.     function view_admit_lookup() {
  2.         $this->set('provider'$this->paginate());

...is setting a variable called $provider with a value. That will be available in the view (view_admit_lookup) as $providers.

In your view you are looping through a variable called $Providers.

 <?php foreach ($Providers as $i => $prov)?>

$providers does not equal $Providers.

I'd change the controller to:

  1.     function view_admit_lookup() {
  2.         $this->set('providers'$this->paginate());

... and the view to

 <?php foreach ($providers as $i => $prov)?>

Also see my comment about your form name in the view (and the use of $form). To save you the tiresome task of actually reading anything and carrying out the instructions, let me correct it for you:

  1.     echo $this->Form->create("Provider"array('action' => 'search'));
  2.     echo $this->Form->input("doc_last_name"array('label' => 'Doctor Last Name'));
  3.     echo $this->Form->submit('Search');
  4.     echo $this->Form->end();

Also, the form is specifying that it posts to an action 'search' - does this exist in your providers controller? I can't see it.


Jeremy Burns
Class Outfit

http://www.classoutfit.com

On 25 Oct 2011, at 15:57, Yves S. Garret wrote:

Yes, they're wrong.  But being new I was sure how correct/incorrect my approach was.  I'm working off of the stuff of another developer (who made the said file names).

This is what I have setup now:

app\
  controllers\
    providers_controller.php
  models\
    provider.php
  views\
    providers\
      view_admit_lookup.ctp

provider.php:
http://bin.cakephp.org/view/1833911095
providers_controller.php:



On Tue, Oct 25, 2011 at 10:10 AM, Jeremy Burns | Class Outfit <jeremyburns@classoutfit.com> wrote:
Why. Not. Read. My. Post? And the guide? With the link I sent you?

From this tree I can tell you that the model file should be lower case and that view is not named correctly. Lower case, with underscores, to match the controller function name (as I mention in my post(s)).

Once you have read the answers to your questions, applied the advice and adhered to conventions, please come back with any other errors.


Jeremy Burns
Class Outfit

http://www.classoutfit.com

On 25 Oct 2011, at 14:19, Yves S. Garret wrote:

This time I'll include the file names and where they are:

app\
  controllers\
    providers_controller.php (has ProvidersController class)
  models\
    Provider.php (has Provider class)
  views\
    providers\
      viewAdmitLookup.ctp (contains all of the view display stuff)

On Tue, Oct 25, 2011 at 9:16 AM, Yves S. Garret <yoursurrogategod@gmail.com> wrote:
Thanks, this is the structure of my directory tree, tell me if I need to re-name anything:

app\
  controllers\
  models\
  views\
    providers\

Should I rename the providers directory to provider?


On Mon, Oct 24, 2011 at 11:33 PM, Jeremy Burns | Class Outfit <jeremyburns@classoutfit.com> wrote:
Your conventions are all over the place. Its best to stick to them.

Did you change the code inside the controller as suggested in my first post?

  1. class ProvidersController extends AppController {
  2.     var $name = 'Providers';

The filename is view_admit_lookup, yet the controller function is viewAdmitLookup - they should match. Change the function name to view_admit_lookup

In the view, you have this:

echo $form->create("Providers"array('action' => 'search'));

It'll create a form that tries to find the Providers model, not the Provider model. Change it to:

echo $form->create("Provider"array('action' => 'search'));

Change Providers to Provider throughout the view code.

In your controller function you have $this->set('providers'... which sends a variable $providers into the view, yet in the view you are iterating through a variable called $Providers. Change the variable in the view to $providers.

Your are using $form-> when you should be using $this->Form (that's the syntax for helpers in general, so $this->Html etc).

See this section of the book on conventions:


You can deviate from them with additional work, but it is not worth the effort else you'll run into issues like this.


Jeremy Burns
Class Outfit

http://www.classoutfit.com

On 24 Oct 2011, at 22:39, Yves S. Garret wrote:

Ok, now I'm getting this when I turned everything to plural.

Missing Controller

Error: ProviderController could not be found.

Error: Create the class ProviderController below in file: app\controllers\provider_controller.php

<?php class ProviderController extends AppController {  	var $name = 'Provider'; } ?> 

Notice: If you want to customize this error message, create app\views\errors\missing_controller.ctp


Model:

http://bin.cakephp.org/view/361596401

View:

http://bin.cakephp.org/view/1786526282

Controller:

http://bin.cakephp.org/view/1385185838


On Mon, Oct 24, 2011 at 4:56 PM, Yves S. Garret <yoursurrogategod@gmail.com> wrote:
Yup.  CakePHP 1.3.  The view is in \app\views\providers\view_admit_lookup.ctp

The controller file name is providers_controller.php.  I added the variable that you suggested to the model file (which is called Provider.php) and I get the same error :-( .


On Mon, Oct 24, 2011 at 2:03 PM, Jeremy Burns | Class Outfit <jeremyburns@classoutfit.com> wrote:
Did you change anything? This is 1.3, right?

The filename should be providers_controller.php
Change the code as per my post below.
The view should be in /app/views/providers/
Add $var $name = 'Provider'; to the beginning of the Provider model file.


Jeremy Burns
Class Outfit

http://www.classoutfit.com

On 24 Oct 2011, at 18:40, Yves S. Garret wrote:

This is my view:
This is my controller:
This is my model:

This is the error that I'm getting:

Missing Controller

Error: ProviderController could not be found.

Error: Create the class ProviderController below in file: app\controllers\provider_controller.php

<?php class ProviderController extends AppController {  	var $name = 'Provider'; } ?> 

Notice: If you want to customize this error message, create app\views\errors\missing_controller.ctp


:-/


On Mon, Oct 24, 2011 at 1:31 PM, Jeremy Burns | Class Outfit <jeremyburns@classoutfit.com> wrote:
Your controller names should be plural; try:

  1. class ProvidersController extends AppController {
  2.     var $name = 'Providers';


Jeremy Burns
Class Outfit

http://www.classoutfit.com

On 24 Oct 2011, at 18:24, Yves S. Garret wrote:

Ok, this is weird.

I found this tutorial on doing searches.

That's good.  Now, this is my Model:
View:
Controller:

Now, when I run the search based on someone, I get something like this:

Missing Controller

Error: ProvidersController could not be found.

Error: Create the class ProvidersController below in file: app\controllers\providers_controller.php

<?php class ProvidersController extends AppController {  	var $name = 'Providers'; } ?> 

Notice: If you want to customize this error message, create app\views\errors\missing_controller.ctp

Now, I don't have Providers, I have Provider (singular only), so where is it getting the plural from?







On Fri, Oct 21, 2011 at 12:30 PM, Yves S. Garret <yoursurrogategod@gmail.com> wrote:
My question in that case would be, why am I getting that error?


On Thu, Oct 20, 2011 at 5:12 PM, Yves S. Garret <yoursurrogategod@gmail.com> wrote:
I have a decent understanding of what the tutorial is trying to do.  However, trying it to move it into my project is my present issue.

Here is my model:
Here is my controller:
Here is my view:

The issue that I get when I run Search:

Missing Controller

Error: ProvidersController could not be found.

Error: Create the class ProvidersController below in file: app\controllers\providers_controller.php

<?php class ProvidersController extends AppController {  	var $name = 'Providers'; } ?> 

Notice: If you want to customize this error message, create app\views\errors\missing_controller.ctp


provider_controller.php has a var $name = 'Providers'; as the name... 


On Tue, Oct 18, 2011 at 3:27 PM, Dee Johnson <devariojay@gmail.com> wrote:
my apologies, I saw where you said you wanted to make the tutorial simpler and i assumed that you already knew how to make calls etc. 

The tutorial is using a search behavior (which probably does the calls - i haven't looked to verify)

but to answer your question from above, I would recommend doing the tutorial OUTSIDE of your current project just to familiarize yourself with what it is asking you to do. 

Once you get that up and running you would have a much better understanding of what direction you would rather go in as a developer. 

so...yes...follow all steps in the tut. 

Now, if you are going away from the tutorial, you can just the data that comes back in the $this->data collection from your search box in the view and use that model call I used above.  If you dont understand this last bit, it is best you try the tutorial out first with a fresh install etc...so as not to disrupt your project or in the very least back it up.


--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php




--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php


--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php


--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php


--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php



--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php


--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php



--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php


--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php


--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php


--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php


--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php


--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php


--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php


--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php


--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php


--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php



--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php


--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php


--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: