PHP newbie (generating HTML content in a generic way)- HOW ?

PHP newbie (generating HTML content in a generic way)- HOW ?

am 10.04.2008 17:52:14 von Ronald Raygun

Sorry for the crossposting - I'm not sure which is the most
active/relevant php ng yet ....


Hi, I am a PHP newbie, but have been programming C/C++ for over 10
years, so in that respect, I'm not a programming noob.

I am putting together a few web pages and I want to 'modularize' the
page content into 'blocks', so that I have php script responsible for
creating different blocks - e.g.

header.php (responsible for creating header section)
footer.php (responsible for creating footer section)
lhsnavig.php (responsible for creating lefthandside menu navigation section)

etc ....

can some one please provide me with skeleton code that I can use to
create such a 'framework' ? MTIA

Re: PHP newbie (generating HTML content in a generic way)- HOW ?

am 10.04.2008 18:05:46 von Guillaume

Ronald Raygun a écrit :
> can some one please provide me with skeleton code that I can use to
> create such a 'framework' ? MTIA

Smarty is an easy one, not really a framework, it's a template engine
which can help you with your request.

http://www.smarty.net/

Regards,
--
Guillaume

Re: PHP newbie (generating HTML content in a generic way)- HOW ?

am 10.04.2008 18:05:46 von Guillaume

Ronald Raygun a écrit :
> can some one please provide me with skeleton code that I can use to
> create such a 'framework' ? MTIA

Smarty is an easy one, not really a framework, it's a template engine
which can help you with your request.

http://www.smarty.net/

Regards,
--
Guillaume

Re: PHP newbie (generating HTML content in a generic way)- HOW ?

am 10.04.2008 18:35:09 von Ronald Raygun

Guillaume wrote:
> Ronald Raygun a écrit :
>
>> can some one please provide me with skeleton code that I can use to
>> create such a 'framework' ? MTIA
>
>
> Smarty is an easy one, not really a framework, it's a template engine
> which can help you with your request.
>
> http://www.smarty.net/
>
> Regards,


Hi Guillame,

I know about smarty - even though its quite 'lightweight', its too much
of an overhead (not to mention leaning curve) for what I want to do,
which is create little scripts, each of which generates a 'block' of
html code - and then combining all of the little 'blocks' of html into
an html code.

This way, I can easily and quickly, build little libraries (PHP
scripts), each of which builds specific html 'blocks', e.g. navigation
menus etc, so I can quickly put a page together using these blocks.

The problem is not how to write the script that generates the html
(thats basically a case of using the echo statement), its how I can use
those 'little blocks' in a single page - this will save me typing the
same text over and over in my pages - and also reduce possibility of
error, provide code resuse etc, etc...

Re: PHP newbie (generating HTML content in a generic way)- HOW ?

am 10.04.2008 18:35:09 von Ronald Raygun

Guillaume wrote:
> Ronald Raygun a écrit :
>
>> can some one please provide me with skeleton code that I can use to
>> create such a 'framework' ? MTIA
>
>
> Smarty is an easy one, not really a framework, it's a template engine
> which can help you with your request.
>
> http://www.smarty.net/
>
> Regards,


Hi Guillame,

I know about smarty - even though its quite 'lightweight', its too much
of an overhead (not to mention leaning curve) for what I want to do,
which is create little scripts, each of which generates a 'block' of
html code - and then combining all of the little 'blocks' of html into
an html code.

This way, I can easily and quickly, build little libraries (PHP
scripts), each of which builds specific html 'blocks', e.g. navigation
menus etc, so I can quickly put a page together using these blocks.

The problem is not how to write the script that generates the html
(thats basically a case of using the echo statement), its how I can use
those 'little blocks' in a single page - this will save me typing the
same text over and over in my pages - and also reduce possibility of
error, provide code resuse etc, etc...

Re: PHP newbie (generating HTML content in a generic way)- HOW ?

am 10.04.2008 19:07:46 von zeldorblat

