Can someone explain the add.php code in the sample block?
Permalink
I am looking at making my own form block to contain previous form code that I developed for my own sites and was reading through some of the sample block code found here.
Can someone please explain the following code to me in readily understood terms?
Specifically...
- what is the difference between add.php, edit.php, and view.php? I mean the code above talks of "this view" but if add.php is a view what in the world does view.php do? Are add, edit, and view all...well...just views??
- wrapped in a form? Where? I mean where in the code is the rest of the form doing the wrapping? And what does $form-> have to do with the wrapping form if anything? Is $form just a class method defined somewhere?
- what do the label and content methods do exactly?
- is there any documentation on this anywhere or do I have go looking all around inside the code again to understand what these things do?
Any help would be appreciated.
Thanks.
Carlos
Can someone please explain the following code to me in readily understood terms?
Specifically...
- what is the difference between add.php, edit.php, and view.php? I mean the code above talks of "this view" but if add.php is a view what in the world does view.php do? Are add, edit, and view all...well...just views??
- wrapped in a form? Where? I mean where in the code is the rest of the form doing the wrapping? And what does $form-> have to do with the wrapping form if anything? Is $form just a class method defined somewhere?
- what do the label and content methods do exactly?
- is there any documentation on this anywhere or do I have go looking all around inside the code again to understand what these things do?
Any help would be appreciated.
Thanks.
Carlos
Thanks for the reply Ollie. I appreciate your thorough response. It does help clarify things even if things are not entirely crystal clear yet.
I think the best thing is for me to just start hacking the sample block code to pieces (i.e. putting print_r statements everywhere, removing pieces of code, etc.) to see what happens.
Carlos
I think the best thing is for me to just start hacking the sample block code to pieces (i.e. putting print_r statements everywhere, removing pieces of code, etc.) to see what happens.
Carlos
In Concrete5 most of the heavy lifting is done for you - which is nice. You only need to follow a few basic conventions in order to get your block to work.
add.php - called when someone adds your block to a page on their C5 site.
edit.php - called when they edit the block that is already on a page of their site
view.php - the output of the block, whatever it is intended to do, and what the visitor will see rendered on a page.
There are two other very important files. One is db.xml, this is used at block installation to build your blocks table. The other is controller php, which can be used to extend events which relate to the block i,e saving after editing, but in the main is used to build the output that is displayed in view.php
The syntax you quoted above generates form fields using the concrete5 helpers - these generally involve writing less code than the html equivalent, but that is probably why it looks unfamiliar to you. You can use normal html, but it's harder work to be honest.
The main difference between the add.php and edit.php files is that add.php fields mainly won't have a default value when the file is called, but the edit.php fields need their values set based on the content of the database row for that block. This is very easy as the data from the blocks table is available to you as a variable, named as the field in the table. ie column/field mydata can be accessed using the variable $mydata.
You probably need to read more about C5, Object Oriented PHP and MVC but I hope the above helps make things clearer.