Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION
Been using CodeIgniter 2.0 to recreate an existing project of mine from the ground up. It's an AFL (Australian Football League) tipping thing, where my fellow employees can log in and place their tips etc.

I'm struggling with how to structure the project. My database looks something like this (simplified):
code:
========
GAME
========
game_id
round_id
venue_id
game_date

========
TEAMGAME
========
tega_id
team_id
game_id
tega_home
tega_score

========
TEAM
========
team_id
team_name
So I'm imagining that in PHP the game object would look something like this:
code:
========
GAME
========
game_id
game_date
teams
- ['home']
-- ['team_id']
-- ['team_name']
-- ['score']
- ['away']
-- ['team_id']
-- ['team_name']
-- ['score']
venue
- ['venue_id']
- ['venue_name']
I'm just not sure how to implement this in CodeIgniter. Is there a way to define your own classes like this? I'm new to the MVC approach, so I'm not sure but one method I was thinking of would be to make this as the game model, but then CodeIgniter doesn't seem to be built to work this way.

I'm completely loving lost to be honest - how do I arrange all these objects so they make sense while still keeping the MVC structure intact?

Edit: Should these perhaps be created as libraries?

putin is a cunt fucked around with this message at 03:02 on Mar 23, 2011

Adbot
ADBOT LOVES YOU

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION
Thanks for the help. I should have explained the fields a bit better, but AFL is divided up into a set number of rounds per season, so the round_id is used to determine which round any given game belongs to. In other words, yeah, it's an INT.

I like the way you've simplified the database model, and I reckon I'll take that advice on board. Thanks!

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION
I think we broke it.

Edit: nvm. You might wanna look at restricting the length of the name field however...

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION
Does anyone have any good resource about this Manager pattern? I'm struggling a little to get my brain to think in OOP mode, and I'd like to know more about using Managers etc so I can apply it to a particular project I'm working on.

Here's what I think I would use so far, bear with me, this is gonna be long-winded.

The project I'm working on is for Footy Tipping (guessing the outcome of AFL games and accumulating a score for each correct pick - at the end of the season the 'tipster' with the highest score is named the winner). For those who don't know, AFL works like this:
  • There is one season every year.
  • There are 24 rounds in a season.
  • There are 17 teams (with another being added next year, so this needs to be flexible).
  • There are 8 games every round (but will go up to 9 next year).
  • There are 2 teams per game (duh)
  • One team has a "BYE" game each week, where they don't play.
Tipping works like this:
  • Each game will be available for tipping until the moment the game starts.
  • Users can tip for as many games as they like, even for the whole season if they wanted to, but once a tip is "locked in" it can't be changed.
  • Users can choose to place a "tentative" tip, which doesn't lock in their decision. If a game starts, any users with tentative tips will have the tip locked in automatically, anyone without a tip at all will automatically have the "away" team locked in.
Sorry if I've made the whole thing sound a lot more complicated than it is, but I hope it was clear enough. The way I'm planning to set up the managers after reading some advice here is thus:

code:
GameManager->get(gameId)
GameManager->getForSeason(seasId)
GameManager->getForRound(roundId)
GameManager->getForTeam(teamId[,seasId])
GameManager->save(Game)
GameManager->destroy(Game)

TipManager->get(tipId)
TipManager->getForUser(userId[,seasId])
TipManager->getForRound(roundId)
TipManager->getForSeason(seasId)
TipManager->save(Tip)
TipManager->destroy(Tip)
I think those are the only managers I need since everything else really only needs to be managed on an individual level (users, teams, rounds etc) - am I on the right track or am I completely lost? Do I actually need managers for the other classes, even if they're only managed individually? I've currently got a system up and running that handles all of this just fine, but the code is a mess and I'd love to redo it using proper OOP concepts instead of the kind of half-n-half solution I've got going at the moment.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION
I'm really hoping someone can help me here because I'm completely stumped.

I have a CodeIgniter site which has a controller called "tip" (it's a football tipping site). The tip controller looks like this:

php:
<?
include_once 'app.php';

class Tip extends App
{
    function __construct()
    {
        parent::__construct();
    }
    
    function index()
    {
        echo 'test';
    }
    
    function save()
    {
        echo 'test';
    }
}
?>
The problem is, whenever I try to access that controller it gives a HTTP500 error:

quote:

HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfil the request.

The bizarre part here is that exact page works if I rename the file and the class to something else and try that instead, but if I try to call it 'tip' it doesn't work. I even had that specific controller, named tip, working perfectly before and it had a lot worse code in it than what is there now. At some point the whole thing fell over so I dumbed the code down to the bare essentials for the sake of debugging, but no luck - even with the code so dumbed down it doesn't work with that specific name.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

rt4 posted:

Does "app" work?

Yeah sorry, forgot to mention that all of other functioning controllers start the same way.

Also this specific file works fine if I simply change its name and nothing else, so I don't think app is causing it.

It's making my head hurt.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION
Oh sweet jesus I'm sorry guys, I found the problem.

I had another class being created elsewhere called 'Tip'... ugh! I think this is evidence that I've been up too long.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

Knyteguy posted:

Meh, I just changed everything to get and it worked. :psyduck:. I'm not very worried about pretty since it's a non-public page, so it works I suppose.

Those CI functions do sanitize the form data (for the most part).

It's not just about pretty - it's about common sense. If you're submitting something to enter it into a database you should be using POST. What Hammerite suggested will probably fix your issue - did you try it?

Also, as mentioned you need to either use the active record stuff (http://codeigniter.com/user_guide/database/active_record.html) built into Code Igniter, use query binding or manually sanitise those inputs, $this->input->post() won't sanitise it for use in queries.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION
I have a bit of a best practice question. I'm writing a model that will obviously have multiple ways of fetching the same data (Users for example can be fetched byId, byUsername, byEmail etc). Obviously this means each of those methods will need to fetch the same database fields, package them into the User class and then return that class instance. This opens up potential for lots of code repetition.

I'm not explaining myself very well, I can tell already, so I'll give an example:

php:
<?
class User
{
    ...

    public static function byId($id)
    {
        $CI = get_instance();
        $CI->db->select('us.user_id, us.user_name, us.user_email');
        $CI->db->where('us.user_id', $id);
        $r = $CI->db->get('user us');

        return new User($r->result());
    }

    public static function byEmail($email)
    {
        $CI = get_instance();
        $CI->db->select('us.user_id, us.user_name, us.user_email');
        $CI->db->where('us.user_email', $email);
        $r = $CI->db->get('user us');

        return new User($r->result());
    }

    ...
}
?>
In the above example, how can I save myself repeating the field names in every method? What is the best practice approach to this - if there is one? I've considered setting an array of field names and using that each time, but as I want to call these methods in a static context, that's not really a viable option.

(By the way, I'm using CodeIgniter if you hadn't guessed).

Edit: Also, bonus question! I have a User class wherein one of the properties represents the user's favourite AFL team. This property is called team and holds a Team object. Now, every time I want to get a User out of the database, I'd like to get their favourite team as well, so I can create the Team object and set it against the 'team' property for that User.

Obviously I will also have a Team model and there will be other models as well that will need to have a "Team" as one or more of the class properties. Obviously I can just include the team details in the query, get it all out and once and set it all up how I want it. But say a few months down the track I want to add an extra field to the Team table. Now I have a hundred different places where I'm fetching Team details that I need to update to also fetch the new field. How do I prevent this being an issue?

Help!

putin is a cunt fucked around with this message at 11:33 on Jun 5, 2012

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

musclecoder posted:

You could use the __call() magic method, something along the lines of:

php:
<?
// code removed for brevity
?>
Even better, you should put that in an abstract generic Entity or Model class and have all of your Entities/Models extend that. Can probably use return(new self($r->result())); in a generic __call() method.

I don't know enough about CI to help you with your second question, but you should look into using a real ORM that can handle cross references like that.

Unfortunately I'm not sure if this will solve the problem as I have some methods that will need to search on two criteria - byUsernameAndPassword() for example. Then I have queries that will be much more complex. Could I perhaps use a switch statement to build the appropriate 'where' statement depending on which method is run? For example:

php:
<?
class User
{
    public function __call($method, $argv)
    {
        $db->select(_FIELDS_GO_HERE_);

        switch ($method)
        {
            case 'byUsernameAndPassword':
                $db->where('us.user_name', $argv[0]);
                $db->where('us.user_pass', $argv[1]);
                break;
            case 'byId':
                $db->where('us.user_id', $argv[0]);
                break;
        }

        $db->get('user us');

        // etc etc
    }
}
?>
Is this a good way to do it? It seems like it might be hard to follow - a bit counterintuitive - for someone else reading the code. But maybe this is the only half-decent way to do it without significant code repetition? I think my main concern is that anyone looking to see what "User::byUsernameAndPassword()" does is going to expect to find that information in that function, but this approach puts the logic inside an entirely separate function.

putin is a cunt fucked around with this message at 13:31 on Jun 5, 2012

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

Sab669 posted:

Can't you just do something like

UPDATE zipcodes
set zipcode= (SELECT SUBSTRING(zipcode, 0, 5) FROM zipcodes)

Bear in mind I'm pretty bad at SQL :downs:

...Though now that I think about it that wouldn't work because the nested query returns > 1 result. Food for thought, though!

SQL code:
UPDATE
zipcodes

SET
zipcode = SUBSTRING(zipcode, 0, 5)
Should work - I think?

Edit: beaten!

putin is a cunt fucked around with this message at 16:03 on Jun 5, 2012

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

fletcher posted:

I wouldn't do it like that. I would go with multiple constructors:

code:
$someUser = new User($username, $password);

$anotherUser = new User($id);
Basically then your username/password constructor would simply figure out what the user id is, then it would call the User($id) constructor to load up the rest of the information.

Hmm I see - the thing is, I want it to work more like musclecoder suggested and have static methods I can use to return User instances that match the parameters. The only real problem I'm having with that is where on earth do I put the list of field names so I'm not having to retype it every time? Can I access properties statically (does that even make sense)?

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

barbarianbob posted:

With codeigniter you can add this as the top of the class. (This is more like your original approach)
public static $selectStr = 'us.user_id, us.user_name, us.user_email';
then do
$this->db->select(self::$selectStr);

or make it a constant. or maybe a method named _setSelectStr() or whatever. It doesn't really matter.

But I'd be hesitant to do __call() in CI, because of how it works. And things like new User() wont work out with it because you're not supposed to do that with CI since it binds models to $this->modelName->methodName()

Also, I'm pretty sure you should be doing class User extends CI_Model {. That'll give you access to $this->db without having to call get_instance() all the time.
Yeah I've been extending CI_Model for the longest time and I've come to the conclusion that I really don't like the way CI handles models. In my mind (and I thought this was a fairly common position, but maybe it isn't) a model should represent a single object of a particular type. It seems to me as though CI_Models are really object factories, rather than models. For that reason I'm going to take a shot at abandoning the CI_Models altogether and write my own. I'm yet to find out whether it will work well or not.

If I can keep the select list in a static property then maybe that will solve my problem. Thanks for the tip, I'll give it a go.

As a disclaimer for the above - I have no formal education in OOP, everything I know has just been picked up along the way from using C++ and Java. That means I'm happy for people to point out any mistakes I'm making in terminology because some of the correct terms for things I'm not exactly clear on.

revmoo posted:

Didn't they change to Model from CI_Model in 2.x?
Other way around - they moved from 'Model' to 'CI_Model' in 2.x.

putin is a cunt fucked around with this message at 01:43 on Jun 6, 2012

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION
PHP's documentation is a weird thing - it's frustrating and tedious to find what you want, until you eventually learn their 'way' of doing things and then it becomes some of the simplest and comprehensive documentation I've ever read.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

DarkLotus posted:

Why the AND? It seems redundant. Also, that snippet of code makes my head hurt.

I'm guessing he wants to check both conditions? What's wrong with that?

As for the problem at hand, try this perhaps?

PHP code:
$row = mysql_fetch_array($result);
$jobber=$row["Jobber Id"];
$query = "SELECT * FROM custdb WHERE `Jobber Id` = ".$jobber." AND `Customer Number` = `Jobber Id`";
$result = mysql_query($query);
if ($result) $jrow = mysql_fetch_array($result);
Then you just use
PHP code:
isset($jrow)
at display time to show blanks instead of the row values.



On a different note - does anyone know if CodeIgniter uses PDO for its DB stuff?

putin is a cunt fucked around with this message at 00:52 on Jun 25, 2012

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

revmoo posted:

If it does, it's added a pretty hefty abstraction layer, because CI has a lot of db functions.

So... "no"? Or "I don't know"?

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

Scaramouche posted:

Yeah, I figured that part out right away but it just felt really strange. It feels strange that a valid result for a function could be 0 (found at first position), !true (not found), or >0 (found).

I actually ended up ditching that whole strpos boondoggle anyway; it was just a pre-upload sanity check. By the time I want to really deal with the pdf I have it in local filesys and am finding it/exists/header there first.

Do you mean because you're expecting it to be -1 if it's not found?

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

Scaramouche posted:

I realize that a lot of it is my own expectation about what something should return; the fact that the function returns differing types based on the input is a bit strange but not 'OMG CODING HORROR'. I think what bothers me more is the loosy goosy nature of the comparisons.

I agree completely - I think that's why I was a bit confused about what you were saying. Even though the return type is mixed, I think it's okay in this instance because it does make sense to return a FALSE. The problem lies in the fact that 0 will still compare as false, I guess it pays to always use the strict comparisons - sucks for people just getting into the language though as it's a frequent gotcha that will continuously crop up.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION
I have learnt more about user authentication in the last two pages than I probably have over my entire time spent learning PHP. Thanks guys!

On a separate note I have a problem that I'm not sure how to approach - I have a web site that uses "some data" to do "some stuff". I get the data via a web service that updates every 10 minutes, so theoretically if I access the web service every ten minutes I'll get the most recent data. I need to then take that data and insert some of it into a database.

How do I do this? Is PHP even the appropriate tool for this? The nature of the web site means that I won't need to have up-to-date data if no one is on the web site (ie. I could access the web site and update the data on each page load) but I don't want to have it occur on every page load since it will create quite a bit of extra load time for every page.

So yeah, crux of the issue - I need a script to run every 10 minutes and I need to know whether PHP is the right way to approach this or is there something else more suitable?

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

Hammerite posted:

PHP could be used for this. Any web scripting language could. Python, Perl or Ruby would also be usable. You schedule a cron job to run your script (whatever type of script) every 10 minutes.


IT Guy posted:

Yeah, PHP can definietly do this job.

You could have a cron job run a script that generates static output and call that file your index.html.

For example:

controller.php - your script that pulls the data from the web service. This is only run from generator.php

generator.php - runs your controller.php script and generates the static output index.html page every 10 minutes via a cron job

index.html - the page your visitors actually hit.

Thanks guys, I had considered a cron job but I was under the impression my host doesn't allow cron jobs to run quite so frequently as 'every 10 minutes'. I had another look and it turns out they do! So I'll go with that approach - thanks!

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

Ursine Asylum posted:

Depending on the site traffic, how touchy your host is about cron jobs, and how long the site update function takes, you could always just implement a poor man's caching system, serialize some data to a file, and update the file on page load if it's >X minutes old.

This is good advice, thanks - I now have more than one option!

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

McGlockenshire posted:

All ORMs suck. It's just a matter of where you want the suck to live.

A major problem with ActiveRecord is that it violates SOLID and separation of concerns, and requires a great deal of additional work in order to perform automated testing.

As a PHP newbie, I want to make sure I'm parsing this properly: are you saying that "All ORMs suck" therefore you shouldn't use one? Or "All ORMs suck" but it's a necessary evil so pick the best of the crappy offerings? One of my biggest problems at the moment is getting the hang of the overall structure of a large PHP project and managing the database connection and queries etc is a big of a pain for me right now, so this topic is particularly interesting to me.

putin is a cunt fucked around with this message at 00:08 on Aug 22, 2012

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

Doh004 posted:

As a PHP newbie, may I ask why you're working on an large project?

I'm not sure how that's relevant, but it's my own project in my own time, I'm doing it to learn - is that okay?

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

Doh004 posted:

No it's not okay! (of course it is).

I would just suggest keep it simple and straight forward to get familiar with PHP, then move on from there!

Probably a more accurate way to put it is that I'm familiar with PHP, but new to large projects.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

Sab669 posted:

If I just throw in a var_dump($result) in that function, I get "bool(false)" as my output? What the heck does that even mean? And print_r yields noting.

If you're not getting an error in the query then it means your query hasn't returned any rows (fetch() returns bool(false) on failure). Try dumping the values of $email and $password immediately before they're used to check that they have been set correctly.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

IT Guy posted:

Did you copy/paste an already hashed password and then rehashing it?

I'll put money on this. And I don't mean that in a cruel way, I mean that in a "I've made this same mistake myself" way.

Alternatively, if you copy-pasted is it possible a trailing space was picked up somewhere along the way?

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION
Got a bit of a tricky one - I'm working on a personal project that is game-like and I'm wanting to include some sort of achievement system. The achievements can be user-activated (ie. the user performs an action and that action results in them getting an achievement) or they may be passive (ie. a change is made in the database - scores being calculated for example - that results in the user getting an achievement). There will be data coming in from an external source that could result in some users receiving achievements.

I'm wondering what is the best way to approach this? I could obviously have a general "check for achievements" function that gets run as a cronjob every 10 minutes or so and checks whether there are any achievements to award, but this won't provide a very immediate result. It's like I need something that can sit passively and "wait" for certain conditions to be met and then award the appropriate achievements.

Am I making any sense at all here?

putin is a cunt fucked around with this message at 04:15 on Aug 30, 2012

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

McGlockenshire posted:

You're looking for a job queue.

There are lots of options, but I'm a fan of Gearman + Supervisor. You'd think I'm on their freaking PR team from how much I find myself recommending them...

That looks along the right lines, but having not done this before it seems complicated as heck. It'll take a bit of reading but I think you've nailed the right solution for me, thanks!

Edit: I don't suppose you have any resources that might help me get started in this?

putin is a cunt fucked around with this message at 07:29 on Aug 30, 2012

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

McGlockenshire posted:

The other year, there was some group doing some sort of PHP advent calendar thing, and it was awesome and useful and it had hands down the best intro to using the two together ever. I also forgot to bookmark it and can't find it now. Sigh.

Thankfully Google is a thing.

Thanks for that - searching phpadvent and Gearman I was able to find a few decent articles, this one sounds like it may be the one you were talking about? http://phpadvent.org/2009/daemonize-your-php-by-sean-coates

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

IT Guy posted:

Anyone know of any good books that focus on single page web application design using PHP and JS?

I would also be keenly interested in this!

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

Deus Rex posted:

we're using FuelPHP which has its warts, but it meant to be a 'cleaner' version of CI or something. Anyway, I've poked around for fun at Laravel and it seems really very promising.

Thanks for this - I hadn't heard of Laravel and it looks quite interesting.

Edit:

So I've been looking into Laravel, playing around with it a bit, and I'm struggling to get the hang of the Eloquent ORM. In my schema I have a USERS table and a TEAMS table, each user record has a TEAM_ID (which may be null) representing the football team they support.

I must be misunderstanding something, because I would call this a one to many (one team can be linked to any number of users, but each user will be linked to just one team). According to the docs I would reflect a one-to-many relationship in the code by saying:
PHP code:
function teams()
{
    return $this->has_one('team');
}
But when I do this it looks for a 'USER_ID' in the TEAMS table. I don't understand why it would do that - surely if I'm saying the USER model has_one TEAM it would imply a foreign key of TEAM_ID in the USER table.

I'm clearly misunderstanding something fairly fundamental, someone please help!

putin is a cunt fucked around with this message at 16:45 on Sep 26, 2012

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

PlesantDilemma posted:

Yeah there are a lot of frameworks out there. Which one has built in models to manage users? I'd like something that already has the sign up/login/recover password thing already made and I can just extend from. I've been using code igniter because I have experience with it from a school project, but it doesn't come with user stuff already.

Laravel comes with the Auth stuff built-in, it seems like it's going to be the next big thing in my opinion as it's incredibly well made and actually makes good use of the improved OO in PHP 5.3

Edit: forgot to mention, also has great documentation.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION
Eloquent ORM is used in the Laravel framework and it's basically the only ORM I have ever used that I've not just "not-hated" but actually loved. It actually handles all the relationships (one-to-one, one-to-many, many-to-many) without issue which is great when you want to say, remove a post and also delete all the entries from your compound tables etc.

putin is a cunt fucked around with this message at 01:45 on Oct 15, 2012

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

fuf posted:

I'm looping through wordpress posts and want a new line after every three posts.

Right now I have

code:
if( $postcount == 4 or $postcount == 7 ): 
//new line
How do I extend this for any number of posts? Is there a way to check if a number is one more than a multiple of 3?

Normally you would handle presentation issues like this in CSS, is there a functional reason for needing to place a linebreak on every third post or is it purely for looks? If it's purely for looks, use CSS instead.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

fuf posted:

Yeah it's purely for looks, but I don't know how I would do it with just CSS. I need PHP to tell me whether a post should be on the start of a new row so I know when to close the last row and start a new one. I guess I could have written the CSS better so that each row didn't have its own container, but that's the way it's laid out...

Biowarfare posted:

div:nth-child(Xn+Y) {} or something?

Yep, you'd say:
code:
div.child_divs { float: left; }
div.child_divs:nth-child(3n) { clear: left; }

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION
For those of you wondering which framework you should be using, if you are able to guarantee your server will have PHP 5.3 then you should almost certainly be using Laravel - it's super amazing.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

IT Guy posted:

You guys using Laravel, when interacting with the database, what do you prefer (raw query, fluent, eloquent)?

I just can't get into Eloquent but so many people say to use it. And fluent is just a dummy proof way to write raw queries. Therefore I typically prefer to use raw queries. Is there anything wrong with this? Should I be learning to use Eloquent?

Eloquent is the bee's knees. It took me a little bit of work and a lot of reading to fully understand it, but it's worth it. If you ever get completely stuck you can browse the actual Laravel code on their web site as well.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION
I have a question around testing that you lot may be able to help me with. I'm working on a footy tipping system that will use dates quite a bit to control things. For example, I'll want it to understand the concept of the 'current' football round. I'll also want it to know when a game has started and ended, that sort of thing.

This is fine logically, it's easy enough to write this stuff but how would you guys go about testing it? For example, maybe I want to make sure notification emails are sent out at the correct time, or that games are locked down from tipping once they've begun - how would I test this? I could manually change the date/time of my dev environment but that's a lot of stuffing around.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

spacebard posted:

Hopefully your classes are loosely-coupled enough so that you could create a unit test based off of PHPUnit_Frameworke_TestCase. Then you should have high confidence that if you assert that your isLocked method or whatever returns true or false.

Sorry but I've not used that before - that will allow me to define an arbitrary point in time and have my app behave as though it is currently that time?

Adbot
ADBOT LOVES YOU

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

Blinkz0rz posted:

I think what he's suggesting is that you should make your Match class's isLocked method accept a datetime rather than assume the current output of date(). That way you can arbitrarily change whatever time you want to use to test whether a match is locked.

Ah okay, thank you. I did wonder if that's what he was getting at. I was hoping to avoid that but it makes sense so I think I'll go for that approach. Thanks both of you.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply