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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

pb with dataobjectmanager testimonial example


Go to End


39 Posts   5939 Views

Avatar
servalman

Community Member, 211 Posts

26 June 2010 at 2:08am

Edited: 26/06/2010 2:16am

merci encore

je vais encore te demander une petite choses qui me coince mais qui doit juste être une question d'écriture (probleme 3)

N'hesite pas à ma dire si tu n'as pas le temps

--------- Problème 2
donc l'objet est "permanent" et je peux y accéder sans avoir à remplir à nouveaux les champs dans une autre pages avec un autre template ?

par exemple AllProductPage.php et AllProductPage.ss

---------------------------- Problème 3

Je sais que tu m'as donné une autre technique pour les flashvars mais cela m'oblige à changer pas mal de chose .

J'ai donc essayé d'adapter ce que j'avais avant mais ce que je ne comprends pas c'est comment on peut affecter la valeur 'Imagename' à la variable $Imagename .

J'ai fait des essais donc voici le résultat sf que je ne comprends pas pour quoi cela ne marche dans certains cas

----------------- WOKING (en dur) ---------------------

public function flashvarFunction() {

 $Imagename = "toto" ;
 $flashVar="'myFlashVar=$Imagename'" ;
 return $flashVar;

}  

----------------- NOT WOKING ---------------------

public function flashvarFunction() {

$Imagename = $this->Imagename
 $flashVar="'myFlashVar=$Imagename'" ;
 return $flashVar;


} 

----------------- NOT WOKING ---------------------

public function flashvarFunction() {

$vars = array (
'Imagename' => $this->Imagename
);

$Imagename = {$vars['Imagename']};

 $flashVar="'myFlashVar=$Imagename'" ;
 return $flashVar;

} 

Merci

Avatar
UncleCheese

Forum Moderator, 4102 Posts

26 June 2010 at 4:38am

1) Oui, c'est ça.

2) C'est quoi $this->Imagename? Oui est-ce défini?

Avatar
servalman

Community Member, 211 Posts

26 June 2010 at 4:53am

Comme toujours c'est parfait


cela vient des attributs d'un objet product je cherche donc un moyen d'affecter les valeurs des attributs à des flashvars sans passer par l'url .

Cela fonctionne en dur mais de manière dynamique

<?
class ProductPage extends Page
{
	static $has_many = array (
		'Products' => 'Product'
	);
 
	public function getCMSFields()
	{
		$f = parent::getCMSFields();
		$f->addFieldToTab("Root.Content.Products", new DataObjectManager(
			$this,
			'Products',
			'Product',
			array('Productname'=>'Productname','Imagename'=>'Imagename','Presentation' => 'Presentation','Contenance' => 'Contenance','Actifs' => 'Actifs','Price' => 'Price'),
			'getCMSFields_forPopup'
		
		));
		
		return $f;
	}


 
}






	class ProductPage_Controller extends Page_Controller
{


public function index() {
return Director::redirect($this->Products()->First()->Link());
}


static $allowed_actions = array (
'show'
);
public function show() {
return array (
'Product' => DataObject::get_by_id("Product",$this->urlParams['ID'])

);
}

}

merci

Avatar
servalman

Community Member, 211 Posts

26 June 2010 at 7:32pm

Bonjour Oncle Fromage

Mon message precedent n'était peut etre pas assez clair ?

Dis le moi

Merci

Thomas

Avatar
UncleCheese

Forum Moderator, 4102 Posts

27 June 2010 at 5:14am

Tu as bien un champ "Imagename" sur l'objet "Product?"

class Product extends DataObject
{
static $db = array (
'Imagename' => 'Varchar'
);

public function FlashVar() {
return "someVar=$this->Imagename";
}
}

Avatar
servalman

Community Member, 211 Posts

27 June 2010 at 5:22am

Edited: 29/06/2010 2:32am

Thank you

For the saturday answer !

I'm know in front of my computer and I'm about to try you code but to be sure :

my Product.php file goes like this an I guess I have to had the code you sent me there (in bold) :

<?
class Product extends DataObject
{
	static $db = array (
		'Productname' => 'Text',
		'Imagename' => 'Text',
		'Presentation' => 'Text',
		'Contenance' => 'Text',
		'Actifs' => 'Text',
		'Price' => 'Text'
	);
 
	static $has_one = array (
		'ProductPage' => 'ProductPage'
	);
 
	public function getCMSFields_forPopup()
	{
		return new FieldSet(
			new TextField('Productname'),
			new TextField('Imagename'),
			new TextField('Presentation'),
			new TextField('Contenance'),
			new TextField('Actifs'),
			new TextField('Price')
			//new TextareaField('Quote')
			

		);
	}

