Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Functions & PHP

  • 31-03-2005 12:13pm
    #1
    Registered Users, Registered Users 2 Posts: 721 ✭✭✭


    This may be a stupid question, but go easy, im new to PHP. Is it possible to link directly to a function inside of a script.

    For example, I have a function called addCategory(), i wanted to call this in a menu, by doing something like linking to category.php?addCategory... would this be a correct way to go about this or am I barking up the wrong tree?

    Thanks in advance


Comments

  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    You could look up classes and the like in PHP.

    My favoured approach when I've got a few random functions that I want to use in a few scripts (Global functions) is to put them all into one file, say called functions.php or includes.php, and at the start of the other scripts, just call include("includes.php") and the functions are available to be called as if they're in the script itself.


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    Modularising code is commonplace in programming and in scripting. The use of functions or codified objects are the most popular means of doing this, particularly with regard to database related code.

    Two advantages to this are code reuse and platform portability; one example of the former might be a handy function that you may reuse in the same project or in future projects, while of the latter you could abstract any and all database interaction to a separate set of functions, so that your principle application need not have to care that it is dealing with a MySQL or PostgreSQL or Oracle database, or even the structure of that database, only what parameters are needed and what response to expect (which naturally makes moving from one database to another much easier). An additional advantage of such modularisation is that it makes it easier for teams to work together.

    For PHP, you might want to take a look at PEAR for a framework in this area.


Advertisement