I'm completing a module that concerns the registration of new users.
Now, my module creates a table in the db that has an id field and an id_usergoup field.
On the configuration page, I would like to see the box with all the user groups available.
The user can select some and their id goes to write in my table. Similarly, in the box I have to see selected ones already chosen (if there are).
How can I make the box with user groups with HelperForm?
And take select the values already chosen and saved in my table?
I hope in your suggestion. Thank you.
In the array for the inputs, you can generate the customer group with this code:
array(
'type' => 'group',
'label' => $this->l('Customer group'),
'name' => 'groupBox',
'required' => true,
'values' => Group::getGroups((int)$this->context->language->id),
'hint' => $this->l('Customer group for which this tab will be available.'),
)
And you can get the selected values with: Tools::getValue('groupBox');
Regards!
Related
I built a form that displays a user's existing email, then asks for a new email and a confirmation email to assure that they've typed it in correctly. The field for the new email is 'new_email', the confirmation field is 'new_email_confirm'. The model already has the field 'email' where their existing email address is stored. The scenario used is 'change_email'. Every other rule works and is validating with errors in my model but this one...when I enter in the exact same email/confirm that's already taken in 'email' I don't get an error, it is allowed to save.
In rules, I have added the following:
array(
'new_email,new_email_confirm',
'required',
'message'=>'This is a required field',
'on'=>'change_email',
),
array(
'new_email',
'email',
'message'=>'Invalid email address',
'on'=>'change_email',
),
array(
'new_email',
'compare',
'compareAttribute'=>'new_email_confirm',
'message'=>"Emails don't match",
'on'=>'change_email',
),
array(
'new_email',
'unique',
'className'=>'User',
'attributeName'=>'email',
'on'=>'change_email',
),
What am I doing wrong?
I have two dirty suggestions to do this, since I am not able to find out what the exact problem is.
1- write a custom validation for uniqueness and remove the unique rule:
array('new_email','customValidationRule'),
and write it like below:
public function customValidationRule(){
//after all validation rules
if(!$this->hasErrors()){
$check=User::model()->findByAttributes(array('email'=>$this->new_email)); //or $this->new_email_confirm
if(!is_null($check) || !empty($check)){
$this->addError('new_email','The new email has been already taken by other!');
}
}
}
2- replace new_email with new_email_confirm in your unique rule.
i want to select multiple files at once, but only ONE File always shows up in the MultiFile-list Div container with the possibility to delete it. But i want to shop up all the files i selected.
What am i doing wrong?
$this->widget('CMultiFileUpload', array(
'model' => $gallery,
'name' => 'attachments',
'accept' => 'jpg|png',
'denied' => 'Only doc,docx,pdf and txt are allowed',
'max' => 100,
'duplicate' => 'Already Selected',
'options'=>array(
),
'htmlOptions' => array('multiple' => 'multiple', 'size' => 25)
)
);
CMultiFileUpload is based on jQuery Multiple File Upload Plugin ($.MultiFile) . On it's site we can read:
What this isn't
This plugin will not create a dialog that allows the user to select multiple files at once. That simply cannot be done via javascript. If that's what you need, you should consider using HTML5's multiple="multiple" attribute or one of the many other flash based file upload solutions (eg.: SWFupload, uploadify and others)
So probably the built in widget isn't what you are looking for. Xupload yii extension, on the other hand might be what you are looking for.
I have two data sources
1) Database
2) Memcached or Totally different database
From 1st database I am getting the group members list IDs ( has more than 10 thousand rows) and after getting the list I query second database or hit Memcached to get the actual details
$connection = Yii::app()->db;
$sql = 'select user_id,joined_date from group_data where group_id=:group_id ';
$dataProvider = new CSqlDataProvider($sql, array(
'keyField' => 'user_id',
'sort' => array(
'attributes' => array(
'user_id',
'joined_date'
),
'defaultOrder'=>array(
'user_id ASC',
)
),
'pagination' => array(
'pageSize' => 30,
),
'totalItemCount' => $count,
));
$connection_master = Yii::app()->masterdb;
In the above data provider , I am not sure how to include my second database and get the actual user name since it is in other database .No direct connection from one database to other.
Here the problem is pagination is based on the first database table ( 30 records per page) and the actual data is from second table .
Any idea on how to implement this ?
Thank You
You could build your own custom data provider class. You can extend it from CDataProvider and implement the missing abstract methods:
abstract protected function fetchData();
abstract protected function fetchKeys();
abstract protected function calculateTotalItemCount();
Notice, that your storage model already comes very close to these methods: You store the IDs in one database and the actual data in another. So you can focus on one DB at a time in each of these methods.
You'd start with fetchKeys(). There you need to query the keys (=IDs) from your second database. Have a look at CSqlDataProvider::fetchData() to see how to use the CPagination object from $this->getPagination() to find out the current limit and offset. If you need sorting you'd also inspect the CSort object from $this->getSort() for current sort settings. With all that data available you should be able to build the query for the IDs on the currently requested result page.
Then in fetchData() you can obtain those keys through $this->getKeys(). You should not call fetchKeys() directly, because with getKeys() the result from fetchKeys() is "cached", so if it's called again later in the same request, there won't be another query. With that keys you now can easily query your main database. The result will represent the rows on the current page.
Finally you have to implement calculateTotalItemCount(). This is very easy again: Just query your second DB for the total number of items.
That's all you need to do - the code in the base CDataProvider class will take care of the rest and call your methods on demand.
I've got the following problem. I built a PHP file, which reads categories from a file, to impor tthem into Magento. I am able to read the file, no problem. The connection via NuSOAP to the Magento API works aswell. I can get the SessionID and I am able to get data, like Information for a category, also its possible to delete categories.
But, whenever I try to create or update anything, it throws an error. The rights for the user are ok aswell. For example, when I create a category, I add the usual data to the call:
$proxy->call(
$sessionId,
'category.create',
$rootCategory, array(
'name' => "TEST",
'is_active' => '1',
'page_layout' => 'two_columns_right',
'description' => "TEST",
'meta_title' => "TEST",
'meta_description' => '',
'meta_keywords' => "TEST",
'include_in_menu' => '0',
'display_mode' => 'PRODUCTS',
'available_sort_by' => 'price',
'default_sort_by' => 'price',
'is_anchor' => '0'
)
);
All the time, it says:
(
[faultcode] => 102
[faultstring] => Category not exists. )
Which is not true. The $rootCategory is definatly a category, which is existing. I tried all other categories, I tried to add a 'path' to the info, I tried to use less information (only the neccesary stuff), I tried to read existing categories to get their IDs, NOTHING works. It always throws this faultcode.
Same happens, when I try to update a category, or create /update a product. Deleting is no problem at all.
Do you see the problem?
i just compared your NON working exemple and i found this while comparing it with another exemple i has ( i do not pretent to be expert ) ..
but seems like your $new_category, array(blahblha) ...
should be INSIDE an array according to the exemple i already have
like this array($new_category,array(blahblah) ...
this is the mains difference i just saw ..
here is the EXEMPLE i just pulled out of the web ... Adapt to your needs..
$proxy->call(
$sessionId,
'category.create',
array(
3,
array(
'name'=>'New openerp',
'is_active'=>1,
'include_in_menu'=>2,
'available_sort_by'=>'position',
'default_sort_by'=>'position')) );
Have you tried specifying the category_id key in your $rootCategory within the call:
$selectedCategory['category_id'],
array('name'=>'New Category Through Soap')
)
Reference: http://www.magentocommerce.com/wiki/doc/webservices-api/api/catalog_category
I have a user submit a field to the database, it validates, and makes the entry. The primary key of this new row is auto-incremented.
The user then gets to another form where that newly created field is required.
Can anyone shed any light on this problem?
Thanks in advance!
Check out Model::getInsertID();
$this->getLastInsertID();
cakephp model docs
// Save the first form
$this->Ingredient->save($newData);
// Get the id of the record just saved
$newIngredientId = $this->Ingredient->id;
// Redirect to a new form
$this->redirect(array(
'controller' => 'dish',
'action' => 'add',
'?' => array('lastId' => $newIngredientId)
));
http://book.cakephp.org/view/1031/Saving-Your-Data,
http://book.cakephp.org/view/1442/link
If it's in the database, when you get to your next form just read it out again in your controller and set it to a view variable.
$this->set('lastid', $this->Model->read(null,$id));
Or if you need to search the database for the field use find
$this->set('lastid', $this->Model->find('first', array('conditions'=>array('username'=>'MyUserName')) , array('id')));
You could go around it by using mysql_insert_id()