Re: How I can add USE INDEX() find() method

2010-05-23 Thread barduck

Did you find an answer to this problem? I also need to force an index
since MySQL fails miserably to choose the proper one.

I searched high and low and there seems to be absolutely no
information how can this be done in cake, if all all.

- barduck



On Mar 31, 3:32 pm, max  wrote:
> Hello
> I want force use mysql multiple-field index.
> Mysql don't use multiple-field index in my query.
> How I can addUSE INDEXto the Model->find() method?
>
> After call Model->find() method
> Cakephp executed this query
> SELECT * FROM `table` where a=1 AND b>2 ORDER BY b
>
> How I can addUSE INDEXinto query?
> It must be so:
> SELECT * FROM `table`USE INDEX(two_field_multiple_index) where a=1
> AND b>2 ORDER BY b
>
> Thanks.

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


Re: Checking RequestHandler::isPost() vs Controller's data

2010-03-24 Thread barduck
It looks to be somewhat of a mess, but the bug is not in
RequestHandler itself.

When you create the form, if you don't specify it, FormHelper->create
assigns the method POST or PUT to the form depending on whether the
record already exists or not. So when there is a record (edit), the
verb is PUT and not POST. One problem is that this verb is assigned to
a hidden field in the form and cake uses the verb from there across
the board on post back. So when submitted, isPost will not work but
isPut will. I have no idea why a special hidden field is used instead
of the HTTP verb itself, maybe there is good reason for that but it's
very confusing.

This is also contrary to the [arguable] consensus on mapping CRUD to
HTTP verbs:

* Create = PUT
* Retrieve = GET
* Update = POST
* Delete = DELETE

The above is arguable, some say that PUT and POST can be both used for
Create and Update depending on some more subtle differences I will not
get into here.

- barduck

On Mar 10, 8:01 pm, Miles J  wrote:
> The main problem I always would run into would that it would not
> recognized a POST, so the form would do nothing. I would usually have
> to submit it twice before it worked.
>
> Never figured out why it did that.
>
> On Mar 10, 7:03 am, Jimmy Bourassa  wrote:
>
> > Thanks Miles,
>
> > Can you be a bit more specific regarding the bugs you've seen?
>
> > Thanks,
>
> > On 10 mar, 00:17, Miles J  wrote:
>
> > > Yes exactly. RequestHandler would force it only if the HTTP method is
> > > POST, where as $data would work no matter what source it came from. I
> > > prefer RequestHandler, but it has been buggy sometimes.
>
> > > On Mar 9, 6:10 pm, Jimmy Bourassa  wrote:
>
> > > > Hello,
>
> > > > I realized that everyone seems to do an empty() call on $this->data in
> > > > controllers in order to check if data has been posted or not.
>
> > > > Is it just me or RequestHandler::isPostyields better results? This
> > > > would allow to pre-fill Controller::$data in various situations.
>
> > > > Thanks,
>
>

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.


Re: Exporting large amount of data from cake application

2010-03-11 Thread barduck

Jorge,

Yes, reading one record at a time is exactly what I am looking for.

But I must admit that I don't understand how the code in the article
is able to achieve this.

Looking in the code I see the FactModel performs:
$raw_facts = $this->query($query);

which if I understand correctly, will still retrieve the entire result
set from the database and covert it into an array in memory before
returning it to the caller. Or am I missing something?

Thanks



On Mar 11, 5:39 pm, Jorge Horacio Cué Cantú 
wrote:
> OK,
>
> Sorry I didn explain myself well enough,
>
> Te point is, one problem wuth Cake for large resultset from queries is that
> cake is retrieving all data into memory at once; the dataset described in
> the article allows you to retrieve *one record at a time* from the dataset,
> then instead of writing a report as in the article, export the data into an
> XML, Excel or warever you need to do.
>
> It just an idea but, who knows? You may end with an interesting exporter
> pluging.
>
> Regards
>
> On Wed, Mar 10, 2010 at 4:22 AM, barduck  wrote:
> > That's an interesting article that contains some useful information.
> > However, I don't think it directly applies to my problem.
>
> > I think that the techniques described in the article are best suited
> > for situations when you have large amounts of complex data that you
> > need to be able to display different views of in a flexible manner.
> > The extracted data is stored back into the database and it is
> > presented to the user in the traditional ways of using find() and
> > passing the info to the [buffered] views.
>
> > In my case, the data I need to export is already simplified and the
> > query is optimized. I don't need to further simplify it or store it
> > back to the DB. My problem is how to stream this data directly to the
> > client. If I use find() on the entire data, I run into memory issues
> > (mostly because everything is buffered in memory until the data is
> > ready and the overhead of passing the arrays back and forth). If I
> > split the query into multiple pages and call find on subsets of the
> > data, the request becomes too slow (the times of the paged queries add
> > up pretty quickly).
>
> > I need to execute the query and then iterate over the raw result set
> > and stream/flush the data. I know I can do this all manually but I was
> > hoping I could leverage cake's models and query building abilities
> > instead of doing it all from scratch.
>
> > Regards
> > - barduck
>
> > On Mar 9, 5:49 pm, Jorge Horacio Cué Cantú 
> > wrote:
> > > Hello,
>
> > > Why don't You take a look at the article "Star schema (OLAP) setup for
> > > reporting" at the backery.
> > > It might be used for exporting instead reporting.
>
> > > The link to the article is
>
> > >http://bakery.cakephp.org/articles/view/starschema-olap-setup-for-rep...
>
> > > Please let us know your insights.
> > > Regards.
>
> > > On Mon, Mar 8, 2010 at 1:45 PM, barduck  wrote:
>
> > > > Hi,
>
> > > > In my cake application (1.2, apache, mysql), I need to export a large
> > > > amount of data (tens of thousands of records or more) in XML format.
> > > > The query itself is heavy but nothing the application/database
> > > > shouldn't handle reasonably (it takes ~1-2 seconds to complete the
> > > > query itself).
>
> > > > I first tried the naive way of just calling find() and passing the
> > > > result to an XML view. This, of course, chokes the application pretty
> > > > quickly and PHP runs out of memory.
>
> > > > Next I tried "paging" the query internally within one call in my
> > > > controller, rending each chuck and flushing the output buffer
> > > > manually. This worked better but it is taking way too long since I now
> > > > have dozens of queries instead of one, each taking over a second to
> > > > complete.
>
> > > > Now I know there must be a way to achieve this since running the same
> > > > query in phpmyadmin and exporting the result as XML works very well. I
> > > > guess that in this case I need to somehow bypass some of cake
> > > > mechanisms, iterate over the result set myself and steam the data to
> > > > the client.
>
> > > > But I still want to use some of cake's strengths when possible so I
> > > > figured I need to do something like this.
>
> > > > * use cake for the request: routes, controller

