Kleine Vragen Topic #4

Gestart doorOne2xs1.965 reacties23.994 weergaven

1.966 berichten · pagina 110 van 132

Berichten
4.213
Reputatie
0
Punten
0,02
Lid sinds
Laatst gezien
Ik heb in een database allemaal tijden staan. Het veld is een time veld in PHPMyAdmin.

Nu wil ik met PHP alle waardes bij elkaar optellen. Weet iemand hoe je dit het makkelijkste kan aanpakken?
0
Stef

Lid

Berichten
10.150
Reputatie
2
Punten
0,00
Lid sinds
Laatst gezien
Robinkoch schreef:
Ik heb in een database allemaal tijden staan. Het veld is een time veld in PHPMyAdmin.

Nu wil ik met PHP alle waardes bij elkaar optellen. Weet iemand hoe je dit het makkelijkste kan aanpakken?
Ligt er aan hoe je "bij elkaar optellen" bedoelt.
Wat je zou kunnen doen is de tijd converteren naar een unix timestamp met strtotime() en dat vervolgens bij elkaar optellen.
Mocht je het dan weer terug willen converteren, kan je dat met date() doen.
0
Berichten
8.602
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Robinkoch schreef:
Ik heb in een database allemaal tijden staan. Het veld is een time veld in PHPMyAdmin.

Nu wil ik met PHP alle waardes bij elkaar optellen. Weet iemand hoe je dit het makkelijkste kan aanpakken?
Gewoon SUM(veld_naam) gebruiken?
0
Stef

Lid

Berichten
10.150
Reputatie
2
Punten
0,00
Lid sinds
Laatst gezien
Mijn stagebedrijf wil graag een dynamisch xml bestand (sitemap) is dit mogelijk met php?
Ik weet dat ik een XML header kan meegeven, maar dan blijft het bestand toch een .php extensie houden.
Blijkbaar kijkt google naar sitemap.xml ofzo confused
0
Berichten
15.958
Reputatie
1
Punten
0,00
Lid sinds
Laatst gezien
Iemand verstand van access? Wil iets doen, alleen het lukt niet sadley
0
Stef

Lid

Berichten
10.150
Reputatie
2
Punten
0,00
Lid sinds
Laatst gezien
Tendmex schreef:
Iemand verstand van access? Wil iets doen, alleen het lukt niet sadley
Een héél klein beetje.
Misschien is het makkelijker om je vraag eerst te stellen? yummie
0
Berichten
15.958
Reputatie
1
Punten
0,00
Lid sinds
Laatst gezien
Stef schreef:
Eerdere citaten tonen
Tendmex schreef:
Iemand verstand van access? Wil iets doen, alleen het lukt niet sadley
Een héél klein beetje.
Misschien is het makkelijker om je vraag eerst te stellen? yummie
Ja hij is lastig te verwoorden maar zal het proberen.

Ik heb een lijst met klanten en een lijst met projecten.

Op het moment dat ik in de lijst met projecten de klant naam invul. Wil ik eigenlijk dat in het lijstje met klanten een kolom met projecten automatisch veranderd dat het project erbij word toegevoegd.

En als het even kan ook andersom, maar dat is niet noodzakelijk.
0
Stef

Lid

Berichten
10.150
Reputatie
2
Punten
0,00
Lid sinds
Laatst gezien
Tendmex schreef:
Eerdere citaten tonen
Stef schreef:
Eerdere citaten tonen
Tendmex schreef:
Iemand verstand van access? Wil iets doen, alleen het lukt niet sadley
Een héél klein beetje.
Misschien is het makkelijker om je vraag eerst te stellen? yummie
Ja hij is lastig te verwoorden maar zal het proberen.

Ik heb een lijst met klanten en een lijst met projecten.

Op het moment dat ik in de lijst met projecten de klant naam invul. Wil ik eigenlijk dat in het lijstje met klanten een kolom met projecten automatisch veranderd dat het project erbij word toegevoegd.

En als het even kan ook andersom, maar dat is niet noodzakelijk.
Dat heet een relatie smileHeb je dat al gegoogeld?
0
Berichten
15.958
Reputatie
1
Punten
0,00
Lid sinds
Laatst gezien
Stef schreef:
Eerdere citaten tonen
Tendmex schreef:
Eerdere citaten tonen
Stef schreef:
Eerdere citaten tonen
Tendmex schreef:
Iemand verstand van access? Wil iets doen, alleen het lukt niet sadley
Een héél klein beetje.
Misschien is het makkelijker om je vraag eerst te stellen? yummie
Ja hij is lastig te verwoorden maar zal het proberen.

