The Sanctuary

Technology => Technophiliacs & Technophiles => Topic started by: RustyShackleford on October 24, 2014, 11:49:08 pm

Title: making boss websites with php
Post by: RustyShackleford 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".
Title: Re: making boss websites with php
Post by: theKit 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 .
Title: Re: making boss websites with php
Post by: RustyShackleford 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.
Title: Re: making boss websites with php
Post by: theKit 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 :)
Title: Re: making boss websites with php
Post by: RustyShackleford 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).
Title: Re: making boss websites with php
Post by: theKit 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.
Title: Re: making boss websites with php
Post by: RustyShackleford 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)
Title: Re: making boss websites with php
Post by: Lanny 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.
Title: Re: making boss websites with php
Post by: RustyShackleford 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.
Title: Re: making boss websites with php
Post by: Lanny 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.
Title: Re: making boss websites with php
Post by: LiquidIce 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?
Title: Re: making boss websites with php
Post by: RustyShackleford 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.
Title: Re: making boss websites with php
Post by: LiquidIce 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.
Title: Re: making boss websites with php
Post by: Lanny 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.
Title: Re: making boss websites with php
Post by: LiquidIce 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.
Title: Re: making boss websites with php
Post by: Lanny on November 08, 2014, 05:05:12 pm
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.

It kinda depends on what you're looking for in a test suite. There is no (or at least no one ever uses a) rspec equivalent, the common testing library is django doing some light transaction wrapping over python's unittest library which is modeled on jUnit. It's pretty straight forward, real easy to pick up but has all the same pitfalls of most testing arrangements. If you want it to run fast you have to mock and inject all over the place. One nice thing about python is that often you can get away with monkey patching rather than explicit dependency injection. Some people would consider that the exact opposite of nice, and I understand why, but I really think that there are places where the internals of a process are stable enough that you can save complexity in the primary code base by patching in the tests.

There's also support for doctests which are cool. I don't use them a lot because they've more conducive to a less stateful environment in my experience, but other might not feel the same.
Title: Re: making boss websites with php
Post by: RustyShackleford on November 08, 2014, 07:13:44 pm
These 'apps' that you guys are talking about are they purely web based eg. navigate to the website and use the app, or something that you download but interacts with a db, or some hybrid. I never fully grasped how people are making local applications with things like rails, but it does make a lot of sense as far as portability (to different devices).