On Apr 10, 12:35 pm, Ronald Raygun wrote:
> Guillaume wrote:
> > Ronald Raygun a =E9crit :
>
> >> can some one please provide me with skeleton code that I can use to
> >> create such a 'framework' ? MTIA
>
> > Smarty is an easy one, not really a framework, it's a template engine
> > which can help you with your request.
>
> >http://www.smarty.net/
>
> > Regards,
>
> Hi Guillame,
>
> I know about smarty - even though its quite 'lightweight', its too much
> of an overhead (not to mention leaning curve) for what I want to do,
> which is create little scripts, each of which generates a 'block' of
> html code - and then combining all of the little 'blocks' of html into
> an html code.
>
> This way, I can easily and quickly, build little libraries (PHP
> scripts), each of which builds specific html 'blocks', e.g. navigation
> menus etc, so I can quickly put a page together using these blocks.
>
> The problem is not how to write the script that generates the html
> (thats basically a case of using the echo statement), its how I can use
> those 'little blocks' in a single page - this will save me typing the
> same text over and over in my pages - and also reduce possibility of
> error, provide code resuse etc, etc...

Re: PHP newbie (generating HTML content in a generic way)- HOW ?

am 10.04.2008 19:07:46 von zeldorblat

On Apr 10, 12:35 pm, Ronald Raygun wrote:
> Guillaume wrote:
> > Ronald Raygun a =E9crit :
>
> >> can some one please provide me with skeleton code that I can use to
> >> create such a 'framework' ? MTIA
>
> > Smarty is an easy one, not really a framework, it's a template engine
> > which can help you with your request.
>
> >http://www.smarty.net/
>
> > Regards,
>
> Hi Guillame,
>
> I know about smarty - even though its quite 'lightweight', its too much
> of an overhead (not to mention leaning curve) for what I want to do,
> which is create little scripts, each of which generates a 'block' of
> html code - and then combining all of the little 'blocks' of html into
> an html code.
>
> This way, I can easily and quickly, build little libraries (PHP
> scripts), each of which builds specific html 'blocks', e.g. navigation
> menus etc, so I can quickly put a page together using these blocks.
>
> The problem is not how to write the script that generates the html
> (thats basically a case of using the echo statement), its how I can use
> those 'little blocks' in a single page - this will save me typing the
> same text over and over in my pages - and also reduce possibility of
> error, provide code resuse etc, etc...

Re: PHP newbie (generating HTML content in a generic way)- HOW ?

am 10.04.2008 20:41:52 von webmasterNOSPAMTHANKS

*** Ronald Raygun escribió/wrote (Thu, 10 Apr 2008 17:35:09 +0100):
> The problem is not how to write the script that generates the html
> (thats basically a case of using the echo statement), its how I can use
> those 'little blocks' in a single page - this will save me typing the
> same text over and over in my pages - and also reduce possibility of
> error, provide code resuse etc, etc...

If you mean blocks like headers, footers, navigation bars... I've always
kept them in individual files inside a directory called "inc" (for
"included files", since I insert them with the PHP include construct).
They're typically plain HTML with some PHP bits inside.





My site pages have a very basic skeleton (all design goes in *.css and *.inc.php files):



$title = 'Template';

require($_SERVER['DOCUMENT_ROOT'] . '/inc/config.inc.php');

?>

borrame.com ¤ <?=htmlspecialchars($title)?>















Here comes content.














--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor en cubitos: http://www.demogracia.com
--

Re: PHP newbie (generating HTML content in a generic way)- HOW ?

am 10.04.2008 20:41:52 von webmasterNOSPAMTHANKS

*** Ronald Raygun escribió/wrote (Thu, 10 Apr 2008 17:35:09 +0100):
> The problem is not how to write the script that generates the html
> (thats basically a case of using the echo statement), its how I can use
> those 'little blocks' in a single page - this will save me typing the
> same text over and over in my pages - and also reduce possibility of
> error, provide code resuse etc, etc...

If you mean blocks like headers, footers, navigation bars... I've always
kept them in individual files inside a directory called "inc" (for
"included files", since I insert them with the PHP include construct).
They're typically plain HTML with some PHP bits inside.





My site pages have a very basic skeleton (all design goes in *.css and *.inc.php files):



$title = 'Template';

require($_SERVER['DOCUMENT_ROOT'] . '/inc/config.inc.php');

?>

borrame.com ¤ <?=htmlspecialchars($title)?>















Here comes content.














--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor en cubitos: http://www.demogracia.com
--