Ik heb een lijst met klanten en een lijst met projecten.

Op het moment dat ik in de lijst met projecten de klant naam invul. Wil ik eigenlijk dat in het lijstje met klanten een kolom met projecten automatisch veranderd dat het project erbij word toegevoegd.

En als het even kan ook andersom, maar dat is niet noodzakelijk.
Dat heet een relatie smileHeb je dat al gegoogeld?
Ja, maar weet niet precies hoe ik hem instel.
Heb al een aantal combinaties geprobeerd maar werken allemaal niet sadley
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
Stef schreef:
Mijn stagebedrijf wil graag een dynamisch xml bestand (sitemap) is dit mogelijk met php?
Ik weet dat ik een XML header kan meegeven, maar dan blijft het bestand toch een .php extensie houden.
Blijkbaar kijkt google naar sitemap.xml ofzo confused
Heb je toegang tot het veranderen van de htaccess en heb je mod_rewrite aanstaan?
Dan zou je namelijk sitemap.php kunnen rewriten naar sitemap.xml ( http://stackoverflow.com/questions/6592810/htaccess-rewrite-xml-sitemap-and-user-friendly-sitemap ) wink
Vroeger werd dat nog al eens gedaan om .php te rewriten naar .html omdat dat destijds beter zou zijn voor SEO volgens mij.
0
Stef

Lid

Berichten
10.150
Reputatie
2
Punten
0,00
Lid sinds
Laatst gezien
Ik zie even niet wat ik fout doe.
Dit is mijn PHP code:

[COLOR= #0000BB]<?php[/COLOR]
use EmbedEmbed[COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$output[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]""[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SERVER[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]REQUEST_METHOD[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]"POST"[/COLOR][COLOR= #007700]) {[/COLOR]
    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]username[/COLOR][COLOR= #007700]])) {[/COLOR]
        [URL="http://www.php.net/include"]include[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]../Embed/src/autoloader.php[/COLOR][COLOR= #007700]);[/COLOR]
        [COLOR= #0000BB]$username[/COLOR] [COLOR= #007700]=[/COLOR] htmlentities[COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]username[/COLOR][COLOR= #007700]]);[/COLOR]
        [COLOR= #0000BB]$info[/COLOR] [COLOR= #007700]=[/COLOR] Embed[COLOR= #007700]::[/COLOR]create[COLOR= #007700]([/COLOR][COLOR= #DD0000]"https://twitter.com/$username"[/COLOR][COLOR= #007700]);[/COLOR]

        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/strlen"]strlen[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$info[/COLOR][COLOR= #007700]->[/COLOR]code[COLOR= #007700]) >[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700]) {[/COLOR]
            [COLOR= #0000BB]$output[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]([/COLOR]
                [COLOR= #DD0000]success[/COLOR] [COLOR= #007700]=>[/COLOR] true
            [COLOR= #007700]);
        }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
            [COLOR= #0000BB]$output[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]([/COLOR]
                [COLOR= #DD0000]success[/COLOR] [COLOR= #007700]=>[/COLOR] false
            [COLOR= #007700]);
        }
    }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
        [COLOR= #0000BB]$output[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"kut"[/COLOR][COLOR= #007700];
    }
}[/COLOR]

[URL="http://www.php.net/echo"]echo[/URL] json_encode[COLOR= #007700]([/COLOR][COLOR= #0000BB]$output[/COLOR][COLOR= #007700]);[/COLOR]


En dit is mijn AJAX request:

$(#accounttwitter).on(input,function(e){
    if($(this).length > 0) {
        $.ajax({
            type: POST,
            url: /data/checktwitter.php,
            username: $(#accounttwitter).val(),
            success: function(data) {
                console.log(data);
                if(data.length > 0) {
                    var result = JSON.parse(data);
                    if(result[success] === true) {
                        $(#accounttwitter).css({color: green});
                    } else {
                        $(#accounttwitter).css({color: red});
                    }
                }

            }
        })
    }
});


Wanneer deze code een request maakt naar de PHP blijft de output "kut" terwijl er eigenlijk een JSON array uit zou moeten komen.
Wat doe ik fout?

toevoeging op maandag 28 november 2016, 15:23:24:
Rik schreef:
Eerdere citaten tonen
Stef schreef:
Mijn stagebedrijf wil graag een dynamisch xml bestand (sitemap) is dit mogelijk met php?
Ik weet dat ik een XML header kan meegeven, maar dan blijft het bestand toch een .php extensie houden.
Blijkbaar kijkt google naar sitemap.xml ofzo confused
Heb je toegang tot het veranderen van de htaccess en heb je mod_rewrite aanstaan?
Dan zou je namelijk sitemap.php kunnen rewriten naar sitemap.xml ( http://stackoverflow.com/questions/6592810/htaccess-rewrite-xml-sitemap-and-user-friendly-sitemap ) wink
Vroeger werd dat nog al eens gedaan om .php te rewriten naar .html omdat dat destijds beter zou zijn voor SEO volgens mij.
Dat zal ik dan maar doen. Thanks! smile
0
Berichten
18.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
$(#accounttwitter).on(input,function(e){
    if($(this).length > 0) {
        $.ajax({
            type: POST,
            url: /data/checktwitter.php,
            data: {
                username: $(#accounttwitter).val()
            },
            success: function(data) {
                console.log(data);
                if(data.length > 0) {
                    var result = JSON.parse(data);
                    if(result[success] === true) {
                        $(#accounttwitter).css({color: green});
                    } else {
                        $(#accounttwitter).css({color: red});
                    }
                }

            }
        })
    }
});


@Stef Probeer m zo eens
0
Stef

Lid

Berichten
10.150
Reputatie
2
Punten
0,00
Lid sinds
Laatst gezien
Luukvdo schreef:
$(#accounttwitter).on(input,function(e){
    if($(this).length > 0) {
        $.ajax({
            type: POST,
            url: /data/checktwitter.php,
            data: {
                username: $(#accounttwitter).val()
            },
            success: function(data) {
                console.log(data);
                if(data.length > 0) {
                    var result = JSON.parse(data);
                    if(result[success] === true) {
                        $(#accounttwitter).css({color: green});
                    } else {
                        $(#accounttwitter).css({color: red});
                    }
                }

            }
        })
    }
});
@Stef Probeer m zo eens

Omg dankjewel biggrin worshippy worshippy worshippy
0
Stef

Lid

Berichten
10.150
Reputatie
2
Punten
0,00
Lid sinds
Laatst gezien
Ik heb op dit moment een class die er ongeveer zo uitziet:

[COLOR= #0000BB]<?php[/COLOR]

[URL="http://www.php.net/class"]class[/URL] Account
[COLOR= #007700]{[/COLOR]
    [URL="http://www.php.net/public"]public[/URL] [COLOR= #0000BB]$eigenschap1[/COLOR][COLOR= #007700];[/COLOR]
    [URL="http://www.php.net/public"]public[/URL] [COLOR= #0000BB]$eigenschap2[/COLOR][COLOR= #007700];[/COLOR]

    [URL="http://www.php.net/public"]public[/URL] [COLOR= #007700]function[/COLOR] __construct[COLOR= #007700]([/COLOR][COLOR= #0000BB]$id[/COLOR][COLOR= #007700]) {[/COLOR]
        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/is_numeric"]is_numeric[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$id[/COLOR][COLOR= #007700])) {[/COLOR]
            [COLOR= #0000BB]$db[/COLOR] [COLOR= #007700]= new[/COLOR] Database[COLOR= #007700]([/COLOR][COLOR= #DD0000]"Databasenaam"[/COLOR][COLOR= #007700]);[/COLOR]
            [COLOR= #0000BB]$query[/COLOR] [COLOR= #007700]= ;[/COLOR][COLOR= #FF8000]//Hier wordt een query uitgevoerd enzo[/COLOR]
            [COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]eigenschap1 [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$query[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]eigenschap1[/COLOR][COLOR= #007700]];[/COLOR]
            [COLOR= #0000BB]$this[/COLOR][COLOR= #007700]-[/COLOR]eigenschap2 [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$query[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]eigenschap2[/COLOR][COLOR= #007700]];[/COLOR]
            [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$query[/COLOR] [COLOR= #007700]===[/COLOR] false[COLOR= #007700]) {[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Error: query returned false."[/COLOR][COLOR= #007700];
            }
        }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Wrong use of function. Use an integer as parameter."[/COLOR][COLOR= #007700];
        }

    }[/COLOR]


Wanneer ik dus een lijstje met accounts wil maken, vraag ik eerst alle account IDs op en daarna initialiseer ik voor ieder ID een account class.
Maar gebruik ik dan niet overdreven veel querys? Is er een nettere manier om dit te doen?
0
Berichten
8.602
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Stef schreef:
Ik heb op dit moment een class die er ongeveer zo uitziet:

[COLOR= #0000BB]<?php[/COLOR]

[URL="http://www.php.net/class"]class[/URL] Account
[COLOR= #007700]{[/COLOR]
    [URL="http://www.php.net/public"]public[/URL] [COLOR= #0000BB]$eigenschap1[/COLOR][COLOR= #007700];[/COLOR]
    [URL="http://www.php.net/public"]public[/URL] [COLOR= #0000BB]$eigenschap2[/COLOR][COLOR= #007700];[/COLOR]

    [URL="http://www.php.net/public"]public[/URL] [COLOR= #007700]function[/COLOR] __construct[COLOR= #007700]([/COLOR][COLOR= #0000BB]$id[/COLOR][COLOR= #007700]) {[/COLOR]
        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/is_numeric"]is_numeric[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$id[/COLOR][COLOR= #007700])) {[/COLOR]
            [COLOR= #0000BB]$db[/COLOR] [COLOR= #007700]= new[/COLOR] Database[COLOR= #007700]([/COLOR][COLOR= #DD0000]"Databasenaam"[/COLOR][COLOR= #007700]);[/COLOR]
            [COLOR= #0000BB]$query[/COLOR] [COLOR= #007700]= ;[/COLOR][COLOR= #FF8000]//Hier wordt een query uitgevoerd enzo[/COLOR]
            [COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]eigenschap1 [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$query[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]eigenschap1[/COLOR][COLOR= #007700]];[/COLOR]
            [COLOR= #0000BB]$this[/COLOR][COLOR= #007700]-[/COLOR]eigenschap2 [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$query[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]eigenschap2[/COLOR][COLOR= #007700]];[/COLOR]
            [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$query[/COLOR] [COLOR= #007700]===[/COLOR] false[COLOR= #007700]) {[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Error: query returned false."[/COLOR][COLOR= #007700];
            }
        }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Wrong use of function. Use an integer as parameter."[/COLOR][COLOR= #007700];
        }

    }[/COLOR]
Wanneer ik dus een lijstje met accounts wil maken, vraag ik eerst alle account IDs op en daarna initialiseer ik voor ieder ID een account class.
Maar gebruik ik dan niet overdreven veel querys? Is er een nettere manier om dit te doen?

Aantal tips:
- Gebruik excepties i.p.v. echo.
- Dependicy injection
- Ik zou een aparte class aanmaken voor databaseverkeer, bijvoorbeeld AccountDAO (DataAccessObject), hierin kan je dan bijvoorbeeld een functie maken met 1 query alle accounts ophaalt en een array met Account object terugstuurt.

toevoeging op donderdag 1 december 2016, 111933:
Als ik even snel een voorbeeldje uitwerk:

[COLOR= #0000BB]<?php[/COLOR]

[URL="http://www.php.net/class"]class[/URL] AccountDAO
[COLOR= #007700]{[/COLOR]
    [URL="http://www.php.net/private"]private[/URL] [COLOR= #0000BB]$dbConnection[/COLOR][COLOR= #007700];[/COLOR]
    
    [COLOR= #FF8000]/**
     * Constructor
     * 
     * @param $dbConnection The PDO database connection
     */[/COLOR] 
    [URL="http://www.php.net/public"]public[/URL] [COLOR= #007700]function[/COLOR] __construct[COLOR= #007700]([/COLOR][COLOR= #0000BB]$dbConnection[/COLOR][COLOR= #007700])
    {[/COLOR]
        [COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]dbConnection [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$dbConnection[/COLOR][COLOR= #007700];
    }[/COLOR]
    
    [COLOR= #FF8000]/**
     * Gets all accounts
     * 
     * @return Array with Account objects
     */[/COLOR] 
    [URL="http://www.php.net/public"]public[/URL] [COLOR= #007700]function[/COLOR] getAllAccounts[COLOR= #007700]()
    {[/COLOR]
        [COLOR= #0000BB]$getAccountsResult[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]dbConnection[COLOR= #007700]->[/COLOR]query[COLOR= #007700]([/COLOR][COLOR= #DD0000]SELECT * FROM account[/COLOR][COLOR= #007700]);[/COLOR]
        
        [COLOR= #0000BB]$returnArr[/COLOR] [COLOR= #007700]= [];[/COLOR]
        
        [URL="http://www.php.net/while"]while[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$accountRow[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$getAccountsResult[/COLOR][COLOR= #007700]->[/COLOR]fetch[COLOR= #007700]([/COLOR]PDO[COLOR= #007700]:[/COLOR][COLOR= #007700]:[/COLOR]FETCH_ASSOC[COLOR= #007700]))
        {[/COLOR]
            [COLOR= #0000BB]$returnArr[/COLOR][COLOR= #007700][] = new[/COLOR] Account[COLOR= #007700]([/COLOR][COLOR= #0000BB]$accountRow[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]],[/COLOR] [COLOR= #0000BB]$accountRow[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]username[/COLOR][COLOR= #007700]]);
        }[/COLOR]
        
        [URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$returnArr[/COLOR][COLOR= #007700];
    }
}[/COLOR]

[URL="http://www.php.net/class"]class[/URL] Account
[COLOR= #007700]{[/COLOR]
    [URL="http://www.php.net/private"]private[/URL] [COLOR= #0000BB]$id[/COLOR][COLOR= #007700];[/COLOR]
    [URL="http://www.php.net/private"]private[/URL] [COLOR= #0000BB]$username[/COLOR][COLOR= #007700];[/COLOR]
    
    [COLOR= #FF8000]/**
     * Constructor
     * 
     * @param int $id The id of the account
     * @param string $username The username of the account
     */[/COLOR] 
    [URL="http://www.php.net/public"]public[/URL] [COLOR= #007700]function[/COLOR] __construct[COLOR= #007700]([/COLOR][COLOR= #0000BB]$id[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$name[/COLOR][COLOR= #007700])
    {[/COLOR]
        [COLOR= #FF8000]// Check if id is integer[/COLOR]
        [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700](![/COLOR][URL="http://www.php.net/is_numeric"]is_numeric[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$id[/COLOR][COLOR= #007700]))[/COLOR]
            throw [COLOR= #007700]new[/COLOR] InvalidArgumentException[COLOR= #007700]([/COLOR][COLOR= #DD0000]Parameter $id needs to be an integer[/COLOR][COLOR= #007700]);[/COLOR]
        
        [COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]id [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$id[/COLOR][COLOR= #007700];[/COLOR]
        [COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]username [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$username[/COLOR][COLOR= #007700];
    }[/COLOR]
    
    [URL="http://www.php.net/public"]public[/URL] [COLOR= #007700]function[/COLOR] getId[COLOR= #007700]()
    {[/COLOR]
        [URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]id[COLOR= #007700];
    }[/COLOR]
    
    [URL="http://www.php.net/public"]public[/URL] [COLOR= #007700]function[/COLOR] getUsername[COLOR= #007700]()
    {[/COLOR]
        [URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]username[COLOR= #007700];
    }
}[/COLOR]


En hoe je het dan toepast:

[COLOR= #0000BB]<?php
$databaseConnection[/COLOR] [COLOR= #007700]= new[/COLOR] PDO[COLOR= #007700](....);[/COLOR]
[COLOR= #0000BB]$accountDAO[/COLOR] [COLOR= #007700]= new[/COLOR] AccountDAO[COLOR= #007700]([/COLOR][COLOR= #0000BB]$databaseConnection[/COLOR][COLOR= #007700]);[/COLOR]

[URL="http://www.php.net/foreach"]foreach[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$accountDAO[/COLOR][COLOR= #007700]->[/COLOR]getAllAccounts[COLOR= #007700]() as[/COLOR] [COLOR= #0000BB]$a[/COLOR][COLOR= #007700])
{[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$a[/COLOR][COLOR= #007700]->[/COLOR]getUsername[COLOR= #007700]();
}[/COLOR]


Je zorgt ervoor dat je DAOs globaal beschikbaar zijn waardoor je er in je controllers bij kan (of je gebruikt hier ook DI voor)
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren