CodeGen foreach - break

thread: 8 messages  |  last: a year ago  |  started: thursday, march 25, 2010, 9:42 am pdt


#1  |  Sebastien Dube (Guelph, Ontario) Canada
Thursday, March 25, 2010, 9:42 AM PDT

Hi,

I have a situation in my codegen template where I loop through all my $objColumns and if at least one of them is a QateTime, for example, i want to write an include statement.

Now, you'll understand that the include statement doesn't need to be written for every columns that satisfy the condition, but only once. So I thought of using a break to exit the foreach loop. It seems not possible. Any idea how this is achieve during codegen?


Thanks

#2  |  VexedPanda (Calgary, AB) Canada
Thursday, March 25, 2010, 12:10 PM PDT

I'm unsure if QCodo's codegen templates support the break command. My guess is not.
QCubed has support for normal PHP based templates for codegen (meaning the templates can do anything you can do in PHP) if you are interested in switching:

http://qcu.be

#3  |  Sebastien Dube (Guelph, Ontario) Canada
Thursday, March 25, 2010, 1:34 PM PDT

Would it be possible to trade only the codegen engine?

#4  |  Mike Ho (Sunnyvale, CA) United States of America Qcodo Administrator
Thursday, March 25, 2010, 1:57 PM PDT

To take a step back, what are you trying to achieve with the include statement that you are wanting to throw in?

It's definitely a very unique use case / request, so I just wanted to learn a bit more.

Thanks!

#5  |  Sebastien Dube (Guelph, Ontario) Canada
Monday, March 29, 2010, 12:57 PM PDT

Hi Mike,

I want to add code if at least one of the column as a defined property that satisfy a condition.

in Other word,

I try to do a

foreach($column as $c){
 if(c->x == 1){
   WRITE "include(myclass.php);"
   OR WRITE "$s = $c->x";
   break;
 }
}

Yes, you might say use the require_once but it is just an example.

Thanks

#6  |  Sebastien Dube (Guelph, Ontario) Canada
Monday, March 29, 2010, 1:04 PM PDT

Mike, I have answered your question, very high level I know.

I also found a solution to my “issue”.

I have written a Class of static function MyQCodeGenHelper.
When i need something more “special”, I simply create a function that return the desired code.

If you have a better way of doing so, let me know. I'll be happy to use it and not have to switch to QCubed.

thanks

#7  |  Mike Ho (Sunnyvale, CA) United States of America Qcodo Administrator
Monday, March 29, 2010, 2:14 PM PDT

Yes, that is definitely a clean approach.

But even better... remember that any class which inherits from a “Base” class or a “Gen” class is intended to be customized by the user.

So note that QCodeGen.class.php in includes/qcodo/codegen extends from QCodeGenBase.class.php. You can feel free to actually place any of your custom methods in QCodeGen.class.php if you wish, including overrides of existing Qcodo functionality, as well as any custom static functions like the ones you have already written.

#8  |  Sebastien Dube (Guelph, Ontario) Canada
Thursday, April 1, 2010, 5:36 AM PDT

Yes got that!

I just like to keep things extra seperated :-)

Just in case that I update my QCodo version too fast.

Thanks for your answer



Copyright © 2005 - 2012, Quasidea Development, LLC
This open-source framework for PHP is released under the terms of The MIT License.