Re: Exporting large amount of data from cake application

2010-03-10 Thread barduck

Zaky, thanks for your reply.

But this doesn't really answer my question. I didn't ask how to
generate an xml file from a sql query, I know how to do that...

I asked how to do it from cake, as a response to a request, on demand,
because I need to consider various input parameters, dynamically
associate models, etc...



On Mar 10, 11:20 pm, Zaky Katalan-Ezra  wrote:
> Put this line into a script file, .sh ot .bat, without the square brackets.
> mysql -u[youruser] -p[youruserpassword] [yourdatabase] -e"select * from
> yourtable" --xml > data.xml
> Run the script from your site.
> When the script return use the text file data.xml.
> There is a security issues you need to address in order to use this file
> only in a specific session or for a specific user.

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


Re: Exporting large amount of data from cake application

2010-03-10 Thread barduck
That's an interesting article that contains some useful information.
However, I don't think it directly applies to my problem.

I think that the techniques described in the article are best suited
for situations when you have large amounts of complex data that you
need to be able to display different views of in a flexible manner.
The extracted data is stored back into the database and it is
presented to the user in the traditional ways of using find() and
passing the info to the [buffered] views.

In my case, the data I need to export is already simplified and the
query is optimized. I don't need to further simplify it or store it
back to the DB. My problem is how to stream this data directly to the
client. If I use find() on the entire data, I run into memory issues
(mostly because everything is buffered in memory until the data is
ready and the overhead of passing the arrays back and forth). If I
split the query into multiple pages and call find on subsets of the
data, the request becomes too slow (the times of the paged queries add
up pretty quickly).

I need to execute the query and then iterate over the raw result set
and stream/flush the data. I know I can do this all manually but I was
hoping I could leverage cake's models and query building abilities
instead of doing it all from scratch.

Regards
- barduck

On Mar 9, 5:49 pm, Jorge Horacio Cué Cantú 
wrote:
> Hello,
>
> Why don't You take a look at the article "Star schema (OLAP) setup for
> reporting" at the backery.
> It might be used for exporting instead reporting.
>
> The link to the article is
>
> http://bakery.cakephp.org/articles/view/starschema-olap-setup-for-rep...
>
> Please let us know your insights.
> Regards.
>
> On Mon, Mar 8, 2010 at 1:45 PM, barduck  wrote:
>
> > Hi,
>
> > In my cake application (1.2, apache, mysql), I need to export a large
> > amount of data (tens of thousands of records or more) in XML format.
> > The query itself is heavy but nothing the application/database
> > shouldn't handle reasonably (it takes ~1-2 seconds to complete the
> > query itself).
>
> > I first tried the naive way of just calling find() and passing the
> > result to an XML view. This, of course, chokes the application pretty
> > quickly and PHP runs out of memory.
>
> > Next I tried "paging" the query internally within one call in my
> > controller, rending each chuck and flushing the output buffer
> > manually. This worked better but it is taking way too long since I now
> > have dozens of queries instead of one, each taking over a second to
> > complete.
>
> > Now I know there must be a way to achieve this since running the same
> > query in phpmyadmin and exporting the result as XML works very well. I
> > guess that in this case I need to somehow bypass some of cake
> > mechanisms, iterate over the result set myself and steam the data to
> > the client.
>
> > But I still want to use some of cake's strengths when possible so I
> > figured I need to do something like this.
>
> > * use cake for the request: routes, controller/action, parse input
> > parameters
> > * use cake models to generate the find query
> > * obtain the SQL query from cake
> > * get the active mysql database connection from cake
> > * execute the query on the raw connection
> > * iterate over the result set, generate the XML elements, sending
> > chucks of data to the client and flushing as needed.
>
> > (when the above works I may save the XML to intermediate file for
> > caching and redirect to that file, using cake's cache to control
> > expiration).
>
> > Does the above make sense or is there any better way to achieve my
> > goal?
>
> > How do I get the raw SQL query for my models without executing it?
> > How do I get the database connection?
>
> > Any help is appreciated.
>
> > Thanks!
>
> > - barduck

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


Exporting large amount of data from cake application

2010-03-08 Thread barduck

Hi,

In my cake application (1.2, apache, mysql), I need to export a large
amount of data (tens of thousands of records or more) in XML format.
The query itself is heavy but nothing the application/database
shouldn't handle reasonably (it takes ~1-2 seconds to complete the
query itself).

I first tried the naive way of just calling find() and passing the
result to an XML view. This, of course, chokes the application pretty
quickly and PHP runs out of memory.

Next I tried "paging" the query internally within one call in my
controller, rending each chuck and flushing the output buffer
manually. This worked better but it is taking way too long since I now
have dozens of queries instead of one, each taking over a second to
complete.

Now I know there must be a way to achieve this since running the same
query in phpmyadmin and exporting the result as XML works very well. I
guess that in this case I need to somehow bypass some of cake
mechanisms, iterate over the result set myself and steam the data to
the client.

But I still want to use some of cake's strengths when possible so I
figured I need to do something like this.

* use cake for the request: routes, controller/action, parse input
parameters
* use cake models to generate the find query
* obtain the SQL query from cake
* get the active mysql database connection from cake
* execute the query on the raw connection
* iterate over the result set, generate the XML elements, sending
chucks of data to the client and flushing as needed.

(when the above works I may save the XML to intermediate file for
caching and redirect to that file, using cake's cache to control
expiration).

Does the above make sense or is there any better way to achieve my
goal?

How do I get the raw SQL query for my models without executing it?
How do I get the database connection?

Any help is appreciated.

Thanks!

- barduck

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


Re: Test Suite 1.2 and database connection

2008-06-19 Thread barduck


Anyone? Please?

Surely someone must have some knowledge about this test suite "magic"

Thanks
- barduck

