functions, the best way to implement and arrange them..

functions, the best way to implement and arrange them..

am 12.07.2011 14:28:59 von Taco Mathijs Hillenaar-Meerveld

--001485e7e92abbdcd204a7de7166
Content-Type: text/plain; charset=ISO-8859-1

It might be a simple question for the local die-hards among here, but i'm
really wondering about how
developers arrange their scripts and keep their map structures.

today i was looking for the best way to keep my scripts clear and to put
them into maps so i have a clear overview.
the same thing i would do for the scripts, using the functions i have and
throwing them in 1 or more php documents.

i can not find it how it should be done. is it a good idea to put a couple
of functions in just 1 document?
like sessions and login/logout functions?

in my idea i would only need to include a document in the header of my
website and then i'm done, right?

some thoughts, ideas and tips would be appreciated.

kind regards

taco

--001485e7e92abbdcd204a7de7166--

Re: functions, the best way to implement and arrange them..

am 12.07.2011 23:36:03 von Karl DeSaulniers

On Jul 12, 2011, at 7:28 AM, Taco Mathijs Hillenaar-Meerveld wrote:

> It might be a simple question for the local die-hards among here,
> but i'm
> really wondering about how
> developers arrange their scripts and keep their map structures.
>
> today i was looking for the best way to keep my scripts clear and
> to put
> them into maps so i have a clear overview.
> the same thing i would do for the scripts, using the functions i
> have and
> throwing them in 1 or more php documents.
>
> i can not find it how it should be done. is it a good idea to put a
> couple
> of functions in just 1 document?
> like sessions and login/logout functions?
>
> in my idea i would only need to include a document in the header of my
> website and then i'm done, right?
>
> some thoughts, ideas and tips would be appreciated.
>
> kind regards
>
> taco


Hi T,
One way I've found is to set up separate pages.
session.php
database.php
forms.php
etc..

Then in each you create a class named the same

EG for session.php
class Session
{
/session vars
var $username = "";

function Session(){
//constructor
}
//call your different session functions
//set username for eg.
}
$session = new Session;
?>

Then call on, say, the username var from a page.

Eg: view_acct.php

....

....


A very loose example, but hope it puts you on a good path..
Best,

Karl DeSaulniers
Design Drumm
http://designdrumm.com


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: functions, the best way to implement and arrange them..

am 13.07.2011 10:09:24 von Taco Mathijs Hillenaar-Meerveld

--0016e64610fc3e8aff04a7eeef8c
Content-Type: text/plain; charset=ISO-8859-1

yes, it was a structure like that i was looking for. so a class is a group
of functions?
i have heard about 'wrappers' to and from what i've heard it is the same
thing?


On Tue, Jul 12, 2011 at 11:36 PM, Karl DeSaulniers wrote:

>
> On Jul 12, 2011, at 7:28 AM, Taco Mathijs Hillenaar-Meerveld wrote:
>
> It might be a simple question for the local die-hards among here, but i'm
>> really wondering about how
>> developers arrange their scripts and keep their map structures.
>>
>> today i was looking for the best way to keep my scripts clear and to put
>> them into maps so i have a clear overview.
>> the same thing i would do for the scripts, using the functions i have and
>> throwing them in 1 or more php documents.
>>
>> i can not find it how it should be done. is it a good idea to put a couple
>> of functions in just 1 document?
>> like sessions and login/logout functions?
>>
>> in my idea i would only need to include a document in the header of my
>> website and then i'm done, right?
>>
>> some thoughts, ideas and tips would be appreciated.
>>
>> kind regards
>>
>> taco
>>
>
>
> Hi T,
> One way I've found is to set up separate pages.
> session.php
> database.php
> forms.php
> etc..
>
> Then in each you create a class named the same
>
> EG for session.php
> > class Session
> {
> /session vars
> var $username = "";
>
> function Session(){
> //constructor
> }
> //call your different session functions
> //set username for eg.
> }
> $session = new Session;
> ?>
>
> Then call on, say, the username var from a page.
>
> Eg: view_acct.php
> >
> ...
>
> ...
>
>
> A very loose example, but hope it puts you on a good path..
> Best,
>
> Karl DeSaulniers
> Design Drumm
> http://designdrumm.com
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--0016e64610fc3e8aff04a7eeef8c--

Re: functions, the best way to implement and arrange them..

am 13.07.2011 10:18:16 von Karl DeSaulniers

On Jul 13, 2011, at 3:09 AM, Taco Mathijs Hillenaar-Meerveld wrote:

> yes, it was a structure like that i was looking for. so a class is
> a group
> of functions?
> i have heard about 'wrappers' to and from what i've heard it is the
> same
> thing?
>
>
> On Tue, Jul 12, 2011 at 11:36 PM, Karl DeSaulniers
> wrote:
>
>>
>> On Jul 12, 2011, at 7:28 AM, Taco Mathijs Hillenaar-Meerveld wrote:
>>
>> It might be a simple question for the local die-hards among here,
>> but i'm
>>> really wondering about how
>>> developers arrange their scripts and keep their map structures.
>>>
>>> today i was looking for the best way to keep my scripts clear and
>>> to put
>>> them into maps so i have a clear overview.
>>> the same thing i would do for the scripts, using the functions i
>>> have and
>>> throwing them in 1 or more php documents.
>>>
>>> i can not find it how it should be done. is it a good idea to put
>>> a couple
>>> of functions in just 1 document?
>>> like sessions and login/logout functions?
>>>
>>> in my idea i would only need to include a document in the header
>>> of my
>>> website and then i'm done, right?
>>>
>>> some thoughts, ideas and tips would be appreciated.
>>>
>>> kind regards
>>>
>>> taco
>>>
>>
>>
>> Hi T,
>> One way I've found is to set up separate pages.
>> session.php
>> database.php
>> forms.php
>> etc..
>>
>> Then in each you create a class named the same
>>
>> EG for session.php
>> >> class Session
>> {
>> /session vars
>> var $username = "";
>>
>> function Session(){
>> //constructor
>> }
>> //call your different session functions
>> //set username for eg.
>> }
>> $session = new Session;
>> ?>
>>
>> Then call on, say, the username var from a page.
>>
>> Eg: view_acct.php
>> >>
>> ...
>>
>> ...
>>
>>
>> A very loose example, but hope it puts you on a good path..
>> Best,
>>
>> Karl DeSaulniers
>> Design Drumm
>> http://designdrumm.com
>>
>>
>> --
>> PHP Database Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>