	public function Link() {
return $this->ProductPage()->Link("show/$this->ID");
}

public function FlashVar() {
return "someVar=$this->Imagename";
} 
}

And my other page ProductPage.php goes like this

<?
class ProductPage extends SiteTree
{
	static $has_many = array (
		'Products' => 'Product'
	);
 
	public function getCMSFields()
	{
		$f = parent::getCMSFields();
		$f->addFieldToTab("Root.Content.Products", new DataObjectManager(
			$this,
			'Products',
			'Product',
			array('Productname'=>'Productname','Imagename'=>'Imagename','Presentation' => 'Presentation','Contenance' => 'Contenance','Actifs' => 'Actifs','Price' => 'Price'),
			'getCMSFields_forPopup'
		
		));
		
		return $f;
	}


 
}






	class ProductPage_Controller extends Page_Controller
{


public function index() {
return Director::redirect($this->Products()->First()->Link());
}


static $allowed_actions = array (
'show'
);
public function show() {
return array (
'Product' => DataObject::get_by_id("Product",$this->urlParams['ID'])

);
}




}

By the way I posted this earlier :

http://silverstripe.org/general-questions/show/287220#post287220

Je suppose que c'est une peu la même réponse ou faut t'il que j'utilise dataObjectManager pour y arriver ?

Merci encore et encore

Thomas

Avatar
servalman

Community Member, 211 Posts

30 June 2010 at 3:39am

Edited: 30/06/2010 3:41am

Bonjour cher oncle cheese

J'ai une sorte de nouveau problème sur lequel je l''espere tu pourra m'aider:

Pour l'instant les scripts sur lesquels tu m'as (énormément) aidés font la chose suivante:

Je crées une page produits dans laquelle je peux ajoutés autant de produits que je veux via la popup de dataobjectmanager,
et cette page comporte un menu avec le Productname de tous les products

ProuctqPage :
|_ product 1
|_ attribut 1
|_ attribut 2
|_ attribut 3
|_ product 2
|_ attribut 1
|_ attribut 2
|_ attribut 3

Or dans les attributs de mes product j'ai besoin d'un champs HTML dans lequel jeux ajoutés des style comme dans Tyne MCe or

Il faut donc j'ai l'impression que je crée un une page par product c'est a dire comme ceci et je sais que nous en avion parlé.

ProuctqPage1 :
|_ product 1
|_ attribut 1
|_ attribut 2
|_ attribut 3
ProuctqPage2 :
|_ product 2
|_ attribut 1
|_ attribut 2
|_ attribut 3

Mais dans ce cas de figure j'ai aussi besoins que chaque product page est un menu composé des ProductName du même niveaux (comme des siblings).
Je n'arrive pas a savoir si cela ce fait avec la template Product_show.ss ou avec les scripts.

Voila mon code pour Product.php

<?
class Product extends DataObject
{
   static $db = array (
      'Productname' => 'Text',
      'Imagename' => 'Text',
      'Presentation' => 'Text',
      'Contenance' => 'Text',
      'Actifs' => 'Text',
      'Price' => 'Text'
   );

   static $has_one = array (
      'ProductPage' => 'ProductPage'
   );

   public function getCMSFields_forPopup()
   {
      return new FieldSet(
         new TextField('Productname'),
         new TextField('Imagename'),
         new TextField('Presentation'),
         new TextField('Contenance'),
         new TextField('Actifs'),
         new TextField('Price')
         //new TextareaField('Quote')
         

      );
   }

   public function Link() {
return $this->ProductPage()->Link("show/$this->ID");
}

public function FlashVar() {
return "someVar=$this->Imagename";
}
}

et voila le code pour ProductPage.php
<?
class ProductPage extends SiteTree
{
static $has_many = array (
'Products' => 'Product'
);

public function getCMSFields()
{
$f = parent::getCMSFields();
$f->addFieldToTab("Root.Content.Products", new DataObjectManager(
$this,
'Products',
'Product',
array('Productname'=>'Productname','Imagename'=>'Imagename','Presentation' => 'Presentation','Contenance' => 'Contenance','Actifs' => 'Actifs','Price' => 'Price'),
'getCMSFields_forPopup'

));

return $f;
}

}

class ProductPage_Controller extends Page_Controller
{

public function index() {
return Director::redirect($this->Products()->First()->Link());
}

static $allowed_actions = array (
'show'
);
public function show() {
return array (
'Product' => DataObject::get_by_id("Product",$this->urlParams['ID'])

);
}

}

Merci de ton aide si tua s un peu de temps

T

Go to Top