And LiquidIce that's interesting you never did php,what was your experience prior to django? I really really want to get a web development type job when I graduate in the spring, but I feel like I'm in this weird in between of self taught knowledge, but lack of real experience. My current job I work on a website, but it is mostly cms stuff, which is pretty boring and not a great experience beyond the experience itself. Of course it's all about how I spin it and I think it will be a valuable stepping stone. Sometimes the job market seems so competitive other times it seems stupidly easy, for example the people at my current job were super impressed at some basic javascript I did that would have otherwise had to be contracted out or gone without certain functionality. Too bad it's a temporary part time position or I would feel a lot more secure about the future.
Title: Re: making boss websites with php
Post by: Lanny on November 08, 2014, 07:43:05 pm
For the project I was talking about earlier, yeah, the only user facing part of the application is a website. You can't make native applications with rails. You can with ruby, which might be what you're thinking of. Another way you might use rails in tandem with a native app is if you have some central DB you could write a native app that uses HTTP requests to communicate with a rails app which in turn communicates with the DB (you generally don't want public native apps interacting with your DB directly). That's what most phone apps are these days, so like snapchat has a native component that operates your camera, displays pictures, w/e and it talks to a web server to get snaps that are sent to you (presumably) over HTTP.

There are also projects for "nativization" client side web stacks. Cordova and node-webkit both take javascript/html/css and package them in a way that makes them look like a native app to their respective target platforms.
Title: Re: making boss websites with php
Post by: LiquidIce on November 09, 2014, 11:23:06 am
These 'apps' that you guys are talking about are they purely web based eg. navigate to the website and use the app, or something that you download but interacts with a db, or some hybrid. I never fully grasped how people are making local applications with things like rails, but it does make a lot of sense as far as portability (to different devices).

And LiquidIce that's interesting you never did php,what was your experience prior to django? I really really want to get a web development type job when I graduate in the spring, but I feel like I'm in this weird in between of self taught knowledge, but lack of real experience. My current job I work on a website, but it is mostly cms stuff, which is pretty boring and not a great experience beyond the experience itself. Of course it's all about how I spin it and I think it will be a valuable stepping stone. Sometimes the job market seems so competitive other times it seems stupidly easy, for example the people at my current job were super impressed at some basic javascript I did that would have otherwise had to be contracted out or gone without certain functionality. Too bad it's a temporary part time position or I would feel a lot more secure about the future.

I've only worked with the first type of app you describe - where the whole app is online and the user interacts with it through a browser. Lanny described it good, so I'll just add that you can make supposedly good native apps for android in a python library called Kivy and ruby has a thing called RubyMotion for making apps for iOS and OSX (I don't know how good they are though, just heard about them).

Prior to Django I was doing Rails stuff for a few months. A good deal of skills transfered over (OOP, not to mention front-end stuff). I was doing CompSci in a community college and I needed to find a job to get travel money and the idea hit me to try a job related to my major (I used to take up retail jobs before that). I applied for a few internships and got taken in by a 15 person startup/dev-agency that used Rails. I already knew basic HTML and CSS from toying around with it since I was 12, but I knew nothing about Ruby nor JS. I did know a bit of Python  because I've been messing around with it for 3-4 months before this opportunity.

Apart from providing 1000$/month, public transit fare, and food, the internship also provided a chance to meet real world problems head on - things like doing maintenance on an older application, writing tests, using version control, collaborating with other programmers. It did lack mentorship a bit, as I was forced to figure things out for myself, but just the opportunity to face those problems taught me a great deal. I got promoted to junior dev after 3 months and got a real salary and more challenging tasks.

I don't know where you live, but here in NYC an internship is an amazing stepping stone both for your learning and your career. Additionally, the market here is developer-starved. The company I work at now spent ~2 months looking for a mid-level django developer. There's more juniors to hire so the competition for you will be tougher, but you can make yourself stand out by (as cheesy as this sounds) having an answer for why you want to work at a company and having a side project or two to show your passion and motivation. One thing that also stuck in my head is that rejection doesn't mean you're intrinsically bad - just that the company had different requirements. I used to get bummed out at getting rejected until I was on the other side of the interview table and had a discussion with my coworkers about how "I'd love to work with this guy, but we need someone at least a year more experience and exposed to more devops".

One last thing that I wish someone told me before - just go out and apply the shit out of job postings. I don't mean mass-spam them, but apply for position that you feel are slightly above your head. If someone asks you about something you don't know at the interview, tell you're learning it and you'd love to continue learning. An internship is a place where someone pays you to learn (awesome) and a junior role is the same, except now you have to be serious and provide value to the company. One year into web development and I'm still learning new things pretty much every single day.

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.

It kinda depends on what you're looking for in a test suite. There is no (or at least no one ever uses a) rspec equivalent, the common testing library is django doing some light transaction wrapping over python's unittest library which is modeled on jUnit. It's pretty straight forward, real easy to pick up but has all the same pitfalls of most testing arrangements. If you want it to run fast you have to mock and inject all over the place. One nice thing about python is that often you can get away with monkey patching rather than explicit dependency injection. Some people would consider that the exact opposite of nice, and I understand why, but I really think that there are places where the internals of a process are stable enough that you can save complexity in the primary code base by patching in the tests.

There's also support for doctests which are cool. I don't use them a lot because they've more conducive to a less stateful environment in my experience, but other might not feel the same.

That sounds pretty good - I'll try to get a taste of it before the next project rolls around so that I can write some simple tests here and there. I've found they help a lot during the maintenance phase when you're working with some else's code and having tests do even a simple sanity check ie. "does this route return a 200?" goes a long way.  Thanks man.

Title: Re: making boss websites with php
Post by: RustyShackleford on November 09, 2014, 04:29:19 pm
LiquidIce, thanks man I appreciate the advice. I think you've convinced me to try and get a company to take me under their wing more than to try and teach myself. Part of why I am scrambling to teach myself one thing and then another is that all these positions make it seem like you have to be pretty fluent in JS and a server side language to be considered I guess that is to scare people away. I'm going to pm you so I don't derail my own thread.
Title: Re: making boss websites with php
Post by: RustyShackleford on November 09, 2014, 05:41:13 pm
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.
Can you point me in the right direction on this?
This stack overflow (http://stackoverflow.com/questions/7839522/php-relative-paths-and-directories) looks like one solution, but I don't think it would be considered a global paths array?

Then there was the problem of having a '/' vs not at the end of the url. What is the cleanest way of resolving that issue?