Jump to content

PHP for processwire


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 post
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 post
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 post
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 post
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 post
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 post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Marvin
      Hello, excuse me
      I'm new at processwire, i want to ask about a master detail system (Inheritance system) using a processwire. Can we create a Inheritance table using a processwire, and how we create it? Thank you for the help
    • By Marvin
      Hi,
      I'm still new at processwire, i want to ask, i was create a website with sign in system, but i want to add a access roles/permission for each user at my website. For now, i just can create a login user without any permission and the user data became as a pages in my processwire.
      Here i attach my code for login
      <?php $note = $note2 = $hidden =""; if($input->get->id == "logout") { $session->remove('login_id'); } if($input->post->submit) { $email = $sanitizer->email($input->post->email); $pass = $sanitizer->text($input->post->pass); $result = $pages->find("email=$email, text_1=$pass"); if(!$email || !$pass) { $note = "Data belum lengkap"; } else { if($result->count > 0) { $session->login_id = "$result"; $hidden = "style = 'diplay:none'"; $url=$pages->get("/files/")->httpUrl; header("Location:$url"); die(); } else { $note = "Akun tidak ditemukan"; } } } ?> And this code for login form
      <div class="frow-container"> <div class="frow centered mt-50"> <div class="col-md-1-3"> <div class="box p-40 shadow-light"> <h2 class="mb-20 text-center" <?=$hidden?>>Database Partitur<br>GII HIT</h2> <form method="post" <?=$hidden?>> <label>Username <input type="text" name="email"></label> <label>Password <input type="password" name="pass"></label> <input type="submit" name="submit" value="Masuk"> </form> <p class="notif"><?=$note;?></p> <div class="text-center"><?=$note2;?></div> </div> </div> </div> </div> Just for remember, my user data now is a pages, and i cannot give any permission to user data.
      Thank you very much for help.
    • By Marvin
      Hello,
      I'm new at process wire and i want to make an web using upload file and showing it at the table as a link to open it at the new tab. I wa succed while upload a file, but how i showing it as a link at the table to open it at the new tab of my browser? Any suggestion may helpfull
      Here i attach my code below :
      This code is for upload it to back-end (process wire)
      <?php $note = $note2 = $hidden =""; if($input->post->submit){ $upload_path = $config->paths->assets.'files/upload/'; if(!is_dir($upload_path)){ if(!wireMkdir($upload_path)) throw new WireException("No upload path"); } $original = $sanitizer->text($input->post->original); $indonesia = $sanitizer->text($input->post->indonesia); $other = $sanitizer->text($input->post->other); $composer = $sanitizer->text($input->post->composer); if(!$original || !$indonesia || !$other || !$composer){ $note = "Data tidak lengkap"; } else { $newFile = new WireUpload("song_files"); $newFile->setMaxFiles(1); $newFile->setOverwrite(false); $newFile->setDestinationPath($upload_path); $newFile->setValidExtensions(array('pdf','docx','doc')); $files = $newFile->execute(); if(!count($files)) { $newFile->error("No files received, so not creating page."); return false; } $newImg = new WireUpload("img_files"); $newImg->setMaxFiles(1); $newImg->setOverwrite(false); $newImg->setDestinationPath($upload_path); $newImg->setValidExtensions(array('jpeg','jpg','png','gif')); $files = $newImg->execute(); if(!count($files)) { $newImg->error("No files received, so not creating page."); return false; } $newPage = new Page(); $newPage->template = "files"; $newPage->parent = $pages->get("/files/"); $newPage->title = $original; $newPage->text_1 = $indonesia; $newPage->text_2 = $other; $newPage->text_3 = $composer; $newPage->of(false); $newPage->save(); foreach($files as $filename) { $filepath = $upload_path . $filename; $newPage->files->add($filepath); $newPage->message("Add file : $filename"); unlink($filepath); } $newPage->save(); } } ?> and this code to showing it as a link at the table
      <table class="border"> <tr> <th>No.</th> <th>Original Song Title</th> <th>Indonesia Song Title</th> <th>Other Song Title</th> <th>Composer</th> <th>File (pdf)</th> </tr> <?php $num = 1; $song; foreach($pages->get("/files/")->children as $child) { //showing every child at files parent directory $page == $child; $song = $pages->get("/files/".$child->id."/")->files; //showing uploaded files at child directory echo $child->id; echo "<tr><td>".$num++.".</td><td>".$child->title."</td><td>".$child->text_1."</td><td>".$child->text_2."</td><td>".$child->text_3."</td><td><a href='".$song->httpUrl."'</a>".$song->name."</td></tr>"; } ?> </table> Thank you for any suggestion
    • By picarica
      so i am trying to fetch dimensions of image using getimagesize() but it returns nothing, at least i think so, i want to feed it to data attribute, bit its emtpy, i tried feeding it the image directly or just image->url
      here is my source code

       
      foreach($page->repeat_body as $r_body) { /* other code here*/ if ($r_body->gallery_check == 1) { echo "<div class='my-gallery' id='grid-gallery' itemscope itemtype='http://schema.org/ImageGallery'>"; foreach($r_body->image as $image) { $options = array('quality' => 80, 'upscaling' => true, 'cropping' => 'north', 'sharpening'=>'medium'); $thumb = $image->size(400, 400, $options); $large = $image->size(1280, 0, $options); list($width, $height) = getimagesize($image->url); echo " <figure itemprop='associatedMedia' itemscope itemtype='http://schema.org/ImageObject'> <a href='$large->url' itemprop='contentUrl' data-size='$widthx$height' data-index='0'> <img src='$thumb->url' height='$height' width='$width' itemprop='thumbnail' alt='Beach'> </a> </figure>"; } echo "</div>"; } /* other code here*/ } now, the images are outputted correctly, i can open then and browse them
    • By franciccio-ITALIANO
      Hello to all. I would like to create an app. So I need to learn at least one programming language. I got informed online, and discovered that javascript with node.js, is the revolution of recent years, because it's faster than php. I wonder: if I develop an app with javascript and with a javascript framework (e.g. Meteor), is there a way to integrate processwire work? I know that processwire supports the transformation of the site into an application, but would it be as simple as Meteor? With the Meteor framework I have my app online in 10 minutes, and without even knowing javascript! (Knowing javascript would serve to personalize it). I should then install the app in a SUB-DOMAIN. If I study php, instead, and if I use a php framework (e.g. Laravel), how long does it take to have my first working app? Is it easy to process Laravel's components? Is writing forms for processwire apps with php a very complex job? Is it better to use Meteor and start with javascript? What would you recommend?
×
×
  • Create New...