php-general Digest 18 Dec 2011 00:22:09 -0000 Issue 7614

Topics (messages 316050 through 316054):

Re: Preferred Syntax
        316050 by: Adam Richardson
        316053 by: Eric Butera

Re: dealing with this code $_POST['custom´]
        316051 by: Marc Guay

Partner needed...
        316052 by: Don Wieland

Re: Working on a Subsummary Report
        316054 by: DealTek

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
On Fri, Dec 16, 2011 at 11:53 PM, Eric Butera <eric.but...@gmail.com> wrote:

> To all the people who responded to this thread:
> It is 2011 - please stop writing code like this.
>
> To the OP:
> I'm glad you're asking questions and realizing you're not happy with
> your current abilities and suspect there's a better way.  I've read
> the replies in this thread and feel a bit let down.  Use a templating
> language - yes, I understand that is what php is for - but I won't go
> into it.  You should not be echoing, printing, or any other method of
> concatenating html dealing with escaping quotes inside your php logic
> code.  Please separate your concerns.
>
> Not sure what that means?  That's OK!  If you want to move forward,
> look up how modern frameworks deal with this issue using their views
> or template views.  You don't have to use a framework if you do not
> want to, that's perfectly fine.  If it works, it works.  But in the
> end, it the separation of logic and html is essential to code
> maintenance.


Eric,

There are many posters to this list, and there exists a broad range of
programming styles and abilities. I'll bet you're a competent programmer,
and that you've worked hard to hone your craft. It takes passion and drive
to improve one's skill set. However, I'd encourage you to focus that
passion on the list in a way that facilitates the growth of those with
questions whilst staying true to their current, specific needs.

Frankly, every answer on the list could begin with the suggestion that they
just use a framework. The list is here to help build up the entire skill
set of PHP developers.

Let's reexamine the original post:

Hello all.
> Can someone tell me which of the following is preferred and why?


Use of the word "Which" implies that there were a closed set of options
they wanted to consider, although we did offer some others, but they all
stayed relatively true to his original options.


>
>  echo "<a style='text-align:left;size:**14;font-weight:bold'
> href='/mypage.php/$page_id'>$**page_name</a><br>";
>  echo "<a style='text-align:left;size:**14;font-weight:bold'
> href='/mypage.php/".$page_id."**'>".$page_name."</a><br>";


Simple.

Please note there is no logic anywhere in this example. PHP is truly
serving merely as a templating language here. So, while I agree with the
general notion that logic should not be intermingled with markup, this
particular example does not serve as the anti-pattern you suggest.

Also, note that we aren't sure where the $page_id and $page_name variables
are coming from. In instances where these are set manually within the
script (like a view variables at the top of the page), there's no need to
escape anything. That said, you're right, if the data is coming from
somewhere else, escaping should happen, but there's not enough information
to infer that, as you say, "You should not be echoing, printing, or any
other method of concatenating html dealing with escaping quotes inside your
php logic code."


>
> When I come across the above code in line 1, I have been changing it to
> what you see in line 2 for no other reason than it delineates out better in
> BBEdit.  Is this just a preference choice or is one method better than the
> other?


The above statement suggests there's an existing codebase that was being
worked through. In this light, the answers mostly focused on answering the
OP's original question, realizing that this was existing code that he was
refactoring lightly as he goes.

This is not to say that I disagree with all that you said, as I actually
developed my own framework that:

   - Cleanly separates PHP from HTML to avoid the intermingling of logic
   and presenation:
   http://nephtaliproject.com/documentation/markup/
   - Automatically handles output escaping, input validation:
   http://nephtaliproject.com/documentation/examples/contact.php
   - And lots of other features that coincide with the general focus of
   your words.

Given that work, I think it's fair to say that I do agree with several of
your general points for web development overall. However, this question
wasn't a big picture question on how to do web development with PHP. It was
a simple question that was answered in a helpful, specific manner by
several on the list.

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

--- End Message ---
--- Begin Message ---
On Sat, Dec 17, 2011 at 12:59 AM, Adam Richardson <simples...@gmail.com> wrote:
> On Fri, Dec 16, 2011 at 11:53 PM, Eric Butera <eric.but...@gmail.com> wrote:
>>
>> To all the people who responded to this thread:
>> It is 2011 - please stop writing code like this.
>>
>> To the OP:
>> I'm glad you're asking questions and realizing you're not happy with
>> your current abilities and suspect there's a better way.  I've read
>> the replies in this thread and feel a bit let down.  Use a templating
>> language - yes, I understand that is what php is for - but I won't go
>> into it.  You should not be echoing, printing, or any other method of
>> concatenating html dealing with escaping quotes inside your php logic
>> code.  Please separate your concerns.
>>
>> Not sure what that means?  That's OK!  If you want to move forward,
>> look up how modern frameworks deal with this issue using their views
>> or template views.  You don't have to use a framework if you do not
>> want to, that's perfectly fine.  If it works, it works.  But in the
>> end, it the separation of logic and html is essential to code
>> maintenance.
>
>
> Eric,
>
> There are many posters to this list, and there exists a broad range of
> programming styles and abilities. I'll bet you're a competent programmer,
> and that you've worked hard to hone your craft. It takes passion and drive
> to improve one's skill set. However, I'd encourage you to focus that passion
> on the list in a way that facilitates the growth of those with questions
> whilst staying true to their current, specific needs.
>
> Frankly, every answer on the list could begin with the suggestion that they
> just use a framework. The list is here to help build up the entire skill set
> of PHP developers.
>
> Let's reexamine the original post:
>
>> Hello all.
>>
>> Can someone tell me which of the following is preferred and why?
>
>
> Use of the word "Which" implies that there were a closed set of options they
> wanted to consider, although we did offer some others, but they all stayed
> relatively true to his original options.
>
>>
>>
>>  echo "<a style='text-align:left;size:14;font-weight:bold'
>> href='/mypage.php/$page_id'>$page_name</a><br>";
>>  echo "<a style='text-align:left;size:14;font-weight:bold'
>> href='/mypage.php/".$page_id."'>".$page_name."</a><br>";
>
>
> Simple.
>
> Please note there is no logic anywhere in this example. PHP is truly serving
> merely as a templating language here. So, while I agree with the general
> notion that logic should not be intermingled with markup, this particular
> example does not serve as the anti-pattern you suggest.
>
> Also, note that we aren't sure where the $page_id and $page_name variables
> are coming from. In instances where these are set manually within the script
> (like a view variables at the top of the page), there's no need to escape
> anything. That said, you're right, if the data is coming from somewhere
> else, escaping should happen, but there's not enough information to infer
> that, as you say, "You should not be echoing, printing, or any other method
> of concatenating html dealing with escaping quotes inside your php
> logic code."
>
>>
>>
>> When I come across the above code in line 1, I have been changing it to
>> what you see in line 2 for no other reason than it delineates out better in
>> BBEdit.  Is this just a preference choice or is one method better than the
>> other?
>
>
> The above statement suggests there's an existing codebase that was being
> worked through. In this light, the answers mostly focused on answering the
> OP's original question, realizing that this was existing code that he was
> refactoring lightly as he goes.
>
> This is not to say that I disagree with all that you said, as I actually
> developed my own framework that:
>
> Cleanly separates PHP from HTML to avoid the intermingling of logic and
> presenation:
> http://nephtaliproject.com/documentation/markup/
> Automatically handles output escaping, input validation:
> http://nephtaliproject.com/documentation/examples/contact.php
> And lots of other features that coincide with the general focus of your
> words.
>
> Given that work, I think it's fair to say that I do agree with several of
> your general points for web development overall. However, this question
> wasn't a big picture question on how to do web development with PHP. It was
> a simple question that was answered in a helpful, specific manner by several
> on the list.
>
> Adam
>
> --
> Nephtali:  A simple, flexible, fast, and security-focused PHP framework
> http://nephtaliproject.com

Hi Adam,

Thanks for the reply, noted!  I was coming from the angle that I've
had to deal with a lot of code that is 2000 lines of
php/html/javascript inside heredocs, mixed quote escaping, etc.  I was
hoping to prevent that from becoming a new thing in this persons code
if that was the case.  Apologies for assuming.

--- End Message ---
--- Begin Message ---
Just forwarding Carlos' response to the list...


---------- Forwarded message ----------
From: Carlos Sura <carlos.su...@googlemail.com>
Date: 17 December 2011 01:15
Subject: Re: [PHP] dealing with this code $_POST['custom´]
To: Marc Guay <marc.g...@gmail.com>




On 16 December 2011 15:57, Marc Guay <marc.g...@gmail.com> wrote:
>
> > $saving_list = $_POST['custom'] == 'FR' ? 148 : 147;
>
> Hi there, here's a quick translatation of this code that might help
> you understand it better:
>
> if ($_POST['custom'] == 'FR'){
>  $saving_list = 148;
> }
> else{
>  $saving_list = 147;
> }



Hello,

Thank you both for answer me.

Also I would like to thank you Marc Guay, because with your answer I
figured out how to do it.

My code is like this:

//$saving_list = $_POST['custom'] == 'FR' ? 148 : 147;
  if ($_POST['custom'] == 'FR'){
                $saving_list = 148;
               }
  if ($_POST['custom'] == 'EN'){
                $saving_list = 147;
               }
 else{
 $saving_list = 152;
 }

I'm not sure if that's the best way, but it is working for me as I
expected, althought any other recommendation would be great.

Regards
--
Carlos Sura.-
www.carlossura.com

--- End Message ---
--- Begin Message ---
Greetings,

I am looking for a partner to help me finish a site and share in profits. The site is PHP/mySQL (using jQuery and jQuery UI). A majority of it is finished. I need to finish up a few more modules.

The name of the site is Sport-Hub.com. I would glad to share more about the services the site will provide to the public, but would require a NDA to be signed first.

If you have interest in a potential back-end revenue stream in exchange for you time in coding, please contact me PRIVATELY.

Thanks!

Don Wieland
D W   D a t a   C o n c e p t s

--- End Message ---
--- Begin Message ---
On Dec 16, 2011, at 12:56 PM, Jim Lucas wrote:
> 
> 
> 1) What does your db schema look like?
> 2) What SQL do you currently use?
> 3) What criteria do you want to use to sort the data?
> 4) Will the output be plaintext, html, etc?
> 5) Is this going to be used to import into another app, or display & printing?
> 

Hi Jim - sorry I didn't see this earlier...


1 - schema - think of a basic 2 table system  parent table and line items 
table... - but really all the important fields are in the child line items...
2 - mysql 5.xx
3 - sort 1st by date (all records happen 1st of every month) then product (only 
2 products needed for this)
4 - html for now
5 - for now just display and printing like:


JAN 2011
--- PRODUCT 1

data row 1
data row 2

--- PRODUCT 2

data row 3
data row 4

like that.......


- thanks for checking this out....




--
Thanks,
Dave - DealTek
deal...@gmail.com
[db-11]




--- End Message ---

Reply via email to