23550 Posts in 19336 Topics by 2890 members
|Go to End|
31 December 2011 at 3:23am Last edited: 31 December 2011 3:44am
Is there a way to count the number of children of each type within the children control? $TotalItems just gives the number of types of children, which is not what I'm looking for.
An example would be if you had links to genres of movies in a Children control showing comedies, action films, and westerns. $TotalItems would print 3, but I don't want to know how many genres of movies there are in the database; I want to know how many there are of each one e.g. comedy (5), action (9), western (3).
31 December 2011 at 4:43am
can you tell us more about your code? do you just use the normal page type? do you added fields?
you can use different pagetypes for different genres, then $TotalItems should work fine.
an other way is to wirte an own function where you manualy get your dataobject and then render a special template in a loop
31 December 2011 at 7:00am
Ah, well the genres were just an example. What I've got is this:
A pagetype ActionPage, with pages like "removal from library," "restriction of access," etc. These are held in ActionHolder.
ActionHolder uses % control Children % to list the titles of each page and link to them. Beside the title I'd like a count of how many of each type there are (e.g. removal from library (6), restriction of access (11)).
$Title and $Link are working as expected (they change each time), but after them $TotalItems always gives (14), which isn't what I wanted. $Count within % control Children % is always blank.
Does that make sense? I feel like this probably has a simple answer and I'm just not seeing it.
31 December 2011 at 8:33am
I understand ...
31 December 2011 at 9:00am
That returns 0 for everything.
I realized why this isn't working, and it's not working because I'd forgotten how it's all set up on the backend.
On any given ArticlePage you can check a box for Actions (corresponding to ActionPages), so I'm actually trying to do two different things at once: on ActionHolder, list and link to the Children. Also, count how many times each of those Children appear in an entirely different table.
Could I maybe write a function to count, with $this->ID as a variable to be put into the SQL, and use that function within Children? Or is it more complicated than that?
31 December 2011 at 9:15am
are your pages organized this way:
I understand it like that ... in this case $Children.count should work on the second level (ActionPage).
can you post code of ActionPage.php?
You have some Checkbox fields there and want the count of the checkd boxes right?
If so ...
To count the active checkboxes is possible with a function but not the best way to solve this, because when you add some new checkboxes you also have to modify the code again.
But post Holder ActionPage code please.
31 December 2011 at 9:43am
No, they're arranged like this:
with a many_many between them.
I figured it out, though. I wrote a function to count what I needed, and it worked once I moved it out of ActionHolder.php into ActionPage.php (since I was trying to call it in the control Children on the page ActionHolder).
Thanks for your help.
|Go to Top|