Re: Moving data from a controller to a view after doing some queries

2008-03-25 Thread George C



Thank you sir, you are a saint!

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



Moving data from a controller to a view after doing some queries

2008-03-24 Thread George C

Hello!  It seems like my lack of knowledge of MVC is once again
holding me back.  I'm attempting to develop some code that searches
for users in the database and shows ones who's first or last names
match.  So, I have a function in my controller:

function findsomeone() {
if ($this->data)
{

$searchstring = $this->data['Client']['searchstring'];
$numwords = substr_count($searchstring, " ");
$fields = array(0 => 'id', 'first_name', 'last_name');
if($numwords > 0)
{
$searcharray = explode(" ",$searchstring);
$results = array();
foreach($searcharray as $saelement)
{
$conditions = "Client.first_name LIKE 
'" . $saelement .
"' OR Client.last_name LIKE '" . 
$saelement . "'";
$results = 
array_merge_recursive($results, $this->Client-
>findAll($conditions, $fields));
}
}
else
{
$conditions = "Client.first_name LIKE '" . 
$searchstring .
"' OR Client.last_name LIKE '" . $searchstring 
. "'";
$results = $this->Client->findAll($conditions, 
$fields);
}
//flatten the array, and then pull out all the 
duplicate entries
$flattened = array();
for($i = 0; $i < count($results); $i++)
{
array_push($flattened, $results[$i]['Client']);
}

array_multisort($flattened, SORT_ASC);

for($i=(count($flattened)-1); $i>0; $i--)
{
if($flattened[$i-1]['id'] == 
$flattened[$i]['id'])
{
array_splice($flattened, $i-1, 1);
}
}

// and here I'm stuck
}

}

So, $flattened has the data I want, and I know that in the view, I
should just be dropping code like "echo $client['Client']
[first_name'];" to display the first name, for example.  What's not
clear to me is how to pass that data back to the controller.

Looking at the index function that bake created for me, I see the
cryptic:

function index() {
$this->Client->recursive = 0;
$this->set('clients', $this->paginate());
}

and unfortunately, it's as clear as mud to me as to how that actually
works, and I can't find a good discussion of what it's doing, so I
can't figure out how to get my data from $flattened back to the view.
Can anyone tell me where I can find a good discussion of how to get
this to work?  Thanks in advance.

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



Re: enum

2008-03-04 Thread George C



On Jan 25, 8:32 am, MonkeyGirl <[EMAIL PROTECTED]> wrote:
> > How would you get the enum values from the model or controller?
>
> By far the easiest way is to go 
> tohttp://cakeforge.org/snippet/detail.php?type=snippet&id=112
> and copy and paste the code that's there into app_model.php, then you
> can just use lines like the following in your code:
>
> $types = $this->Album->getEnumValues('type');
>
> In this example, 'type' is the name of the enum column, Album is the
> model it's in, and 'types' is the variable that will automatically be
> picked up by this line in the view (assuming you're using Cake 1.2
> with its form helper):
>
> echo $form->input('type');
>
> This will give you a dropdown, just like the one you get for foreign
> keys.
>
> Hope that helps,
> Zoe.

Looks simple enough, but I'm very new to the whole Model-View-
Controller paradigm, so I can't quite make sense of this.

Adding the first part of that code into the app_model.php file is
straightforward enough, and I only need the "function add()" section
if I intend to use this functionality with Bake (right?) which I
currently don't.

So, would I want to say in some view:
$types = $this->Album->getEnumValues('type');
echo $form->input('type');
$labels = $this->Album->getEnumValues('label')
echo $form->input('label')

Or that's what I'd think to do at first glance, but it doesn't seem to
work - $this seems to point to the current "view" object and not the
"Album" object, which I suppose makes sense.  But then it's not clear
to me where the "$types = $this->Album->getEnumValues('type');" line
ought to go, if not in the view page.  Thanks in advance for any
clarification you can send my way!

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



Help configuring CakePHP 1.1 or 1.2 for a total CakePHP newbie

2008-02-24 Thread George C

Hello!

I'd like to get started using Cake, but so far I haven't had a lot of
luck.  I've been attempting to follow the excellent "Cook up Web sites
fast with CakePHP, Part 1" hosted at: 
http://www-128.ibm.com/developerworks/edu/os-dw-os-php-cake1.html

My first attempt involved using CakePHP 1.2, beta version 6311.  After
downloading it, unpacking it in a folder beneath my webroot, changing
the permissions to 777 on /app/tmp and attempting to visit
http://www.myurl.com/cake12/ (which should bring up the configuration/
welcome page) my browser hangs for a minute before spitting out:

Fatal error: Maximum execution time of 60 seconds exceeded in /var/
www/
html/cake12/cake/libs/view/view.php on line 634

Fatal error: Call to a member function on a non-object in /var/www/
html/cake12/cake/libs/cache.php on line 208

Undeterred, I switched to CakePHP 1.1.9.6305, upacked in a folder
beneath my webroot called cake11, changed the permissions of the /app/
tmp folder, and tried to visit http://www.myurl.com/cake11/ - this
time with some success, although I don't see any section about my
cache being set up properly or my tmp directory being writable.
Nonetheless I plowed ahead through the tutorial, and created the files
listed on page 3 of the tutorial.  So, when I visited
http://www.myurl.com/cake11/users/register I saw the registration page
and filled it out.  When I hit the registration button, my URL is
changed to http://www.myurl.com/users/register and I'm told that page
doesn't exist, which makes sense.

I tried changing the ROOT and APP_DIR values in /app/webroot/
index.php, but that only seemed to break everything, so I changed it
back.  My next attempt was to copy all of the files in /webroot/cake11
directly into /webroot.  This works to some degree - I quickly defined
a index() function in /app/controllers/users_controller this displays
a small message using $this->flash, so when I retrieve 
http://www.myurl.com/users
I see the message, but attempting to visit http://www.myurl.com/users/register
gives me the same "page doesn't exist" message, even though I know
that register.ctp is there.

So, my questions are:
1) Can anyone make sense of the error I'm getting with 1.2?  I'm happy
to stick with 1.1, if need be, but I'd be glad to get it working.

2) What is the correct way to tell CakePHP to use a certain path?
Leaving files in /webroot/cake11 works until it needs to (I'm
guessing) build a URL, at which point it assumes the Cake files should
be in the /webroot folder; and moving them to /webroot seems to make
the register.ctp view seem to not exist at all as far as the web
server is concerned.

Thanks in advance!

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



Help configuring CakePHP 1.1 or 1.2 for a total CakePHP newbie

2008-02-24 Thread George C

Hello!

I'd like to get started using Cake, but so far I haven't had a lot of
luck.  I've been attempting to follow the excellent "Cook up Web sites
fast with CakePHP, Part 1" hosted at: 
http://www-128.ibm.com/developerworks/edu/os-dw-os-php-cake1.html

My first attempt involved using CakePHP 1.2, beta version 6311.  After
downloading it, unpacking it in a folder beneath my webroot, changing
the permissions to 777 on /app/tmp and attempting to visit
http://www.myurl.com/cake12/ (which should bring up the configuration/
welcome page) my browser hangs for a minute before spitting out:

Fatal error: Maximum execution time of 60 seconds exceeded in /var/www/
html/cake12/cake/libs/view/view.php on line 634

Fatal error: Call to a member function on a non-object in /var/www/
html/cake12/cake/libs/cache.php on line 208

Undeterred, I switched to CakePHP 1.1.9.6305, upacked in a folder
beneath my webroot called cake11, changed the permissions of the /app/
tmp folder, and tried to visit http://www.myurl.com/cake11/ - this
time with some success, although I don't see any section about my
cache being set up properly or my tmp directory being writable.
Nonetheless I plowed ahead through the tutorial, and created the files
listed on page 3 of the tutorial.  So, when I visited
http://www.myurl.com/cake11/users/register I saw the registration page
and filled it out.  When I hit the registration button, my URL is
changed to http://www.myurl.com/users/register and I'm told that page
doesn't exist, which makes sense.

I tried changing the ROOT and APP_DIR values in /app/webroot/
index.php, but that only seemed to break everything, so I changed it
back.  My next attempt was to copy all of the files in /webroot/cake11
directly into /webroot.  This works to some degree - I quickly defined
a index() function in /app/controllers/users_controller this displays
a small message using $this->flash, so when I retrieve 
http://www.myurl.com/users
I see the message, but attempting to visit http://www.myurl.com/users/register
gives me the same "page doesn't exist" message, even though I know
that register.ctp is there.

So, my questions are:
1) Can anyone make sense of the error I'm getting with 1.2?  I'm happy
to stick with 1.1, if need be, but I'd be glad to get it working.

2) What is the correct way to tell CakePHP to use a certain path?
Leaving files in /webroot/cake11 works until it needs to (I'm
guessing) build a URL, at which point it assumes the Cake files should
be in the /webroot folder; and moving them to /webroot seems to make
the register.ctp view seem to not exist at all as far as the web
server is concerned.

Thanks in advance!

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