1283 Posts
Bucklash
9 years ago
0
Topic

Hi Sebloders

NOTE: Any errors, let me know
This post is to help others understand how to get all the variables available by using print_r(). It is a long winded example, so get a cup of coffee...

 

  

Article Content type

Start of by using the default Article Content Type (image: lpp-article-contenttype). For this example I will use the Content View to access the fields data in the front-end of the Joomla! site. By default, the Article Content Type has the fields Article Introtext and Article Fulltext available (image: lpp-article-contentview).

image: lpp-article-contenttype 

image: lpp-article-contentview

 

  

Create Menu Items

Save (and close)!! Using Joomla!'s Admin Menu, navigate to Menus -> Main Menu, click the green New Button, Select Menu Item Type SEBLOD -> Form, select Content Type Article. The Menu Title will automatically fill with Article (image: lpp-menuitem-articleform). Next create a Menu Item Type SEBLOD -> List & Search, select Articles (image: lpp-menuitem-articlelist). Save and Close!!

image: lpp-menuitem-articleform 

image: lpp-menuitem-articlelist

 

    

Add Content

Go to the front end of your Joomla! Site, log in, so that you can add an Article. I entered "Title: print_r, Nice!", "Article Introtext: This text is in the Article Introtext field. Rage Against the Machine's first album was killer. Evil Empire, has killer tracks, too. People of the Sun and Bulls on Parade stand out the most for me." (image: lpp-article-create-01).

image: lpp-article-create-01

   

   

View Content

Save!! Navigate to the Articles Menu Item. You will see the Intro View as it is a page showing a list of Articles (lpp-article-introview-01). Click the Title to navigate to the Article (lpp-article-contentview-01).

image: lpp-article-introview-01 

image: lpp-article-contentview-01

If you receive an error message rather than the content, quickly navigate to the Article Content Type Form in Seblod Admin area, click on Content View, then Intro View. Save and Close!! Retry accessing the Article on the front end.

 

  

Add print_r() to Template

Next up is adding the print_r() function to the correct template. Back in the Sebod Admin Area, click the Article Content Type, make sure you are on the Content View, and change from Fields to Template (lpp-article-contenttemplate-01). Mine is One - seb_one. Next, in your sites files directory, navigate to the seb_one template index.php file (lpp-template-index-01) and open it. Place in the code the following php code
<?php print_r($cck) and die; ?> // $cck is used in the template, $fields is used in fields.
	

(image: lpp-index-added-print_r). Save!!. The wording 'and die' is optional, compare the difference! Refresh the Article page on the front end. The result is an array based on the fields (image: lpp-print_r-array-anddie) used. It is pretty difficult to read so it needs to be made all pretty and nice.

NOTE: $fields gets used in the field, whereas $cck gets used in the template, also, $config gets used for  storing data.

image: lpp-article-contenttemplate-01 

image: lpp-template-index-01 

image: lpp-index-added-print_r 

image: lpp-print_r-array-anddie-raw

 

    

Format print_r() Output

Copy the output seen on the browser window in to a text editor. Depending on yuur text editor depends how easy this will be for you, but format the output for readability like this: if open parenthesis, start new line and indent unless immediately followed by a closed parenthesis. If square bracket begin new line, do not indent (image: lpp-print_r-array-anddie-pretty). "Open parenthesis: (", "Close Parenthesis: )", "Open Square Bracket: [", there is a file attached with my output prettified (file: lpp-print_r-array-anddie-pretty).

image: lpp-print_r-array-anddie-pretty

    

     

Use print_r() Output in Template

Next up, you would probably create a Position Override and add your code there, but to keep this example short I will use the seb_one index.php file. So, remove the print_r() statement that was inserted earlier and replace with this:
<?php $result = $cck->getId('art_introtext'); ?> // Stores the value from the key "id" from ['art_introtext'] array.<br>
	

Next add some code to display it, I am using Joomla!'s message magic...

<?php JFactory::getApplication()->enqueueMessage($result . ' is the answer' , 'Result'); ?> // Message shows $result.<br>
	

(image: lpp-cck-output). Experiment with the other values you can access like this: $cck->getSomething('form this array')

<?php $result = $cck->getId('art_introtext'); ?>
<?php $result = $cck->getTitle('art_introtext'); ?>
<?php $result = $cck->getFolder('art_introtext'); ?><br>
	

image: lpp-cck-output

   

    

Use print_r() Output in Field   

Remove the code from the template (a position override would have been really convenient here). Next up, I am going to add code to a  beforeRender field to the Article Content Type Form. This is a paid for product from the Seblod Store. Add the beforeRender field to the Content View (image: lpp-beforerender-field), I added "Title: LPP Field", "Mode: Free" (You can choose file and load the code that way instead). The code for BeforeRender:
$result = $fields['art_introtext']->options2; 
// output
JFactory::getApplication()->enqueueMessage($result . ' is the output' , 'Result');<br>
	

The output message should display (image: image: lpp-beforerender-message):

result
{"editor":"","width":"100%","height":"280","import":"1"} is the output<br>
	

When I work out how to pull just the value of width ie 100% I will add it to this example.

image: lpp-beforerender-field

image: lpp-beforerender-message

 

Clear as mud?  

  

Bucklash

Get a Book for SEBLOD