Jump to content

PHP for processwire


kuba2
 Share

Recommended Posts

Hello there

This is a very overall question....

I am fairly new to CMS and PHP, but I am managing the essentials.

Still, I am struggling with PHP. I worked through quite some youtube tutorials and my brain is beginning to adapt, but the theory is a little different than the practice. All the pieces are there, but I have trouble putting them together.

Is there a nice tutorial to train processwire specific PHP? How can I get prolific in PHP for PW?

Theres tons of overall PHP lessons, but I am looking for something tying into PW.

Programming is new to me ( coming from the design side ) and it opposes me quite hard     ;)

I would be very thankful for any suggestions

Thanks

Jakob

Link to comment
Share on other sites

Hi,

in general, processwire has a very clean an "simple" API. So it has a very easy learning curve and you get result right away.

I think after you got the basics of PHP it is very helpful if you just start working with it(and PW). The documentation has so many examples and codesnippets that lots of stuff can really be learned by just doing it. And the more you struggle with a specific problem, the easier it should also be for you to dig into more specific tutorials that help you advance with it.

Also the community here is very helpful and friendly and even answering some rather basic PHP questions if they come up from time to time.

Ok, enough written, here is also a link of nice page that might help you proceed in writing good php code: www.phptherightway.com

Hope this helps you a bit to go on :)

Greetings

  • Like 1
Link to comment
Share on other sites

In a nutshell, you have to know these (very) basic concepts:

  • Define a variable
  • Output a variable
  • Loop through an array
  • Perhaps use switch/case instead of if/else
  • Concatenate strings for HTML-output
  • Use include() or require()
  • Have the API cheatsheet ready to build your selectors

There are tons of examples around here, and also when you download and install PW, everything in the /site folder is very well commented to get you going.

  • Like 4
Link to comment
Share on other sites

In a nutshell, you have to know these (very) basic concepts:

  • Define a variable
  • Output a variable
  • Loop through an array
  • Perhaps use switch/case instead of if/else
  • Concatenate strings for HTML-output
  • Use include() or require()
  • Have the API cheatsheet ready to build your selectors

In addition to this, I also recommend reading up about the very basics of Object Oriented Programming,

http://www.tutorialspoint.com/php/php_object_oriented.htm

at least the concepts behind it. Although in the case of ProcessWire frontend development you are not "forced" to implement anything in OOP, knowing the fundamentals helps a lot to understand the API and its usage. An often used technique in the OOP world is method chaining. You do not have to use it, but when you want to look up someone else's code, you need to how and why it works:

http://www.xpertdeveloper.com/2010/09/method-chaining-in-php/

BTW I highly recommend bookmarking http://www.tutorialspoint.com/php/

You can use this method before you jump into your trial-and-error experiment:

  1. Whenever you start working on something unfamiliar, say sending emails, study some basics in pure PHP, say: http://www.tutorialspoint.com/php/php_sending_emails.htm
  2. After that, look for alternatives in the ProcessWire world: API support, module support

Of course, it is recommended to use the API and/or modules whenever you can, but understanding why is so makes working with them easier.

Hope this helps, good luck, and never give up! :)

  • Like 7
Link to comment
Share on other sites

One more thing to mention: personally I've really enjoyed the courses from Codecademy. Their system isn't exactly perfect, but it's still pretty awesome, and "learning by doing" has always worked better for me personally than learning from books. If you enjoy a hands-on experience, I'd suggest giving them a try. It's free and they've got an easy-to-understand PHP course for beginners :)

On a related note I wrote a blog post about PHP templating a few years ago. It's mostly about PHP vs. Twig, but could also work as a kind of an introduction to templating in PHP.

  • Like 3
Link to comment
Share on other sites

Hi,

 I found this forum thread that you might find interesting. It contains a post by Mr. Cramer himself, It's a little old but still work checking out when you have a chance.  https://processwire.com/talk/topic/3118-crowd-fund-new-tutorials/#entry31001

If you haven't seen this already, you might find it helpful : http://wiki.processwire.com/index.php/Small_Project_Walkthrough

This one also to help with searching the forums for specific topics / tutorials https://processwire.com/talk/topic/6196-easy-search-on-pw-forums-with-google/

For example, try using this search on Google 'site:https://processwire.com learn php' .

You know, the Readme.txt file that comes with the Processwire install in the templates folder? It's actually worth a read :)

Though it has nothing to do with PHP in terms of Processwire, if you are new to programming, and you haven't done so already, I'd suggest you get familiar with debugging techniques pertaining to php.  Find some tutorials on on the subject. Xdebug will come up. Look into it, There are also php debugging addons for both Firefox and Chrome. Also have a look at Tracy Debugger http://modules.processwire.com/modules/tracy-debugger/

There are also articles in the PW forums on debugging.

 Start creating a collection of code snippets for yourself as you go along. It doesn't have to be fancy.  Just something you can go to when you need an example of how you coded something in that past. Might save you a little Googling time. 

Lastly, try to get in the habit of writing what is usually referred to as 'clean code'. Use comments wisely. Don't leave dead/unused code in a module. It only clutters things up and is a distraction.

Take the extra time to give variables meaningful names.. etc etc. Nothing sucks worse than having to go back to something you yourself wrote, say 6 months ago, and you find yourself staring at the screen silently cursing yourself out, because you can't remember what you were trying to accomplish.  Bottom line - Google on 'Writing clean PHP code' and go from there.

Best wishes on your coding endeavors. :)

Edited by cstevensjr
Edited first link so that it would work
  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...