On Jun 17, 11:41 am, barduck <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I am a little bit confused how the 'test' database connection is used
> in 1.2 (RC1) and how to work with it properly.
>
> The sample database.php has a $test connection config example in it,
> this is also mentioned in various articles and posts on this group.
> However, in the manual (http://book.cakephp.org) it says to use
> $test_suite and also looking through the code, there are various
> references to "test_suite" connection.
>
> What's the relation between the two? Which of them should be in my
> database.php?
>
> Also, I am wondering if the test connection is being automatically
> used in tests that use fixtures and those without? My experiments
> indicate that this is not the case but I may be doing something wrong.
> Should cake always magically use the test connection when testing
> controllers and models in a test case or do I need to do something
> explicitly to make this work?
>
> Thanks.
>
> Cheers,
> - barduck
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Does SimpleTest v1.01 break Test Suite v1.2.0.0??

2008-06-18 Thread barduck


Well, I can't help much because I am also currently having a lot of
problems with the test suite, so for what it's worth -

I think SimpleTest 1.0.1 works because many of the tests do pass
without errors.

What I noticed is that if you are switching between cake's revisions,
make sure that the cache (/tmp/cache) is deleted after each switch as
it seems to cause problems otherwise.

There *are* tests that don't pass. I don't know if these are known
issues that cake's developers intended to release RC1 with and ignore
the failed tests or just failures that are specific to my
configuration/system but many of the core tests fail. At least one of
the tests you mention fails here too.

cheers,
- barduck



On Jun 18, 9:31 pm, mGee <[EMAIL PROTECTED]> wrote:
> Any chance someone might have some input? It would be greatly
> appreciated.
>
> Peace
> Mike
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: How to create test cases for plugins

2008-06-17 Thread barduck


I am also struggling with the test framework and it isn't an easy
path. There isn't plenty of documentation and it is sometimes outdated
or incorrect.

But look at section "4.7.6.2 The testAction method" in the cookbook.

In your case, it isn't displaying anything in debug() because by
default, testAction() is set to 'return' => 'result' so it just
returns the result of the controller's action (which usually doesn't
return anything unless you explicitly make it so).

Look at the parameters that testAction() expects for 'return' and set
it accordingly. But I think the book's documentation is not updated to
the latest version because it states that the parameters are 'vars',
'render' and 'return' while if you are using RC1 and look at the
source code for testAction() in cake_test_case.php, you will see the
the expected parameters are one of 'result', 'view',  'contents' or
'vars'.

So set it to one of the other values to make it return the rendered
view or vars.

- barduck



On Jun 17, 3:33 pm, jaro <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I've been reading a lot about test cases but cannot find a how-to
> approach in testing plugins controllers.
>
> Read the tutorial 
> inhttp://book.cakephp.org/view/160/testing#testing-plugins-485
> but that was only for models.
>
> I created the ffg to test my pizza_controller.php. I named it
> pizza_controller.test.php
>
> class PizzaControllerTest extends CakeTestCase {
>function startCase() {
>  echo 'Starting Test Case';
>}
>function endCase() {
>  echo 'Ending Test Case';
>}
>function startTest($method) {
>  echo 'Starting method ' . $method . '';
>}
>function endTest($method) {
>  echo '';
>}
>function testIndex() {
>  $result = $this->testAction('/shopping_cart/index');
>  debug($result);
>}
>
> }
>
> Nothing is displayed in the test.php page. What am I missing?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Test Suite 1.2 and database connection

2008-06-17 Thread barduck


Hi all,

I am a little bit confused how the 'test' database connection is used
in 1.2 (RC1) and how to work with it properly.


The sample database.php has a $test connection config example in it,
this is also mentioned in various articles and posts on this group.
However, in the manual (http://book.cakephp.org) it says to use
$test_suite and also looking through the code, there are various
references to "test_suite" connection.

What's the relation between the two? Which of them should be in my
database.php?

Also, I am wondering if the test connection is being automatically
used in tests that use fixtures and those without? My experiments
indicate that this is not the case but I may be doing something wrong.
Should cake always magically use the test connection when testing
controllers and models in a test case or do I need to do something
explicitly to make this work?

Thanks.

Cheers,
- barduck

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Why does Cake generate these redundant unnecessary queries?

2007-04-09 Thread barduck

Thanks for the reply.

I am using "recursive = 2" in the example because although it is not
needed in the sample code, I do need it in the real scenario where I
have other associations.

Yes, I am familiar with this article and tried the expects() method.
It can help when you need to remove unwanted associations but in case
when you do need the information from these associations and don't
want to have them removed, expects() doesn't help you to reduce the
redundant queries.

My point being, I don't understand why cake generates these queries in
the first place, all the information was already retrieved in the
initial query so I assumed this is a bug or otherwise unintentional
behavior.


On Apr 10, 6:13 am, "dericknwq" <[EMAIL PROTECTED]> wrote:
> This was my point when I 
> postedhttp://groups.google.com/group/cake-php/browse_thread/thread/b73a9a23...
>
> Anyways, I don't suppose you will need a level 2 recursive call based
> on the Model you've shown. Buthttp://bakery.cakephp.org/articles/view/185
> should help greatly. :)
>
> On Apr 10, 12:54 am, "barduck" <[EMAIL PROTECTED]> wrote:
>
> > Hi,
>
> > I was looking at my SQL debug logs and seeing a lot of redundant
> > unnecessary queries which I don't think should be there at all. I am
> > using the nightly build of 1.2 from couple of days ago but I was
> > seeing this with 1.2 for quite a while.
>
> > So I created a very basic scenario and this is still reproducing, just
> > two DB tables and two cake models:
>
> > class Category extends AppModel
> > {
> > var $name = 'Category';
>
> > }
>
> > class Product extends AppModel
> > {
> > var $name = 'Product';
>
> > var $belongsTo = array('Category');
>
> > var $recursive = 2;
>
> > }
>
> > In my products controller, I want to get all products:
>
> > $products = $this->Product->findAll();
>
> > And this is what I see in the SQL log:
>
> > 1   DESC `products` 3   3   5
> > 2   DESC `categories`   2   2   5
> > 3   SELECT `Product`.`id`, `Product`.`name`, `Product`.`category_id`,
> > `Category`.`id`, `Category`.` name` FROM `products` AS `Product` LEFT
> > JOIN `categories` AS `Category` ON (`Product`.`category_id` =
> > `Category`.`id`) WHERE 1 = 112  12  1
> > 4   SELECT `Category`.`id`, `Category`.` name` FROM `categories` AS
> > `Category` WHERE `Category`.`id` = 11   1   1
> > 5   SELECT `Category`.`id`, `Category`.` name` FROM `categories` AS
> > `Category` WHERE `Category`.`id` = 11   1   0
> > 6   SELECT `Category`.`id`, `Category`.` name` FROM `categories` AS
> > `Category` WHERE `Category`.`id` = 11   1   0
> > 7   SELECT `Category`.`id`, `Category`.` name` FROM `categories` AS
> > `Category` WHERE `Category`.`id` = 11   1   0
> > 8   SELECT `Category`.`id`, `Category`.` name` FROM `categories` AS
> > `Category` WHERE `Category`.`id` = 31   1   0
> > 9   SELECT `Category`.`id`, `Category`.` name` FROM `categories` AS
> > `Category` WHERE `Category`.`id` = 31   1   1
> > 10  SELECT `Category`.`id`, `Category`.` name` FROM `categories` AS
> > `Category` WHERE `Category`.`id` = 31   1   0
> > 11  SELECT `Category`.`id`, `Category`.` name` FROM `categories` AS
> > `Category` WHERE `Category`.`id` = 31   1   3
> > 12  SELECT `Category`.`id`, `Category`.` name` FROM `categories` AS
> > `Category` WHERE `Category`.`id` = 31   1   1
> > 13  SELECT `Category`.`id`, `Category`.` name` FROM `categories` AS
> > `Category` WHERE `Category`.`id` = 31   1   1
> > 14  SELECT `Category`.`id`, `Category`.` name` FROM `categories` AS
> > `Category` WHERE `Category`.`id` = 21   1   1
> > 15  SELECT `Category`.`id`, `Category`.` name` FROM `categories` AS
> > `Category` WHERE `Category`.`id` = 21   1   0
>
> > What are all the SELECT queries from categories table doing there?
> > They are already included in the main query with the LEFT JOIN and why
> > is there a separate query for each product row even if the same
> > category was already fetched?
>
> > This is just a sample DB, in my real scenario with many more
> > associations, a findAll() query generates over 1000 redundant queries
> > which takes some time to execute.
>
> > Can anyone shed some light on this?
>
> > Thanks.


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Why does Cake generate these redundant unnecessary queries?

2007-04-09 Thread barduck

Hi,

I was looking at my SQL debug logs and seeing a lot of redundant
unnecessary queries which I don't think should be there at all. I am
using the nightly build of 1.2 from couple of days ago but I was
seeing this with 1.2 for quite a while.

So I created a very basic scenario and this is still reproducing, just
two DB tables and two cake models:

class Category extends AppModel
{
var $name = 'Category';
}

class Product extends AppModel
{
var $name = 'Product';

var $belongsTo = array('Category');

var $recursive = 2;
}


In my products controller, I want to get all products:

$products = $this->Product->findAll();


And this is what I see in the SQL log:

1   DESC `products` 3   3   5
2   DESC `categories`   2   2   5
3   SELECT `Product`.`id`, `Product`.`name`, `Product`.`category_id`,
`Category`.`id`, `Category`.` name` FROM `products` AS `Product` LEFT
JOIN `categories` AS `Category` ON (`Product`.`category_id` =
`Category`.`id`) WHERE 1 = 112  12  1
4   SELECT `Category`.`id`, `Category`.` name` FROM `categories` AS
`Category` WHERE `Category`.`id` = 11   1   1
5   SELECT `Category`.`id`, `Category`.` name` FROM `categories` AS
`Category` WHERE `Category`.`id` = 11   1   0
6   SELECT `Category`.`id`, `Category`.` name` FROM `categories` AS
`Category` WHERE `Category`.`id` = 11   1   0
7   SELECT `Category`.`id`, `Category`.` name` FROM `categories` AS
`Category` WHERE `Category`.`id` = 11   1   0
8   SELECT `Category`.`id`, `Category`.` name` FROM `categories` AS
`Category` WHERE `Category`.`id` = 31   1   0
9   SELECT `Category`.`id`, `Category`.` name` FROM `categories` AS
`Category` WHERE `Category`.`id` = 31   1   1
10  SELECT `Category`.`id`, `Category`.` name` FROM `categories` AS
`Category` WHERE `Category`.`id` = 31   1   0
11  SELECT `Category`.`id`, `Category`.` name` FROM `categories` AS
`Category` WHERE `Category`.`id` = 31   1   3
12  SELECT `Category`.`id`, `Category`.` name` FROM `categories` AS
`Category` WHERE `Category`.`id` = 31   1   1
13  SELECT `Category`.`id`, `Category`.` name` FROM `categories` AS
`Category` WHERE `Category`.`id` = 31   1   1
14  SELECT `Category`.`id`, `Category`.` name` FROM `categories` AS
`Category` WHERE `Category`.`id` = 21   1   1
15  SELECT `Category`.`id`, `Category`.` name` FROM `categories` AS
`Category` WHERE `Category`.`id` = 21   1   0



What are all the SELECT queries from categories table doing there?
They are already included in the main query with the LEFT JOIN and why
is there a separate query for each product row even if the same
category was already fetched?

This is just a sample DB, in my real scenario with many more
associations, a findAll() query generates over 1000 redundant queries
which takes some time to execute.

Can anyone shed some light on this?

Thanks.


--~--~-~--~~~---~--~~
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: new to cake php, need help on tag clouds database design

2007-03-22 Thread barduck


I am not sure I understand what are you trying to achieve, why would
you need a table with tag, user id and post id?

For typical tag cloud implementation, I assume that you would have
tags, users and posts, each user has set tags associated with it and
each post has (different) set of tags for it. Right?

In this case, your database will be something like that

"tags" table, with "id" and "tag"
"users" table, with "id" and all the other information you want to
save for the user
"posts" table, with "id" and all post related information

Now, you have 2 tables for the relationship between tags, users and
posts.
"tags_users" HABTM table, with "tag_id" and "user_id"
"posts_tags" HABTM table, with "post_id" and "tag_id"


- barduck






On Mar 22, 11:42 am, "feelexit" <[EMAIL PROTECTED]> wrote:
> I just start a simple web application. Need to make tag clouds for it,
> so it will look more like web 2.0
>
> here's the problem, I have this table called "tags".
>
> tags has id, tag, users_id, posts_id,  I dont want to have id to be my
> primary key, I only want 3 columns, tag, users_id, posts_id,  and I
> want all these 3 columns to form my primary key.
>
> but based on wht I learned, I need to follow Cake's database naming
> conventions, and I have to have "id" in the table, is there a way to
> get rid of this "id" column?
>
> by the way, where is Cake's database naming conventions, I found linke
> to Cake's naming conventions, but theres nothing about "database name
> convention".


