Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

cached output


Go to End


769 Views

Avatar
Eldar

Community Member, 4 Posts

8 November 2012 at 5:57am

Edited: 08/11/2012 6:06am

hello!
does anybody know how to solve the problem called "Side effects" (http://doc.silverstripe.org/framework/en/reference/templates)?

I need to call the function which increments variable on +1 each time. Du to cacheing effect, I can see on output only the first value of the variable and value is not growing next time.

Here are examples of my files:

FirstPage.php

<?php
class FirstPage extends Page {
        public $j=10;
        static $db = array(
	);
	
	static $has_one = array(
		'Photo1' => 'Image',
		'Photo2' => 'Image',
		'Photo3' => 'Image',
		'Photo4' => 'Image',
		'Photo5' => 'Image',
		'Photo6' => 'Image',
		'Photo7' => 'Image',
		'Photo8' => 'Image',
		'Photo9' => 'Image',
		'Photo10' => 'Image'
	);
	function getCMSFields() {
		$fields = parent::getCMSFields();
		$fields->addFieldToTab("Root.Content.Images", new ImageField('Photo1', 'Картинка #1 (660px * 380px)'));
		$fields->addFieldToTab("Root.Content.Images", new ImageField('Photo2', 'Картинка #2 (660px * 380px)'));
		$fields->addFieldToTab("Root.Content.Images", new ImageField('Photo3', 'Картинка #3 (660px * 380px)'));
		$fields->addFieldToTab("Root.Content.Images", new ImageField('Photo4', 'Картинка #4 (660px * 380px)'));
		$fields->addFieldToTab("Root.Content.Images", new ImageField('Photo5', 'Картинка #5 (660px * 380px)'));
		$fields->addFieldToTab("Root.Content.Images", new ImageField('Photo6', 'Картинка #6 (660px * 380px)'));
		$fields->addFieldToTab("Root.Content.Images", new ImageField('Photo7', 'Картинка #7 (660px * 380px)'));
		$fields->addFieldToTab("Root.Content.Images", new ImageField('Photo8', 'Картинка #8 (660px * 380px)'));
		$fields->addFieldToTab("Root.Content.Images", new ImageField('Photo9', 'Картинка #9 (660px * 380px)'));
		$fields->addFieldToTab("Root.Content.Images", new ImageField('Photo10','Картинка #10 (660px * 380px)'));

		return $fields;
	}
       function countImages(){
            $out="";
            $k=0;
            if ($this->Photo1ID  > 0) ++$k;
            if ($this->Photo2ID  > 0) ++$k;
            if ($this->Photo3ID  > 0) ++$k;
            if ($this->Photo4ID  > 0) ++$k;
            if ($this->Photo5ID  > 0) ++$k;
            if ($this->Photo6ID  > 0) ++$k;
            if ($this->Photo7ID  > 0) ++$k;
            if ($this->Photo8ID  > 0) ++$k;
            if ($this->Photo9ID  > 0) ++$k;
            if ($this->Photo10ID > 0) ++$k;
            for ($i=1; $i<=$k; ++$i){
                $out.='<a href="#">'.$i.'</a>';
            }
            return $out;
        }

public function currentImage(){
    $this->j++;
    return $this->j;
}

}

class FirstPage_Controller extends Page_Controller {
}

FirstPage.ss

<% if Photo1 %>
$Photo1.URL $currentImage<br>
<% end_if %>

<% if Photo2 %>
$Photo2.URL $currentImage<br>
<% end_if %>

<% if Photo3 %>
$Photo3.URL $currentImage<br>
<% end_if %>

<% if Photo4 %>
$Photo4.URL $currentImage<br>
<% end_if %>

<% if Photo5 %>
$Photo5.URL $currentImage<br>
<% end_if %>

<% if Photo6 %>
$Photo6.URL $currentImage<br>
<% end_if %>

<% if Photo7 %>
$Photo7.URL $currentImage<br>
<% end_if %>

<% if Photo8 %>
$Photo8.URL $currentImage<br>
<% end_if %>

<% if Photo9 %>
$Photo9.URL $currentImage<br>
<% end_if %>

<% if Photo10 %>
$Photo10.URL $currentImage<br>
<% end_if %>

Output:
/assets/-/0.jpg 11
/assets/-/0.jpg 11
/assets/-/0.jpg 11
/assets/-/0.jpg 11

11,11,11... but I need 11,12,13...

thanks a lot for help!

P.S. silverstripe: 2.4.4