Re: PHP newbie (generating HTML content in a generic way)- HOW ?

am 10.04.2008 23:45:17 von Ronald Raygun

Álvaro G. Vicario wrote:
> *** Ronald Raygun escribió/wrote (Thu, 10 Apr 2008 17:35:09 +0100):
>
>>The problem is not how to write the script that generates the html
>>(thats basically a case of using the echo statement), its how I can use
>>those 'little blocks' in a single page - this will save me typing the
>>same text over and over in my pages - and also reduce possibility of
>>error, provide code resuse etc, etc...
>
>
> If you mean blocks like headers, footers, navigation bars... I've always
> kept them in individual files inside a directory called "inc" (for
> "included files", since I insert them with the PHP include construct).
> They're typically plain HTML with some PHP bits inside.
>
>
>


>
>
> My site pages have a very basic skeleton (all design goes in *.css and *.inc.php files):
>
>
> >
> $title = 'Template';
>
> require($_SERVER['DOCUMENT_ROOT'] . '/inc/config.inc.php');
>
> ?>
>
> borrame.com ¤ <?=htmlspecialchars($title)?>
>
>
>
>
>
>
>
>
>

>
>
>


>
>
>
>

Here comes content.


>
>

>
>
>
>
>
>
>
>
>
>

Thanks Álvaro, this looks like EXACTLY what I was looking for. By the
way, what is the codigo() function used for ? (is it a spanish word or a
PHP keyword)?

Re: PHP newbie (generating HTML content in a generic way)- HOW ?

am 10.04.2008 23:45:17 von Ronald Raygun

Álvaro G. Vicario wrote:
> *** Ronald Raygun escribió/wrote (Thu, 10 Apr 2008 17:35:09 +0100):
>
>>The problem is not how to write the script that generates the html
>>(thats basically a case of using the echo statement), its how I can use
>>those 'little blocks' in a single page - this will save me typing the
>>same text over and over in my pages - and also reduce possibility of
>>error, provide code resuse etc, etc...
>
>
> If you mean blocks like headers, footers, navigation bars... I've always
> kept them in individual files inside a directory called "inc" (for
> "included files", since I insert them with the PHP include construct).
> They're typically plain HTML with some PHP bits inside.
>
>
>


>
>
> My site pages have a very basic skeleton (all design goes in *.css and *.inc.php files):
>
>
> >
> $title = 'Template';
>
> require($_SERVER['DOCUMENT_ROOT'] . '/inc/config.inc.php');
>
> ?>
>
> borrame.com ¤ <?=htmlspecialchars($title)?>
>
>
>
>
>
>
>
>
>

>
>
>


>
>
>
>

Here comes content.


>
>

>
>
>
>
>
>
>
>
>
>

Thanks Álvaro, this looks like EXACTLY what I was looking for. By the
way, what is the codigo() function used for ? (is it a spanish word or a
PHP keyword)?

Re: PHP newbie (generating HTML content in a generic way)- HOW ?

am 11.04.2008 03:26:58 von gn501957

Ronald Raygun wrote:
>
>
> �lvaro G. Vicario wrote:
>> *** Ronald Raygun escribi�/wrote (Thu, 10 Apr 2008 17:35:09 +0100):
>>
>>> The problem is not how to write the script that generates the html
>>> (thats basically a case of using the echo statement), its how I can
>>> use those 'little blocks' in a single page - this will save me typing
>>> the same text over and over in my pages - and also reduce possibility
>>> of error, provide code resuse etc, etc...
>>
>>
>> If you mean blocks like headers, footers, navigation bars... I've always
>> kept them in individual files inside a directory called "inc" (for
>> "included files", since I insert them with the PHP include construct).
>> They're typically plain HTML with some PHP bits inside.
>>
>>
>>


>>
>>
>> My site pages have a very basic skeleton (all design goes in *.css and
>> *.inc.php files):
>>
>>
>> >>
>> $title = 'Template';
>>
>> require($_SERVER['DOCUMENT_ROOT'] . '/inc/config.inc.php');
>>
>> ?> >> "http://www.w3.org/TR/html4/strict.dtd">
>>
>> borrame.com ¤ <?=htmlspecialchars($title)?>
>>
>>
>>
>>
>>
>>
>>
>>
>>

