Author Topic: making boss websites with php  (Read 1706 times)

0 Members and 2 Guests are viewing this topic.

Offline RustyShackleford

  • Devotee
  • **
  • Posts: 213
    • View Profile
making boss websites with php
« on: October 24, 2014, 11:49:08 pm »
Any good tutorials or inspiration? I'm familiar with all programming concepts so sites like W3 schools don't help because I don't need  the basic concepts explained and when it gets into more challenging territory these sites are fail and don't explain shit. Awhile ago I did this ruby on rails tutorial where I built a twitter clone, but I basically started mindlessly (hand) copying code.

Right now I have this simple site where I load everything from php and load the pages off of the end of the url eg. http://...../nigger would load ?page=nigger.php which would load the page nigger.php from my content directory. Pretty simple, but pretty cool, only thing I am wondering about is that I am using full path names because otherwise shit gets fucked up with whether or not there is a '/' at the end of the url. The only problem is that if I actually deployed my site the path names wouldn't be the same and for a full site this could mean a lot of editing. What's the best practice for working with path names? Also been experimenting with some ajax, but struggling to move beyond the given example.

Where should I look to learn more about php? Basically I understand the basic programming concepts, but I don't know how to apply them to building a web page. Building a twitter clone or whatever is a bit much, maybe a site with a members area? Idk some stuff seems stupid easy, some stupid hard, and other stuff like "oh I did that in rails, but idk how it actually works".

Offline theKit

  • Devotee
  • **
  • Posts: 178
    • View Profile
Re: making boss websites with php
« Reply #1 on: October 25, 2014, 12:04:32 am »
If you don't understand how things like ajax work, I suggest you focus on that. Understand how the things in the examples you're exposed to work and once you're beyond that what you need a project of your own to create. That is how you're going to learn to program. Get an idea and try to make it, as you struggle through the process of creating something you learn 'how to use' those basics you say you've already grasped.

Learn a bit about SQL and databases. Get some basic web security principles under your belt too. That 'loading ?page=nigger.php from your content directory" is going to get you in trouble if you launch your site without proper path restrictions. Refer to all your local paths in a global paths array so when you do deploy, all you have to do is adjust the array .

Offline RustyShackleford

  • Devotee
  • **
  • Posts: 213
    • View Profile
Re: making boss websites with php
« Reply #2 on: October 25, 2014, 12:42:24 am »
If you don't understand how things like ajax work, I suggest you focus on that. Understand how the things in the examples you're exposed to work and once you're beyond that what you need a project of your own to create. That is how you're going to learn to program. Get an idea and try to make it, as you struggle through the process of creating something you learn 'how to use' those basics you say you've already grasped.
So with ajax I get the example on W3 (start typing word and get suggestions written in the element below. I get in theory how it works, what it does, even what that specific example does, but don't know how to further apply it, To build something new. In my mind I know I can pull say a simple text file, but I can already do that with javascript, then I say well how about the btc-e trading graph and I get mind fucked. I'm having trouble finding that inbetween.
Quote
Learn a bit about SQL and databases. Get some basic web security principles under your belt too. That 'loading ?page=nigger.php from your content directory" is going to get you in trouble if you launch your site without proper path restrictions. Refer to all your local paths in a global paths array so when you do deploy, all you have to do is adjust the array .
SQL and DB I'm sort of familiar with both because of RoR and class. As far as paths, niiice - I am going to look into that first. Seems like the first step to learn, on stack overlow people said just write the full path, but that almost undoes the dynamic aspect if the path changes at all.

So you think I should focus on ajax first then db stuff later? That's a plan. My other question is with OOP, again I understand the concept, but as far I have done each object is like an entity in a db. Since I have a db for entities I'm not sure how I would implement an object or what I would gain.

And thanks, this is a question I feel like stack overflow would rip me a new one, but I really don't know where to start.

Offline theKit

  • Devotee
  • **
  • Posts: 178
    • View Profile
Re: making boss websites with php
« Reply #3 on: October 25, 2014, 01:24:01 am »
As far as I understand, ajax deals with XML documents and you need to know how to manipulate xml to get beyond returning text with ajax. I can't help you with OOP. I fucking hate it at this point. Right now having a hell of a time dealing with objects - getting data out of them, manipulating them inside arrays. I've spent 4 days doing something I could have done sloppily procedurally in 5 minutes.

Decide what you want to make,
make a plan and an outline as to how you would go about making it
start coding its parts
as you build you'll discover holes in your knowledge and that is how you learn to code (at least thats how i've done it)
then get frustrated and abandon your project in favor of something more simple :)