--~--~-~--~~~---~--~~
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: Need some help with pagination in 1.2

2007-03-20 Thread barduck


No one? Nothing?

Ok. Anyway, for lack of better advice I decided that I will just copy
the paginate() method from the base Controller to my controller,
remove the stuff I don't need and add my own logic in between to
validate and replace the parameters.

makes sense?




On Mar 18, 12:44 pm, "barduck" <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I need some help and advice with implementing pagination in 1.2 .
>
> I got the basic functionality working which means I have paginate()
> return the correct count of items of the first page and if change the
> URL to pass different page # and limit #, the page behaves as
> expected.
>
> What I am not sure about is how to get more control over the
> pagination behavior and make it do exactly what I want. Looking at the
> source code it seems like paginate() is taking its parameters from the
> URL in is various forms (params, URL and passedArgs) and it overrides
> anything else I can set (well, there is whitelist but I am not sure
> how to use it exactly and couldn't make it to work).
>
> I am looking for the proper way to do the following:
>
> 1. Validate the parameters passed to paginate(). For example having a
> max and min values that the "limit" parameter can have (to prevent
> just calling my page with huge limit numbers) or to prevent some field
> names as entries for being sorted by (currently, everything passed in
> the URL goes).
>
> 2. Gracefully ignore any fields that are passed as sort parameter and
> don't actually exists. So if a user enters some non existing field
> name in the URL, the page just ignores it and sorts the data by the
> default field instead of displaying an ugly error.
>
> 3. Have aliases for some fields to be used with the sort parameters.
> So if I need to sort by a field that is nested a level or two deep
> inside the model, I can just use something like "sort:alias_name"
> instead of writing the entire hierarchy for the required field.
>
> Where is the proper place to hook the above? What is the best way to
> achieve it and keep everything clean?
>
> On a related note, what could be the reason for $paginator->next('>>',
> null, null, null) not returning the correct URL for the next page? It
> just returns the same URL the page is on, without any parameters. Do I
> need to pass anything special to it?
>
> 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: Newbie to Cake - IIS5 problem

2007-03-20 Thread barduck


This is not Cake or PHP problem but how web servers generally work and
serve URLs.

When you request "http://localhost/cake/app/index.php?/posts/index";,
the web server knows that you are looking for the document "index.php"
under directory "/cake/app/" with the parameter "/posts/index". IIS
knows that in order to serve "index.php", it needs to invoke the PHP
ISAPI and pass handling of the request to it.

If you omit the "?" and just write "http://localhost/cake/app/
index.php/posts/index" IIS looks for the default (configurable,
"index.html", "index.htm" etc by default) document under "/cake/app/
index.php/posts/index/", which of course doesn't exist, so no PHP/Cake
is being invoked and you get the "not found" error.

There is no way to do what you want without URL rewriting before IIS
handles the request. There is an ISAPI filter that does it quite well,
look at:
http://www.isapirewrite.com/

It is very similar to mod rewrite on Apache. There is a free lite
version that should satisfy your needs on development environment.

Hope this helps.
- barduck

On Mar 18, 1:39 pm, "david" <[EMAIL PROTECTED]> wrote:
> I seen loads of posts about the problems with IIS, but I didn't spot
> anything that relates exactly to my problem (so maybe it's not a cake
> problem - but IIS) - maybe there is an existing post - and I just
> don't know what to search for! (in which case I do apologise in
> advance)
>
> Basically, I can't run any rewrite dll's, so wanted to try the options
> without it
> I'm using php as ISAPI
> The only php settings I've changed are the extensionpath, and
> uncommented the extensions for mysql
> I've gone through the basic tutorial
> I'm using PHP 5
> Cake 1.1.13.4450
>
> So, to the problem
>
> By adding
> define ('SERVER_IIS', true);
>  and
> define ('BASE_URL', env('SCRIPT_NAME').'?');
>
> I can gethttp://localhost/cake/app/index.php?/posts/index
> working (and links from that page work also)
>
> but if i omit the '?', I just get page cannot be found
>
> I did try
> define ('BASE_URL', env('SCRIPT_NAME'));
>
> But if i omit the '?' in the url, I still get page cannot be found -
> it still shows the initial page if I put the '?' back in the url as
> before, but now links from that page don't work (the links miss the
> '?' out)
>
> Have I missed a setting from IIS or PHP that cake needs?
>
> Also, why do I have to put the 'app' part in also? - if I just 
> usehttp://localhost/cake/index.php?/posts/index
> It stays on the home page


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Need some help with pagination in 1.2

2007-03-18 Thread barduck

Hi all,

I need some help and advice with implementing pagination in 1.2 .

I got the basic functionality working which means I have paginate()
return the correct count of items of the first page and if change the
URL to pass different page # and limit #, the page behaves as
expected.

What I am not sure about is how to get more control over the
pagination behavior and make it do exactly what I want. Looking at the
source code it seems like paginate() is taking its parameters from the
URL in is various forms (params, URL and passedArgs) and it overrides
anything else I can set (well, there is whitelist but I am not sure
how to use it exactly and couldn't make it to work).

I am looking for the proper way to do the following:

1. Validate the parameters passed to paginate(). For example having a
max and min values that the "limit" parameter can have (to prevent
just calling my page with huge limit numbers) or to prevent some field
names as entries for being sorted by (currently, everything passed in
the URL goes).

2. Gracefully ignore any fields that are passed as sort parameter and
don't actually exists. So if a user enters some non existing field
name in the URL, the page just ignores it and sorts the data by the
default field instead of displaying an ugly error.

3. Have aliases for some fields to be used with the sort parameters.
So if I need to sort by a field that is nested a level or two deep
inside the model, I can just use something like "sort:alias_name"
instead of writing the entire hierarchy for the required field.


Where is the proper place to hook the above? What is the best way to
achieve it and keep everything clean?


On a related note, what could be the reason for $paginator->next('>>',
null, null, null) not returning the correct URL for the next page? It
just returns the same URL the page is on, without any parameters. Do I
need to pass anything special to it?

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: Unique subdomain for each user

2007-03-07 Thread barduck


You can setup Apache to accept multiple domains/subdomains for a
virtual host.

You will need to setup apache to use virtual hosts, read the Apache
documentation here:
http://httpd.apache.org/docs/2.0/vhosts/name-based.html

Then you can set up a virtual host with your base domain name and add
an alias with a subdomain wildcard. Something like this:
ServerName domain.tld
ServerAlias *.domain.tld

After that, use mod_rewrite rule to rewrite the URL and append the
subdomain to your URL's before it is passed to Cake rewrite rules.

By the way, Apache can't just accept subdomains by itself, you will
still need to have the DNS entries for the sub domains set up
correctly. So in order for you to be able to create users on the fly
you will need a DNS server that can either accept the *.domain.tld
wildcard and return the correct entry or have some other method to set
the entry automatically for each .domain.tld

Hope this helps.
- barduck


On Mar 6, 8:09 pm, "phirschybar" <[EMAIL PROTECTED]> wrote:
> This is probably just an apache question but I figure somebody in the
> group would know the answer...
>
> My app needs to work so that username.appdomain.com maps to
> appdomain.com/username/controller/action/..
>
> Is this a simple apache setup trick?
>
> Users need to be able to create accounts themselves so I cannot do
> manual httpd.conf edits for each user...
>
> Thoughts?


--~--~-~--~~~---~--~~
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: So confused

2007-03-05 Thread barduck


Nate & John:

First let me emphasize that this way or another, it is fine by me. I
don't expect anything from anyone, I don't demand anyone to help me, I
don't require that the documentation be by any standards and I am not
complaining about it, it is better than not having any of this at all.
You don't owe me anything and I realize that you do all this
tremendous work in your spare time just because you care for it and
enjoy it.

I didn't say that newbies can't contribute, but don't expect them to
come and start writing documentation or submitting tickets as soon as
they arrive. And more importantly, don't get upset when they don't.
They won't.

Because a newbie comes to a project with a mentality of "Is this
project worth it? What is there for *ME*?", nobody comes to a project
they are not familiar with thinking "I want to contribute". So yes,
they will ask the same questions over and over, they will ignore the
faqs and search feature, they will seem clueless and sometimes rude
and demanding, that's how it is.

It is the job of the existing community to make them feel welcome
despite their annoyances, to make them feel comfortable with the
project and to make them want to stick around. Then, some of them will
stay and move toward a "hey, this is cool! I want to contribute!" way
of thinking. And a big part of this falls on the documentation,
articles and examples.

The importance of newbies, as John wrote, is by providing fresh and
unbiased eyes. They raise issues you long learned to live with, their
questions turn into faqs. And it is up to you to use this information
efficiently.

So while saying "if you are not happy with it, help to make it better"
response makes perfect sense in your eyes (and it is, I was on that
side of the fence as well), it may not come across that way to someone
who just arrived and trying to make the first steps - "Me? Help to
make it better? Why? I just got here, I am not even sure all this is
right for me".

I think that as much as it is my (or any newbie) interest to get the
most out of this project and have my questions answered as quickly and
thoroughly as possible, it is in the best interests of the project and
its community as well because in the long run, any project of this
nature requires constant influx of new people to be successful. So we
all basically want the same thing :)





On Mar 5, 9:08 pm, "nate" <[EMAIL PROTECTED]> wrote:
> Barduck:
>
> Let's not forget that the wisdom of the masses has already been
> aggregated on this very list.  95% of all questions any newbie could
> ever ask have already been asked--and answered--many, many, many
> times.  See here:http://cake.insertdesignhere.com/posts/view/11
>
> The idea that newbies can't contribute to the documentation effort is
> also not true.  Since almost all newbie questions have already been
> asked (and answered), any newbie that used this mailing list to find
> an answer to their question could easily take a few minutes to track
> down the most relevant information and codify that information into a
> thorough documentation ticket.  But that all assumes that said newbie
> actually cared enough to think ahead like that, ahem.
>
> On Mar 5, 12:16 pm, "barduck" <[EMAIL PROTECTED]> wrote:
>
> > Why is it that every time someone comments of the insufficient
> > documentation you Cake veterans jump in and say something along the
> > lines "so make it better"?
>
> > Well, guess what, there is a catch - anyone who actually NEEDS the
> > documentation is not in a position (yet) to contribute to it. And
> > anyone who knows enough about Cake to contribute to the documentation
> > can't REALLY see why the documentation is lacking.
>
> > Let's face it, like with any other framework/platform/language, it
> > looks totally different from the perspective of a total newbie to what
> > it looks like to someone who already comfortable with it. Over time,
> > when we gain knowledge and things become familiar, we tend to,
> > naturally, diminish the importance of documenting every little detail
> > and we don't understand what the newbies are complaining about when
> > they say they are totally lost in the documentation. That's the way it
> > usually works.
>
> > The only way to make any progress in this front is for the new comers
> > to express their problems and concerns in constructive manner and for
> > the Cake developers and veterans to listen to these problems and
> > complaints and think how to address them. There is no other way.
>
> > There is theoretically nothing wrong with saying "if you don't like
> > the documentation, help to m

Re: So confused

2007-03-05 Thread barduck


Why is it that every time someone comments of the insufficient
documentation you Cake veterans jump in and say something along the
lines "so make it better"?

Well, guess what, there is a catch - anyone who actually NEEDS the
documentation is not in a position (yet) to contribute to it. And
anyone who knows enough about Cake to contribute to the documentation
can't REALLY see why the documentation is lacking.

Let's face it, like with any other framework/platform/language, it
looks totally different from the perspective of a total newbie to what
it looks like to someone who already comfortable with it. Over time,
when we gain knowledge and things become familiar, we tend to,
naturally, diminish the importance of documenting every little detail
and we don't understand what the newbies are complaining about when
they say they are totally lost in the documentation. That's the way it
usually works.

The only way to make any progress in this front is for the new comers
to express their problems and concerns in constructive manner and for
the Cake developers and veterans to listen to these problems and
complaints and think how to address them. There is no other way.

There is theoretically nothing wrong with saying "if you don't like
the documentation, help to make it better" but it doesn't really help
the newbie who may be raising a valid point and it doesn't help Cake
to bring new people into the community. And an active and thriving
community is essential to any project of this kind.

So please don't take it personally, all of us appreciate the hard work
that is being done both on the code and documentation but looking
through the eyes of a total newbie, the documentation is...well, can
be frustrating at times.

Cheers.
- barduck





On Mar 2, 9:21 pm, "nate" <[EMAIL PROTECTED]> wrote:
> Great, I'll take that as you voulenteering to fix it.  You can contact
> the documentation lead at psychic at cakephp dot org.
>
> On Mar 2, 1:54 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
> wrote:
>
> > If you are going to continue developing with cakePHP get used to this.
> > I love cakePHP for a lot of things, but this community has some
> > terrible documentation.
>
> > skatona wrote:
> > > oh man, thank you.  I've been going crazy thinking that they wouldn't
> > > possibly let something like that slip by, so have been staring at each
> > > and every individual character in my code to see what I messed up.
> > > Over and over.
>
> > > Thanks a ton!
>
> > > On Mar 1, 2:30 pm, "bernardo" <[EMAIL PROTECTED]> wrote:
> > > > You are right. There is a bug in the code used in the screencast. I
> > > > think the problem is that edit.thtml is copied from add.thtml but
> > > > forget to include the line  hidden('Post/id'); ?> so
> > > > the id is not posted and the controller ends adding a new post. The
> > > > code in the manual is correct though.
>
> > > > I wonder how nobody noticed this before...
>
> > > > On Mar 1, 1:41 pm, "skatona" <[EMAIL PROTECTED]> wrote:
>
> > > > > I must be losing it.
>
> > > > > I'm a veteran php web developer and a friend said cakephp was awesome
> > > > > so I've checked it out and gone through a couple screencasts.  Am I
> > > > > crazy, or is the Blog Tutorial screencast wrong?  More specifically,
> > > > > the Edit functionality does NOT edit a post.  It merely Adds one.
>
> > > > > Watch the screencast again.  You click Edit, it brings up the Title
> > > > > and Body textboxes with the information from that post, but when you
> > > > > edit it and save - it just creates a new post!  I thought Edit meant
> > > > > "change", not "give me the info so I can use it in another NEW post".
>
> > > > > Someone please help me out here.
>
> > > > > -Shaun


--~--~-~--~~~---~--~~
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: Please help me understand URL and Routes in Cake

2007-03-04 Thread barduck


No one?

Surely someone can offer some additional insights on this.

Thanks.


On Mar 1, 10:44 am, "barduck"  wrote:
> Thanks for the reply.
>
> I think I have better understanding of the Route functionality now.
>
> I am still not sure I understand the full potential of regular
> expressions in Route. I mean, I see how I can specify a regex in the
> matching part of the Route->connect() but in mod rewrite, I can use
> regular expression both in the matching and the substitutions part of
> the URL (the groups from the match can be used in the rewritten URL,
> using (...) in the pattern and $N in the substitution), can something
> like this be done in Route?
>
> I assume the colon is one way to do this, but does colon-param pattern
> always needs to come surrounded by slashes (/)? What about the
> asterisk I used in my route, how come it isn't being confused with the
> meaning of asterisk in regex?
>
> I am also not sure what is the best way to achieve what I described in
> my original post. One possible solution is to define one big parameter
> and parse it myself in my code using a delimiter I set.
>
> So I set unit1+unit2+unit3... as one big parameter and separate it in
> code myself by the plus signs. Then I set a Route rule to detect plus
> signs before the normal unit view match. I think this will work also
> for the parameters to the index view but I wonder if this is the right
> way to do this and whether cake can do it automatically for me?
>
> Thanks.
>
> - barduck
>
> On Feb 28, 5:54 pm, Chris Lamb <[EMAIL PROTECTED]> wrote:
>
> > > I understand that Cake does [routing] this in two phases, one
> > > using apache mod rewrite to pass the rest of the path to cake and the
> > > second one by "Routes" to further route the URL in cake internally. Is
> > > this correct?
>
> > Yes.
>
> > > I assume that the major purpose of the Routes is to map URLs to
> > > controllers, functions and parameters.
>
> > Correct.
>
> > > 1. I've seen a colon (:) used in the manual in routes config (like /
> > > blog/:action/* ). What is the special meaning of the colon? It isn't
> > > mentioned anywhere.
>
> > They are to control the parameters that are passed to the Controller.
> > I think the syntax is a Ruby-ism. First, the general case. If your
> > route is:
>
> >   /blog/:spam/*
>
> > then if the browser requested
>
> >   /blog/eggs/
>
> > then $this->params['spam'] would contain the value 'eggs'. You can have
> > more than one in the route. For example:
>
> >   /blog/:year/:month/:day/:slug/*
>
> > gets you something like the default WordPress blog link structure.
> > There are two 'magic' parameters, "controller" and "action" which, when
> > set, decide which controller or action to call respectively. For
> > example, the route:
>
> >   /blog/:action/:spam
>
> > when called with:
>
> >   /blog/view/eggs/
>
> > will call the "view" action with $this->params['spam'] set to "eggs".
>
> > > 2. Can I use regular expressions in Routes like on mod rewrite? How?
> > > The manual doesn't mention it.
>
> > Just use regular Perl-compatible regexs.
>
> > > 3. Can I still use URL query string parameters using "?" ? Or does
> > > cake only use the /controller/action/param/param... convention?
>
> > Cake has a different method of handling query string parameters. My
> > advice is to construct a controller action to display $this->params and
> > see how they are handled.
>
> > > Hope I am making myself clear. Sorry for the long message.
>
> > Hopefully someone else can help with the rest if the above does not
> > help you solve the problem yourself. Note that the CakePHP source is
> > very readable for a PHP program, so examining the dispatcher code may
> > make sense than any of this.
>
> > Best wishes,
>
> > --
> >  Chris Lamb, Leamington Spa, UKGPG: 0x634F9A20
>
> >  signature.asc
> > 1KDownload


--~--~-~--~~~---~--~~
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: Need help with less trivial associations

2007-03-04 Thread barduck

Thanks for the response.

The groups_units association is needed because there are units that
don't belong to any department but only to groups.

I assume the example you gave is for cake 1.2 ? I am using 1.1 and
can't find that Set::extract in the API. I will try and figure out how
to do this in 1.1, unless someone can offer help with the 1.1
equivalent.

Also, what would be the best place to put this code assuming I want
every Unit to have the full list of unique groups once the Unit model
is read from the database?

Thanks.


On Mar 4, 2:06 am, "Grant Cox" <[EMAIL PROTECTED]> wrote:
> Well, I would scrap the groups_units HABTM association, as it isn't
> really a direct association.  You can't add/remove those associations
> directly, so it's really just a symptom of the main Group ->
> Department -> Units association.
>
> Now, to get the associated group ids from a unit, have something like:
>
> $this->Unit->recursive = 2; // get the Departments, and the
> Departments' Groups
> $unit = $this->Unit->read(null, $unit_id);
> $group_ids = Set::extract($unit, 'Department.{n}.Group.{n}.id';
> $unique_group_ids = array_keys(array_flip($group_ids));


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Need help with less trivial associations

2007-03-03 Thread barduck


Hi all,

I need some help with defining some less trivial associations.

Suppose I have the following entities:
Unit
Group
Department


A Unit can be part of multiple groups and multiple departments.
Each group belongs to one department.
If unit is part of a department, it also belongs to all the groups
belonging to that department.

So I have the following
HABTM  groups_units
HABTM departments_units
Group belongsTo department.

Now, for each unit, I can have all the groups and departments it
belongs to.

Now I need a list of ALL the groups a unit belongs to, whether it is
by the direct association to a group or by the indirect association
through a department (and therefore all the groups belonging to that
department).

I probably can have additional custom SQL to get that information (but
it will be redundant cause I already have that info in my models) or
to have a code to generate that list (where to put it?) but what would
be the best and most elegant way to have a single array of such groups
in cake?

Thanks


--~--~-~--~~~---~--~~
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: Please help me understand URL and Routes in Cake

2007-03-01 Thread barduck

Thanks for the reply.

I think I have better understanding of the Route functionality now.

I am still not sure I understand the full potential of regular
expressions in Route. I mean, I see how I can specify a regex in the
matching part of the Route->connect() but in mod rewrite, I can use
regular expression both in the matching and the substitutions part of
the URL (the groups from the match can be used in the rewritten URL,
using (...) in the pattern and $N in the substitution), can something
like this be done in Route?

I assume the colon is one way to do this, but does colon-param pattern
always needs to come surrounded by slashes (/)? What about the
asterisk I used in my route, how come it isn't being confused with the
meaning of asterisk in regex?

I am also not sure what is the best way to achieve what I described in
my original post. One possible solution is to define one big parameter
and parse it myself in my code using a delimiter I set.

So I set unit1+unit2+unit3... as one big parameter and separate it in
code myself by the plus signs. Then I set a Route rule to detect plus
signs before the normal unit view match. I think this will work also
for the parameters to the index view but I wonder if this is the right
way to do this and whether cake can do it automatically for me?

Thanks.

- barduck

On Feb 28, 5:54 pm, Chris Lamb <[EMAIL PROTECTED]> wrote:
> > I understand that Cake does [routing] this in two phases, one
> > using apache mod rewrite to pass the rest of the path to cake and the
> > second one by "Routes" to further route the URL in cake internally. Is
> > this correct?
>
> Yes.
>
> > I assume that the major purpose of the Routes is to map URLs to
> > controllers, functions and parameters.
>
> Correct.
>
> > 1. I've seen a colon (:) used in the manual in routes config (like /
> > blog/:action/* ). What is the special meaning of the colon? It isn't
> > mentioned anywhere.
>
> They are to control the parameters that are passed to the Controller.
> I think the syntax is a Ruby-ism. First, the general case. If your
> route is:
>
>   /blog/:spam/*
>
> then if the browser requested
>
>   /blog/eggs/
>
> then $this->params['spam'] would contain the value 'eggs'. You can have
> more than one in the route. For example:
>
>   /blog/:year/:month/:day/:slug/*
>
> gets you something like the default WordPress blog link structure.
> There are two 'magic' parameters, "controller" and "action" which, when
> set, decide which controller or action to call respectively. For
> example, the route:
>
>   /blog/:action/:spam
>
> when called with:
>
>   /blog/view/eggs/
>
> will call the "view" action with $this->params['spam'] set to "eggs".
>
> > 2. Can I use regular expressions in Routes like on mod rewrite? How?
> > The manual doesn't mention it.
>
> Just use regular Perl-compatible regexs.
>
> > 3. Can I still use URL query string parameters using "?" ? Or does
> > cake only use the /controller/action/param/param... convention?
>
> Cake has a different method of handling query string parameters. My
> advice is to construct a controller action to display $this->params and
> see how they are handled.
>
> > Hope I am making myself clear. Sorry for the long message.
>
> Hopefully someone else can help with the rest if the above does not
> help you solve the problem yourself. Note that the CakePHP source is
> very readable for a PHP program, so examining the dispatcher code may
> make sense than any of this.
>
> Best wishes,
>
> --
>  Chris Lamb, Leamington Spa, UKGPG: 0x634F9A20
>
>  signature.asc
> 1KDownload


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Please help me understand URL and Routes in Cake

2007-02-28 Thread barduck


Hi,

I am trying to understand how friendly URLs and "Routes" work in Cake
and have few of questions that might be trivial but I can't seem to
find an answer in the documentation.

I am familiar with url rewriting from other platforms where I used a
similar functionality of mod rewrite to map logical URLs to physical
server paths. I understand that Cake does this in two phases, one
using apache mod rewrite to pass the rest of the path to cake and the
second one by "Routes" to further route the URL in cake internally. Is
this correct?

I assume that the major purpose of the Routes is to map URLs to
controllers, functions and parameters.

Questions:

1. I've seen a colon (:) used in the manual in routes config (like /
blog/:action/* ). What is the special meaning of the colon? It isn't
mentioned anywhere.
2. Can I use regular expressions in Routes like on mod rewrite? How?
The manual doesn't mention it.
3. Can I still use URL query string parameters using "?" ? Or does
cake only use the /controller/action/param/param... convention?

And now to a real example:

Suppose I have a Model called Unit, so I would like to have a view to
show multiple units in table, with various filters and sorted
parameters, and a view that shows the information on a single unit.

So, I'd like to have the following URLs
/units- for a view showing a table of multiple units
/units/- for a view of the single unit (no, I don't
want to use the action in the URL like /units/view/, I'd
like to keep this one as short and simple as possible)

I defined the following Routes:

$Route->connect('/units', array('controller' => 'units', 'action' =>
'index'));
$Route->connect('/units/*', array('controller' => 'units', 'action' =>
'view'));

So far everything works fine.

Now I would like to accomplish 2 additional things:

1. Have parameters passed to the /units/ index view (like filters and
sort columns) on the URL. I would normally do this with query string
parameters:
/units?sort=column&filer=.&...
How do I do this in Cake so it doesn't interfere with the single unit
view?

2. I would like to be able to pass multiple units to the index view
and show these units in the same multiple units table (with unknown
parameter count). Like this
/units/unit1+unit2+units3
OR
/units/unit1/unit2/unit3/...

How do I define unknown count of parameters in Routes and how do I do
this without interfering with the single unit view?


Hope I am making myself clear. Sorry for the long message.

Thanks in advance!

- barduck


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---