I would venture to say a class is much more then a wrapper.
but basically setting your back-end pages as classes to control
everything with.
Makes referencing things in your front end much easier too, since
most of the nuts and bolts are
in the classes. Yes classes have many functions inside them. whatever
you want to use,
but there is a somewhat strict structure your classes have to be
built in for them to work properly.

I would google something like "php class example" or "php class
structure" or "php pages as classes"
That would probably yield some good reads.

Best,

Karl DeSaulniers
Design Drumm
http://designdrumm.com


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: functions, the best way to implement and arrange them..

am 13.07.2011 10:25:22 von bedul

--20cf300fb29b56014104a7ef2897
Content-Type: text/plain; charset=ISO-8859-1

using function is good.. I like to use it in my script.. but I do think
about you should use Class because Class make your script more structure..
and you can hide your setting to make everyone unable to see or hack you
system..

example.. I always like to use

bla

then i built function h1($s)

actualy use function for simple task.. for moderate or complex.. use class

dev arrange the script because they know the flow and that can be have if
they experience 1-3 project or more. not something easy actualy

On Tue, Jul 12, 2011 at 7:28 PM, Taco Mathijs Hillenaar-Meerveld <
tm.hillenaar@gmail.com> wrote:

> It might be a simple question for the local die-hards among here, but i'm
> really wondering about how
> developers arrange their scripts and keep their map structures.
>
> today i was looking for the best way to keep my scripts clear and to put
> them into maps so i have a clear overview.
> the same thing i would do for the scripts, using the functions i have and
> throwing them in 1 or more php documents.
>
> i can not find it how it should be done. is it a good idea to put a couple
> of functions in just 1 document?
> like sessions and login/logout functions?
>
> in my idea i would only need to include a document in the header of my
> website and then i'm done, right?
>
> some thoughts, ideas and tips would be appreciated.
>
> kind regards
>
> taco
>



--
akan ada dimana mulut terkunci dan suara tak ada lagi..
saat itu gunakanlah HP untuk melakukan SMS!!
-> ini aliran bedul.. bukan aliran aneh.
tertawa sebelum tertawa didepan RSJ..

--20cf300fb29b56014104a7ef2897--

Re: functions, the best way to implement and arrange them..

am 14.07.2011 04:50:58 von Tamara Temple

On Jul 12, 2011, at 7:28 AM, Taco Mathijs Hillenaar-Meerveld wrote:

> It might be a simple question for the local die-hards among here,
> but i'm
> really wondering about how
> developers arrange their scripts and keep their map structures.
>
> today i was looking for the best way to keep my scripts clear and to
> put
> them into maps so i have a clear overview.
> the same thing i would do for the scripts, using the functions i
> have and
> throwing them in 1 or more php documents.
>
> i can not find it how it should be done. is it a good idea to put a
> couple
> of functions in just 1 document?
> like sessions and login/logout functions?
>
> in my idea i would only need to include a document in the header of my
> website and then i'm done, right?
>
> some thoughts, ideas and tips would be appreciated.
>
> kind regards
>
> taco

Arranging functions, classes, and such into files is something that
we've used in software engineering for a long, long time. There are
some general concepts:

* Keep your files fairly small and concise. Don't put everything in
one file.
* The contents of your files should be logically consistent. Group
functions which work on similar sets of data, or do similar tasks,
together.
* Classes are a great way to go with grouping functions that act on a
cohesive set of data. Generally, one class per file is a good rule of
thumb, although there are also cases for including more than one class
in a single file.
* Functions and methods should be cohesive; they should do only one
thing. You can have several functions in a file, and you should have
several methods in a class.
* Grouping functions temporaly is generally a bad idea. The conceptual
exception to this is having a single configuration file for setting up
variables in the program that might vary with installation. This isn't
really arranging functions, though, as it's generally just setting and
initializing data for the application.
* When you are writing functions and classes, work to make them
general case and reusable as much as possible
* It's okay to have included files include other files; in fact, this
is generally How It's Done. Remember to use include_once and
require_once where appropriate.

Some reasonable chunks of files:
* session handling - it's nice to include all your session handling in
one file, this is where you may want to set up a class and instantiate
it.
* database access - also nice to be able to abstract out database
setup and calls
* database migration - another area that can easily be separated from
the whole
* models - each piece of business logic would be a good fit for a
separate class and/or file
* views - keeping with the tradition of separating logic from
presentation, keeping the code for presenting the page in separate
files is also a good idea
* authorization and access control - if you choose to write your own,
keeping it separate from the rest of your application is a great idea.
* data manipulation, string formatting, special processing



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php