Offline RustyShackleford

  • Devotee
  • **
  • Posts: 213
    • View Profile
Re: making boss websites with php
« Reply #4 on: October 25, 2014, 01:36:57 am »
then get frustrated and abandon your project in favor of something more simple :)
I chuckled. You're right about just trying though it's all easy peasy until you actually go and do it.

For oop my experience in class was we'd do something like say build a cash register with some base item and we would use that to purchase some specific item, say a computer, which would be the created object and obviously you can create as many of those as you want and each one has attributes (exactly like a record in a database). Except it was never a database it was just the jvm so now I'm confused about separating database objects from true programming objects. I can't even think of a real example where it would come in handy (besides gui stuff I guess, but with web that's totally different).

Offline theKit

  • Devotee
  • **
  • Posts: 178
    • View Profile
Re: making boss websites with php
« Reply #5 on: October 25, 2014, 02:26:50 am »
http://www.youtube.com/watch?v=c_hNNAdyfQk

This is a good example of how to practically use OOP with PHP.

Offline RustyShackleford

  • Devotee
  • **
  • Posts: 213
    • View Profile
Re: making boss websites with php
« Reply #6 on: October 25, 2014, 05:00:47 pm »
This is a good example of how to practically use OOP with PHP.
Thanks, will definitely check it out.

So I've got a question about connecting to a mysql database.
Code: [Select]
$connection = mysqli_connect( 'localhost', 'rusty', 'password', 'my_db'  );
echo "test";
The echo statement doesn't execute nor anything else obviously after the connect. Not sure what is going wrong, its the symptoms of a syntax error,  but I believe I am using it correctly according to the docs. The credentials are good (and the user has permissions) and 'my_db' exists. From my understanding a failed connection would return false, can't figure out why it would just halt.

Edit so I ran that code in the console and got
Code: [Select]
PHP Fatal error:  Call to undefined function mysqli_connect()
Edit 2: So mysqli wasn't enabled.  8)
« Last Edit: October 25, 2014, 05:25:04 pm by RustyShackleford »

Offline Lanny

  • Zealot
  • ****
  • Posts: 1,123
    • View Profile
Re: making boss websites with php
« Reply #7 on: October 27, 2014, 01:45:55 am »
As far as I understand, ajax deals with XML documents and you need to know how to manipulate xml to get beyond returning text with ajax.

This is a common misconception but not your fault. The name AJAX (Asynchronous Javascript And XML) is a misnomer at this point. What people are actually talking about when they say ajax is the underlying transport mechanism that lets you make HTTP requests from client-side javascript. 90% of the time the encoding is going to be JSON rather than XML which what was originally intended. There are historical reasons for this, some good and some bad, but you don't really need to worry about it.

For oop my experience in class was we'd do something like say build a cash register with some base item and we would use that to purchase some specific item, say a computer, which would be the created object and obviously you can create as many of those as you want and each one has attributes (exactly like a record in a database). Except it was never a database it was just the jvm so now I'm confused about separating database objects from true programming objects. I can't even think of a real example where it would come in handy (besides gui stuff I guess, but with web that's totally different).

Objects and database records are different things and there's no inherent relationship between the two. Notable points of departure is that a table in a database doesn't support inheritance (generally) and that a record is just data, there is no behaviour (methods).

Objects have been used as an organizational technique (using the term "organizational" very broadly) for a long time but in recent years it's become popular to use objects to model a database (this is called an ORM and is a major part of Rails). The idea is the database still exists but the ORM sits between it and the programmer so you're just working with native objects so there's no need to learn SQL (there's several other advantages too, but staying out of the SQL mire is the big one). PHP doesn't ship with an ORM but there are a lot of frameworks and standalone ORMs that you can use in PHP if you want.

Offline RustyShackleford

  • Devotee
  • **
  • Posts: 213
    • View Profile
Re: making boss websites with php
« Reply #8 on: October 28, 2014, 10:19:28 pm »
Yeah as far as AJAX, I was following examples and stuff and then realized I wasn't using any XML at all (except for one example that pulls xml and then just echo's it out.) Have to say it's pretty cool, still wrapping my head around how to build up pages visually using elements outputted with the XMLHttpRequest() object.

For object oriented stuff, that's actually one of the reasons I'm trying my hand at php. Over the summer I was doing a bunch with rails, but it just left me wicked confused. At the moment I'd rather do the sql and understand what I'm doing than abstract it out to the active record or whatever (I know I could technically just use ruby and not rails, but idk php just seems better for me trying to learn).

What exactly does it mean to not use an ORM? The basic stuff I've done right now has just been creating mysql objects and directly querying the database? Rails was pretty cool where I'd just define the setup and hook it up right and it would go. Like I said it just overwhelmed me.

Offline Lanny

  • Zealot
  • ****
  • Posts: 1,123
    • View Profile
Re: making boss websites with php
« Reply #9 on: October 28, 2014, 11:37:32 pm »
What exactly does it mean to not use an ORM? The basic stuff I've done right now has just been creating mysql objects and directly querying the database?

Yup, you'll be writing your own SQL and interacting with your database "directly" (there's still driver code in there, but you're closer to it than going through an ORM).

Quote
Rails was pretty cool where I'd just define the setup and hook it up right and it would go. Like I said it just overwhelmed me.

Yeah, rails advertises itself to novices but I've always had my doubts about its didactic value. It was made for people to churn out CRUD apps as fast as possible and there's a lot of speed-for-magic trade offs that make sense when you're trying to improve the productivity of a professional web dev but not so much for someone learning. I guess people said the same thing about the move to high level languages too so maybe I'm just a curmudgeon, but if you don't think rails and co. are doing it for you don't force it.

Offline LiquidIce

  • Adherent
  • *
  • Posts: 52
    • View Profile
Re: making boss websites with php
« Reply #10 on: November 05, 2014, 10:00:31 am »


Yeah, rails advertises itself to novices but I've always had my doubts about its didactic value. It was made for people to churn out CRUD apps as fast as possible and there's a lot of speed-for-magic trade offs that make sense when you're trying to improve the productivity of a professional web dev but not so much for someone learning. I guess people said the same thing about the move to high level languages too so maybe I'm just a curmudgeon, but if you don't think rails and co. are doing it for you don't force it.

As someone who puts "rails developer" on his resume, you hit the nail on the head. If you ever go to any rails meetup, you'll have no trouble finding people talking about problems they're having with their newest application and it all boils down to the application somehow being something more than a CRUD app. Rails is amazing when applied to the right task and sticking to the Rails Way(tm), but as soon as you stray from it - the world is pain.
I now do a lot of Django at work and it's a breath of fresh air.

As far as OP goes, I think the best way to learn is by doing. I mean start some projects and learn things as you go along. Ask questions when you get stuck. I don't think there's a correct sequence to learn this stuff - it boils down to handling the problems that a task throws at you. I've only really looked into the grittier parts of doing AJAX after a year of work. Same goes for CSS3 features like transitions, but I've done some more-than-just-CRUD complex db stuff earlier.

Do you have any cool projects in mind, Rusty?

Offline RustyShackleford

  • Devotee
  • **
  • Posts: 213
    • View Profile
Re: making boss websites with php
« Reply #11 on: November 05, 2014, 08:16:18 pm »
Do you have any cool projects in mind, Rusty?
Nothing incredibly original. When I was doing Rails I started 2 projects one was a application for creating polls and the idea being that people could vote and it would create a pie chart or something showing the results. I actually tried a tutorial to do this in PHP, but the persons code was full of errors and I stood no chance at debugging it.

Another project was a simple billing application. With Employees and Clients interacting with each other, storing information on current projects, record keeping and billing on completion.

I didn't make significant headway on either, but once I get the hang making a PHP login I'll have a go at them. Also I'm going to try and do a simple blogging application - that was one of the core Rails tutorials for noobs.

Offline LiquidIce

  • Adherent
  • *
  • Posts: 52
    • View Profile
Re: making boss websites with php
« Reply #12 on: November 06, 2014, 10:18:05 am »
Do you have any cool projects in mind, Rusty?
Nothing incredibly original. When I was doing Rails I started 2 projects one was a application for creating polls and the idea being that people could vote and it would create a pie chart or something showing the results. I actually tried a tutorial to do this in PHP, but the persons code was full of errors and I stood no chance at debugging it.

Another project was a simple billing application. With Employees and Clients interacting with each other, storing information on current projects, record keeping and billing on completion.

I didn't make significant headway on either, but once I get the hang making a PHP login I'll have a go at them. Also I'm going to try and do a simple blogging application - that was one of the core Rails tutorials for noobs.

All of these sound like great projects to run into some common problems and solve them, good choice man. Keep us updated with how you're doing and ask questions if you have any - I don't know php but I know rails and django.

Offline Lanny

  • Zealot
  • ****
  • Posts: 1,123
    • View Profile
Re: making boss websites with php
« Reply #13 on: November 06, 2014, 04:07:43 pm »
I now do a lot of Django at work and it's a breath of fresh air.

What are your thoughts on Django? I work with it at my job. At this point the codebase is kinda beastly, it's been hacked on my a series of student programmers over the years and there are constant deadlines so I've been the only one who's taken time to do refactoring. That, of course, isn't Django's fault but sometimes I feel like I'm not getting a lot out of the framework at this point. In the beginning it was a pretty straight forward django app but as time has gone on various evolutionary pressures have pushed us into making this kind of franken-django. I've pretty much gutted the templating system in favor of a client side MVVM framework and JSON passing. I have a bunch of gnarly introspection and rewriting logic in the routing layer. I wrote my own test runners because the DB is too complex to rebuild and populate for every test. I have a gunicorn instance kinda bolted onto the side to handle websockets, and let me tell you trying to make the ORM green cooperative is a royal pain in the ass. Also like 75% of my time these days is spent profiling the SQL the ORM spits out and finding the black magicks and forbidden incantations which will make it run faster.

Mind you, none of this is a direct critique of Django (except maybe the ORM, the default join behaviour is a little questionable and multiple table inheritance is cool but really crucifies your DB performance beyond all justification). In fact maybe it's a virtue that it's not too hard to swap out framework functionality for something better suited to the problem.

Also class based views are a godsend when it comes to refactoring.

Offline LiquidIce

  • Adherent
  • *
  • Posts: 52
    • View Profile
Re: making boss websites with php
« Reply #14 on: November 08, 2014, 03:53:52 pm »
I now do a lot of Django at work and it's a breath of fresh air.

What are your thoughts on Django? I work with it at my job. At this point the codebase is kinda beastly, it's been hacked on my a series of student programmers over the years and there are constant deadlines so I've been the only one who's taken time to do refactoring. That, of course, isn't Django's fault but sometimes I feel like I'm not getting a lot out of the framework at this point. In the beginning it was a pretty straight forward django app but as time has gone on various evolutionary pressures have pushed us into making this kind of franken-django. I've pretty much gutted the templating system in favor of a client side MVVM framework and JSON passing. I have a bunch of gnarly introspection and rewriting logic in the routing layer. I wrote my own test runners because the DB is too complex to rebuild and populate for every test. I have a gunicorn instance kinda bolted onto the side to handle websockets, and let me tell you trying to make the ORM green cooperative is a royal pain in the ass. Also like 75% of my time these days is spent profiling the SQL the ORM spits out and finding the black magicks and forbidden incantations which will make it run faster.

Mind you, none of this is a direct critique of Django (except maybe the ORM, the default join behaviour is a little questionable and multiple table inheritance is cool but really crucifies your DB performance beyond all justification). In fact maybe it's a virtue that it's not too hard to swap out framework functionality for something better suited to the problem.

Also class based views are a godsend when it comes to refactoring.

Whoa, the applications I've worked on so far weren't even near that level of complexity - right now I'm basically making CRUD apps because these are my first commercial projects using Django so I've been having it easy.

What I can tell you, after having worked on small and mid-sized Rails projects in the past, that:
Quote
In fact maybe it's a virtue that it's not too hard to swap out framework functionality for something better suited to the problem.
is absolutely true. This extends also to the ease of integrating other code to work in Django. Rails feels like Rails whereas Django feels like Python. Ive found some backendy things much easier in Django than in Rails (ie. multistep forms, working with objects that have complex states) . Rail's strong point is convention over configuration and it's great when you're making CRUD apps, but as soon as you step away from that, the world is pain. I think both frameworks might have problems with handling newer technologies like websockets, but I imagine handling them using Django to be easier - with Rails you have to not only solve the new problem, but also fight the framework along the way.

One thing I've missed so far is TDD - I haven't had the time to write tests for my project, but I don't feel bad about since it's only a bunch of basic operations, but is testing something that is easy with Django? On one hand, testing is easy with Rails, but it's also easy to create a horrible test suite (slow, looking at code coverage instead of testing code that should really be tested) but I think that's an issue more with the community than with the framework itself.