>>
>>
>>


>>
>>
>>
>>

Here comes content.


>>
>>

>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>
> Thanks �lvaro, this looks like EXACTLY what I was looking for. By the
> way, what is the codigo() function used for ? (is it a spanish word or a
> PHP keyword)?

Not to speak for the poster Vicario or anything here, but codigo() could
be a user-defined function defined in one of the many include()ed source
code files.... The parameter passed to the function is quite possibly a
reference to an SQL script to execute when the function is called....

...gk

Re: PHP newbie (generating HTML content in a generic way)- HOW ?

am 11.04.2008 03:26:58 von gn501957

Ronald Raygun wrote:
>
>
> �lvaro G. Vicario wrote:
>> *** Ronald Raygun escribi�/wrote (Thu, 10 Apr 2008 17:35:09 +0100):
>>
>>> The problem is not how to write the script that generates the html
>>> (thats basically a case of using the echo statement), its how I can
>>> use those 'little blocks' in a single page - this will save me typing
>>> the same text over and over in my pages - and also reduce possibility
>>> of error, provide code resuse etc, etc...
>>
>>
>> If you mean blocks like headers, footers, navigation bars... I've always
>> kept them in individual files inside a directory called "inc" (for
>> "included files", since I insert them with the PHP include construct).
>> They're typically plain HTML with some PHP bits inside.
>>
>>
>>


>>
>>
>> My site pages have a very basic skeleton (all design goes in *.css and
>> *.inc.php files):
>>
>>
>> >>
>> $title = 'Template';
>>
>> require($_SERVER['DOCUMENT_ROOT'] . '/inc/config.inc.php');
>>
>> ?> >> "http://www.w3.org/TR/html4/strict.dtd">
>>
>> borrame.com ¤ <?=htmlspecialchars($title)?>
>>
>>
>>
>>
>>
>>
>>
>>
>>

>>
>>
>>


>>
>>
>>
>>

Here comes content.


>>
>>

>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>
> Thanks �lvaro, this looks like EXACTLY what I was looking for. By the
> way, what is the codigo() function used for ? (is it a spanish word or a
> PHP keyword)?

Not to speak for the poster Vicario or anything here, but codigo() could
be a user-defined function defined in one of the many include()ed source
code files.... The parameter passed to the function is quite possibly a
reference to an SQL script to execute when the function is called....

...gk

Re: PHP newbie (generating HTML content in a generic way)- HOW ?

am 11.04.2008 17:40:27 von webmasterNOSPAMTHANKS

*** Ronald Raygun escribió/wrote (Thu, 10 Apr 2008 22:45:17 +0100):
> Thanks Álvaro, this looks like EXACTLY what I was looking for. By the
> way, what is the codigo() function used for ? (is it a spanish word or a
> PHP keyword)?

It's a custom function I use in the site the sample comes from. I just
forgot to remove it <:-)


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor en cubitos: http://www.demogracia.com
--

Re: PHP newbie (generating HTML content in a generic way)- HOW ?

am 11.04.2008 17:40:27 von webmasterNOSPAMTHANKS

*** Ronald Raygun escribió/wrote (Thu, 10 Apr 2008 22:45:17 +0100):
> Thanks Álvaro, this looks like EXACTLY what I was looking for. By the
> way, what is the codigo() function used for ? (is it a spanish word or a
> PHP keyword)?

It's a custom function I use in the site the sample comes from. I just
forgot to remove it <:-)


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor en cubitos: http://www.demogracia.com
--

Re: PHP newbie (generating HTML content in a generic way)- HOW ?

am 11.04.2008 22:02:31 von kenoli

I do something similar. In addition, you can create functions and
call them at various points in the page to insert content of all sorts
along with appropriate html and tags, style attributes and
javascript. Using a master function with a switch operator, you can
vary the template, location of content in the page and other
variables. I actually found it was easier to set this up myself than
to learn Smarty, which looked like a challenge.

I'm really happy with what I have and can customize it to do exactly
what I want it to do.

--Kenoli

On Apr 11, 8:40=A0am, "=C1lvaro G. Vicario"
wrote:
> *** Ronald Raygun escribi=F3/wrote (Thu, 10 Apr 2008 22:45:17 +0100):
>
> > Thanks =C1lvaro, this looks like EXACTLY what I was looking for. By the
> > way, what is the codigo() function used for ? (is it a spanish word or a=

> > PHP keyword)?
>
> It's a custom function I use in the site the sample comes from. I just
> forgot to remove it <:-)
>
> --
> --http://alvaro.es- =C1lvaro G. Vicario - Burgos, Spain
> -- Mi sitio sobre programaci=F3n web:http://bits.demogracia.com
> -- Mi web de humor en cubitos:http://www.demogracia.com
> --

Re: PHP newbie (generating HTML content in a generic way)- HOW ?

am 11.04.2008 22:02:31 von kenoli

I do something similar. In addition, you can create functions and
call them at various points in the page to insert content of all sorts
along with appropriate html and tags, style attributes and
javascript. Using a master function with a switch operator, you can
vary the template, location of content in the page and other
variables. I actually found it was easier to set this up myself than
to learn Smarty, which looked like a challenge.

I'm really happy with what I have and can customize it to do exactly
what I want it to do.

--Kenoli

On Apr 11, 8:40=A0am, "=C1lvaro G. Vicario"
wrote:
> *** Ronald Raygun escribi=F3/wrote (Thu, 10 Apr 2008 22:45:17 +0100):
>
> > Thanks =C1lvaro, this looks like EXACTLY what I was looking for. By the
> > way, what is the codigo() function used for ? (is it a spanish word or a=

> > PHP keyword)?
>
> It's a custom function I use in the site the sample comes from. I just
> forgot to remove it <:-)
>
> --
> --http://alvaro.es- =C1lvaro G. Vicario - Burgos, Spain
> -- Mi sitio sobre programaci=F3n web:http://bits.demogracia.com
> -- Mi web de humor en cubitos:http://www.demogracia.com
> --

Re: PHP newbie (generating HTML content in a generic way)- HOW ?

am 12.04.2008 03:23:27 von Jerry Stuckle

kenoli wrote:
> On Apr 11, 8:40 am, "Álvaro G. Vicario"
> wrote:
>> *** Ronald Raygun escribió/wrote (Thu, 10 Apr 2008 22:45:17 +0100):
>>
>>> Thanks Álvaro, this looks like EXACTLY what I was looking for. By the
>>> way, what is the codigo() function used for ? (is it a spanish word or a
>>> PHP keyword)?
>> It's a custom function I use in the site the sample comes from. I just
>> forgot to remove it <:-)
>>
>> --
>> --http://alvaro.es- Álvaro G. Vicario - Burgos, Spain
>> -- Mi sitio sobre programación web:http://bits.demogracia.com
>> -- Mi web de humor en cubitos:http://www.demogracia.com
>> --
>
>
> I do something similar. In addition, you can create functions and
> call them at various points in the page to insert content of all sorts
> along with appropriate html and tags, style attributes and
> javascript. Using a master function with a switch operator, you can
> vary the template, location of content in the page and other
> variables. I actually found it was easier to set this up myself than
> to learn Smarty, which looked like a challenge.
>
> I'm really happy with what I have and can customize it to do exactly
> what I want it to do.
>
> --Kenoli
>

(Top posting fixed)

Much better than using a switch() function is to use classes - or
different functions to do different things. Never have one function do
multiple things - like output different HTML based on a switch()
statement. It makes troubleshooting a nightmare.

P.S. Please don't top post. Thanks.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: PHP newbie (generating HTML content in a generic way)- HOW ?

am 12.04.2008 03:23:27 von Jerry Stuckle

kenoli wrote:
> On Apr 11, 8:40 am, "Álvaro G. Vicario"
> wrote:
>> *** Ronald Raygun escribió/wrote (Thu, 10 Apr 2008 22:45:17 +0100):
>>
>>> Thanks Álvaro, this looks like EXACTLY what I was looking for. By the
>>> way, what is the codigo() function used for ? (is it a spanish word or a
>>> PHP keyword)?
>> It's a custom function I use in the site the sample comes from. I just
>> forgot to remove it <:-)
>>
>> --
>> --http://alvaro.es- Álvaro G. Vicario - Burgos, Spain
>> -- Mi sitio sobre programación web:http://bits.demogracia.com
>> -- Mi web de humor en cubitos:http://www.demogracia.com
>> --
>
>
> I do something similar. In addition, you can create functions and
> call them at various points in the page to insert content of all sorts
> along with appropriate html and tags, style attributes and
> javascript. Using a master function with a switch operator, you can
> vary the template, location of content in the page and other
> variables. I actually found it was easier to set this up myself than
> to learn Smarty, which looked like a challenge.
>
> I'm really happy with what I have and can customize it to do exactly
> what I want it to do.
>
> --Kenoli
>

