Parse order PHP & EE Code
Posted: 30 July 2008 12:53 PM   [ Ignore ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  517
Joined  07-08-2008

Hello,

I have two questions, is there a way to neither select INPUT or OUTPUT for PHP code and instead make it so the page is parsed all at the same time?  I think most likely not so my second question is…

I’m having an issue trying to get dynamic information with EE code and storing it into a PHP array.  Basically I have a string in {segment_3} and I’m using PHP to explode it into an array (they are values that are variable).  Now I’m loop these values (to do all of them) and using each value to run an EE query with the subcategories plugin (this isn’t a plugin question).  Then I need to store the values that the EE query gives me back to another PHP array.

So here is my code:

<?
//get count of total sub filters
$count = 0;
                    
//put {segment_3} into an array1                
$rootnodes = explode("|", "{segment_3}");
$checkboxes = array();
                    
//loop exp:subcategories with each item in array1
$count = 0;
                
foreach (
$rootnodes as $i)
{            
    {exp
:subcategories count_entries_with_status="open" count_entries_from_weblogs="5" root_node="$i"}
                            
    
//store into array2
    
$checkboxes[$count]['id'] = "{category_id}";
    
$checkboxes[$count]['name'] = "{category_name}";
    
$checkboxes[$count]['count'] = "{entries_count}";
                            
    
{/exp:subcategories}        
                
    $count
++;    
}unset($i);
?>

So the {exp:subcategories…} takes the $i from the foreach loop.  Then my $checkboxes array takes the {category_id} and other data from the {exp:subcategories…} output.

So you see how I need a mixed order for PHP and EE code.

Any ideas or something?  Thanks


P.S. I’m not really clear if my questions should be in Tech Support or “How-to”, please advise because the forum descriptions aren’t clear.

 Signature 

.
// INTERACTIVEDEVELOPER
Phire Branding Company

Profile
 
 
Posted: 30 July 2008 01:10 PM   [ Ignore ]   [ # 1 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  19293
Joined  06-03-2002

You can’t have PHP parsed both an input and output, and they are very different stages.  You are using PHP to supply information to a tag (Input), and then want that tag’s output to provide information to your PHP (Output).  A suggested solution would be to either use a plugin for one set (or both) of the PHP, or move the tag and in the Ouput PHP to an embedded template, since each template has its own PHP parsing settings.  Make sense?

 Signature 
Profile
MSG
 
 
Posted: 30 July 2008 01:17 PM   [ Ignore ]   [ # 2 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  517
Joined  07-08-2008

Sorta makes senses and this is what I tried but couldn’t get it to work properly:

I took out the contents of the FOREACH loop and put it into another template.  I then included that template via PHP by calling it through the template URL.  I used $i as a url variable and also $count so that way I didn’t need PHP for the EE code.

My problem was with the actual PHP variable (array) that stores the values (from the EE code) within the included page.  Now I’m storing the entries in the included file, and running this include multiple times in a loop.  How can I consolidate all of these records?

 Signature 

.
// INTERACTIVEDEVELOPER
Phire Branding Company

Profile
 
 
Posted: 30 July 2008 01:30 PM   [ Ignore ]   [ # 3 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  19293
Joined  06-03-2002

Do not include it with PHP, use EE’s embeds, otherwise you’re instantiating EE multiple times for that single page request, quite wasteful.  Though again, a plugin would be superior.  Better yet, step back and describe in plain terms what you’re wanting to do that made you turn to a PHP solution to start with.  I’m trying to follow your code sample and explanation, and can’t help but think that there’s a much simpler solution in your grasp.

 Signature 
Profile
MSG
 
 
Posted: 30 July 2008 01:39 PM   [ Ignore ]   [ # 4 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  517
Joined  07-08-2008

Well, this is what we’re trying to do.

We have a “tool” that has checkboxes that can be selected to filter articles that are displayed on a page.  Within this tool, we have checkboxes with topics and subtopics (categories and subcategories in EE).  When a user clicks a topic checkbox, the subtopic checkboxes automatically change based on what was selected.  If the user selects more than one, then subtopics of both topics would be displayed.

To add some spice, this is all done with Ajax to save the user from having to reload the page.  I have it working for a single click of a checkbox, meaning not evaluating if any other checkboxes are checked.

The problem came when I wanted to evaluate ALL checkboxes that are clicked anytime they click/unclick any topic checkbox.  So via Javascript, I put into a variable all the checked boxes, then passed that to an EE template via AJAX, like:

makePOSTRequest('/index.php/ajax/tool_subtopics/' + checkedboxes + '/')

Where checkboxes was a list of ID of the parent category of the selected checkboxes.

Did I lose you? smile

So, all of that is working great and fine and leads us to the code I pasted at the start of this thread.  The data comes in, I’m taking it and exploding it and then need to print off all the subcategories that relate to the checked topics (categories).

It’s really complicated but I’m just stuck at the final step -  getting a proper list of subtopics.

Hope that helped explain it.  Maybe I am making this harder than it is so please advise me.  Thanks again.

This is the other thread which solved my first issue and gave my the idea of exploding a string (for reference): Other thread

 Signature 

.
// INTERACTIVEDEVELOPER
Phire Branding Company

Profile
 
 
Posted: 30 July 2008 01:43 PM   [ Ignore ]   [ # 5 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  19293
Joined  06-03-2002

Well, before I dig deeper, let me put two things before you that may lead you to change your implementation, and a simpler implementation.

Dynamic Parameters
Database Class

I think I’m only loosely understanding what you’re after, but the first link will show you how to make the weblog entries tag automatically filter its output based on POSTed data. The second is the documentation for EE’s database driver, which you can use in place of the subcategories tag to allow you to keep all of your PHP on the same template, without worrying about input/output parsing since you would eliminate the need to input information to tags or retrieve information from tags.

 Signature 
Profile
MSG
 
 
Posted: 30 July 2008 02:16 PM   [ Ignore ]   [ # 6 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  517
Joined  07-08-2008

Okay I’ve started to read through the documents and will see if I can find a way.

Thanks for the help

 Signature 

.
// INTERACTIVEDEVELOPER
Phire Branding Company

Profile
 
 
Posted: 30 July 2008 02:42 PM   [ Ignore ]   [ # 7 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  29221
Joined  05-15-2004

Phire, I am going to mark this thread as resolved for the time being. Derek gave you a lot to work with, but if there’s anything else, related ot not, or if you need additional assistance, please simply start a new thread in the appropriate forum. Thanks.

 Signature 

ExpressionEngine 2.0 Downloads | Docs | Bugtracker

“If the English language made any sense, lackadaisical would have something to do with a shortage of flowers.” (Doug Larson)

Profile
MSG
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1743, on December 02, 2009 03:47 PM
Total Registered Members: 120496 Total Logged-in Users: 44
Total Topics: 126566 Total Anonymous Users: 29
Total Replies: 665437 Total Guests: 291
Total Posts: 792003    
Members ( View Memberlist )