How can we get a list of string into controller than show to the view in custom block

Permalink
Hi i have create a custom block
they is three input field
<input id="ccm_expandable_block_city" name="city[]" value="<?php echo $controller->city?>" maxlength="255" type="text" style="width:80%">
with the same name
how i am suppose to get a list of city inside my controller save it and show it in the view

my controller look like this
protected $btTable = 'btExpandable';
   protected $btInterfaceWidth = "375";
   protected $btInterfaceHeight = "325";
   protected $btCacheBlockOutput = true;
   protected $btCacheBlockOutputOnPost = true;
   protected $btCacheBlockOutputForRegisteredUsers = true;
   public $country = "";
   public $city = "";
   public $adresse = "";
   public $number = "";
   public $fax = "";
    public function getBlockTypeDescription() {
      return t("Creates a expandable block");
   }
   public function getBlockTypeName() {

Any help would be appreciate

 
JohntheFish replied on at Permalink Reply
JohntheFish
If the field names map directly to database table columns, you don't have to do anything. C5 saves them for you and then makes the values available to subsequent edit/view.

Create a simple block using the designer content addon and you will see such minimal controller/edit/view files created.
DarkVision replied on at Permalink Reply
i never manage to get a list of my city its always get the last one when i try to show it in the view

the add.php file only as 3 input with similar name but each time return the last one in the view never a list what type data should i use for db.xml im kind of confuse.
<input id="ccm_expandable_block_city" name="city" value="<?php echo $controller->city?>" maxlength="255" type="text" style="width:80%">
<input id="ccm_expandable_block_city" name="city" value="<?php echo $controller->city?>" maxlength="255" type="text" style="width:80%">
<input id="ccm_expandable_block_city" name="city" value="<?php echo $controller->city?>" maxlength="255" type="text" style="width:80%">
JohntheFish replied on at Permalink Best Answer Reply
JohntheFish
You can make the input name with '[]' on the end and php will take all similar and create an array.
name="city[]"


You will then need to process that in the controller save() method to serialize it and then in the view() method to unserialize it. (or whatever method of turning an array into a string you use)
DarkVision replied on at Permalink Reply
Thx i was able to get my list by using serialize and unserialize
JohntheFish replied on at Permalink Reply
JohntheFish
Just published a howto on this as there were several similar questions.

http://www.concrete5.org/documentation/how-tos/developers/save-and-...