(Top posting fixed)

Much better than using a switch() function is to use classes - or
different functions to do different things. Never have one function do
multiple things - like output different HTML based on a switch()
statement. It makes troubleshooting a nightmare.

P.S. Please don't top post. Thanks.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: PHP newbie (generating HTML content in a generic way)- HOW ?

am 12.04.2008 06:19:30 von kenoli

On Apr 11, 6:23=A0pm, Jerry Stuckle wrote:
> kenoli wrote:
> > On Apr 11, 8:40 am, "=C1lvaro G. Vicario"
> > wrote:
> >> *** Ronald Raygun escribi=F3/wrote (Thu, 10 Apr 2008 22:45:17 +0100):
>
> >>> Thanks =C1lvaro, this looks like EXACTLY what I was looking for. By th=
e
> >>> way, what is the codigo() function used for ? (is it a spanish word or=
a
> >>> PHP keyword)?
> >> It's a custom function I use in the site the sample comes from. I just
> >> forgot to remove it <:-)
>
> >> --
> >> --http://alvaro.es-=C1lvaro G. Vicario - Burgos, Spain
> >> -- Mi sitio sobre programaci=F3n web:http://bits.demogracia.com
> >> -- Mi web de humor en cubitos:http://www.demogracia.com
> >> --
>
> =A0> I do something similar. =A0In addition, you can create functions and
> =A0> call them at various points in the page to insert content of all sort=
s
> =A0> along with appropriate html and tags, style attributes and
> =A0> javascript. =A0Using a master function with a switch operator, you ca=
n
> =A0> vary the template, location of content in the page and other
> =A0> variables. =A0I actually found it was easier to set this up myself th=
an
> =A0> to learn Smarty, which looked like a challenge.
> =A0>
> =A0> I'm really happy with what I have and can customize it to do exactly
> =A0> what I want it to do.
> =A0>
> =A0> --Kenoli
> =A0>
>
> (Top posting fixed)
>
> Much better than using a switch() function is to use classes - or
> different functions to do different things. =A0Never have one function do
> multiple things - like output different HTML based on a switch()
> statement. =A0It makes troubleshooting a nightmare.
>
> P.S. Please don't top post. =A0Thanks.
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================

The usefulness of the switch operator for me is that based on a
particular field or combination of fields in a record it can select a
specific template, a specific page placement in a template, a
particular navigation function, data from a particular related table,
etc. As far as I can see, to do this kind of thing is going to
require some kind of conditional operator to select the appropriate
templates and functions and it seemed efficient to me to have it all
taken place in one location using a switch, and pretty easy to debug.
I'd be interested knowing more about the downside of this and
alternative constructs. Even using a class would require some kind of
switch like conditional within the class.

The way I am doing this is to send a get query to a php script in a
file that sets a series of variables based on what it receives
triggering a switch that selects the right template and functions
based on what it receives. It seemed pretty efficient and elegant to
me, though I am flying by the seat of my pants and a lot of non-
programmer intuition. I essentially have one script creating all the
pages in my site by connecting data through a set of functions applied
to a set of templates.

--Kenoli

Re: PHP newbie (generating HTML content in a generic way)- HOW ?

am 12.04.2008 06:19:30 von kenoli

On Apr 11, 6:23=A0pm, Jerry Stuckle wrote:
> kenoli wrote:
> > On Apr 11, 8:40 am, "=C1lvaro G. Vicario"
> > wrote:
> >> *** Ronald Raygun escribi=F3/wrote (Thu, 10 Apr 2008 22:45:17 +0100):
>
> >>> Thanks =C1lvaro, this looks like EXACTLY what I was looking for. By th=
e
> >>> way, what is the codigo() function used for ? (is it a spanish word or=
a
> >>> PHP keyword)?
> >> It's a custom function I use in the site the sample comes from. I just
> >> forgot to remove it <:-)
>
> >> --
> >> --http://alvaro.es-=C1lvaro G. Vicario - Burgos, Spain
> >> -- Mi sitio sobre programaci=F3n web:http://bits.demogracia.com
> >> -- Mi web de humor en cubitos:http://www.demogracia.com
> >> --
>
> =A0> I do something similar. =A0In addition, you can create functions and
> =A0> call them at various points in the page to insert content of all sort=
s
> =A0> along with appropriate html and tags, style attributes and
> =A0> javascript. =A0Using a master function with a switch operator, you ca=
n
> =A0> vary the template, location of content in the page and other
> =A0> variables. =A0I actually found it was easier to set this up myself th=
an
> =A0> to learn Smarty, which looked like a challenge.
> =A0>
> =A0> I'm really happy with what I have and can customize it to do exactly
> =A0> what I want it to do.
> =A0>
> =A0> --Kenoli
> =A0>
>
> (Top posting fixed)
>
> Much better than using a switch() function is to use classes - or
> different functions to do different things. =A0Never have one function do
> multiple things - like output different HTML based on a switch()
> statement. =A0It makes troubleshooting a nightmare.
>
> P.S. Please don't top post. =A0Thanks.
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================

The usefulness of the switch operator for me is that based on a
particular field or combination of fields in a record it can select a
specific template, a specific page placement in a template, a
particular navigation function, data from a particular related table,
etc. As far as I can see, to do this kind of thing is going to
require some kind of conditional operator to select the appropriate
templates and functions and it seemed efficient to me to have it all
taken place in one location using a switch, and pretty easy to debug.
I'd be interested knowing more about the downside of this and
alternative constructs. Even using a class would require some kind of
switch like conditional within the class.

The way I am doing this is to send a get query to a php script in a
file that sets a series of variables based on what it receives
triggering a switch that selects the right template and functions
based on what it receives. It seemed pretty efficient and elegant to
me, though I am flying by the seat of my pants and a lot of non-
programmer intuition. I essentially have one script creating all the
pages in my site by connecting data through a set of functions applied
to a set of templates.

--Kenoli

Re: PHP newbie (generating HTML content in a generic way)- HOW ?

am 12.04.2008 14:32:51 von Jerry Stuckle

kenoli wrote:
> On Apr 11, 6:23 pm, Jerry Stuckle wrote:
>> kenoli wrote:
>>> On Apr 11, 8:40 am, "Álvaro G. Vicario"
>>> wrote:
>>>> *** Ronald Raygun escribió/wrote (Thu, 10 Apr 2008 22:45:17 +0100):
>>>>> Thanks Álvaro, this looks like EXACTLY what I was looking for. By the
>>>>> way, what is the codigo() function used for ? (is it a spanish word or a
>>>>> PHP keyword)?
>>>> It's a custom function I use in the site the sample comes from. I just
>>>> forgot to remove it <:-)
>>>> --
>>>> --http://alvaro.es-Álvaro G. Vicario - Burgos, Spain
>>>> -- Mi sitio sobre programación web:http://bits.demogracia.com
>>>> -- Mi web de humor en cubitos:http://www.demogracia.com
>>>> --
>> > I do something similar. In addition, you can create functions and
>> > call them at various points in the page to insert content of all sorts
>> > along with appropriate html and tags, style attributes and
>> > javascript. Using a master function with a switch operator, you can
>> > vary the template, location of content in the page and other
>> > variables. I actually found it was easier to set this up myself than
>> > to learn Smarty, which looked like a challenge.
>> >
>> > I'm really happy with what I have and can customize it to do exactly
>> > what I want it to do.
>> >
>> > --Kenoli
>> >
>>
>> (Top posting fixed)
>>
>> Much better than using a switch() function is to use classes - or
>> different functions to do different things. Never have one function do
>> multiple things - like output different HTML based on a switch()
>> statement. It makes troubleshooting a nightmare.
>>
>> P.S. Please don't top post. Thanks.
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck...@attglobal.net
>> ==================
>
> The usefulness of the switch operator for me is that based on a
> particular field or combination of fields in a record it can select a
> specific template, a specific page placement in a template, a
> particular navigation function, data from a particular related table,
> etc. As far as I can see, to do this kind of thing is going to
> require some kind of conditional operator to select the appropriate
> templates and functions and it seemed efficient to me to have it all
> taken place in one location using a switch, and pretty easy to debug.
> I'd be interested knowing more about the downside of this and
> alternative constructs. Even using a class would require some kind of
> switch like conditional within the class.
>
> The way I am doing this is to send a get query to a php script in a
> file that sets a series of variables based on what it receives
> triggering a switch that selects the right template and functions
> based on what it receives. It seemed pretty efficient and elegant to
> me, though I am flying by the seat of my pants and a lot of non-
> programmer intuition. I essentially have one script creating all the
> pages in my site by connecting data through a set of functions applied
> to a set of templates.
>
> --Kenoli
>

Which means anytime you need to add a new value or combination of
values, you need to redo your code. Data should never drive code.

But I'm not going to get into an argument with you as to why it's a bad
design. It sounds like you already have your mind made up.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: PHP newbie (generating HTML content in a generic way)- HOW ?

am 12.04.2008 14:32:51 von Jerry Stuckle

kenoli wrote:
> On Apr 11, 6:23 pm, Jerry Stuckle wrote:
>> kenoli wrote:
>>> On Apr 11, 8:40 am, "Álvaro G. Vicario"
>>> wrote:
>>>> *** Ronald Raygun escribió/wrote (Thu, 10 Apr 2008 22:45:17 +0100):
>>>>> Thanks Álvaro, this looks like EXACTLY what I was looking for. By the
>>>>> way, what is the codigo() function used for ? (is it a spanish word or a
>>>>> PHP keyword)?
>>>> It's a custom function I use in the site the sample comes from. I just
>>>> forgot to remove it <:-)
>>>> --
>>>> --http://alvaro.es-Álvaro G. Vicario - Burgos, Spain
>>>> -- Mi sitio sobre programación web:http://bits.demogracia.com
>>>> -- Mi web de humor en cubitos:http://www.demogracia.com
>>>> --
>> > I do something similar. In addition, you can create functions and
>> > call them at various points in the page to insert content of all sorts
>> > along with appropriate html and tags, style attributes and
>> > javascript. Using a master function with a switch operator, you can
>> > vary the template, location of content in the page and other
>> > variables. I actually found it was easier to set this up myself than
>> > to learn Smarty, which looked like a challenge.
>> >
>> > I'm really happy with what I have and can customize it to do exactly
>> > what I want it to do.
>> >
>> > --Kenoli
>> >
>>
>> (Top posting fixed)
>>
>> Much better than using a switch() function is to use classes - or
>> different functions to do different things. Never have one function do
>> multiple things - like output different HTML based on a switch()
>> statement. It makes troubleshooting a nightmare.
>>
>> P.S. Please don't top post. Thanks.
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck...@attglobal.net
>> ==================
>
> The usefulness of the switch operator for me is that based on a
> particular field or combination of fields in a record it can select a
> specific template, a specific page placement in a template, a
> particular navigation function, data from a particular related table,
> etc. As far as I can see, to do this kind of thing is going to
> require some kind of conditional operator to select the appropriate
> templates and functions and it seemed efficient to me to have it all
> taken place in one location using a switch, and pretty easy to debug.
> I'd be interested knowing more about the downside of this and
> alternative constructs. Even using a class would require some kind of
> switch like conditional within the class.
>
> The way I am doing this is to send a get query to a php script in a
> file that sets a series of variables based on what it receives
> triggering a switch that selects the right template and functions
> based on what it receives. It seemed pretty efficient and elegant to
> me, though I am flying by the seat of my pants and a lot of non-
> programmer intuition. I essentially have one script creating all the
> pages in my site by connecting data through a set of functions applied
> to a set of templates.
>
> --Kenoli
>

Which means anytime you need to add a new value or combination of
values, you need to redo your code. Data should never drive code.

But I'm not going to get into an argument with you as to why it's a bad
design. It sounds like you already have your mind made up.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: PHP newbie (generating HTML content in a generic way)- HOW ?

am 16.04.2008 20:00:19 von unknown

Post removed (X-No-Archive: yes)