It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I use Extjs4 and MVC. I would like to change my Model's fields dynamically...
Something like adding a variable number of fields... Any suggests?
You can use the model.setFields(fieldsArray) function, shown here in the API. This method replaces all existing fields on the model with whatever new fields you include in the argument. There is not a static getFields method to capture the existing fields so as not to overwrite them but it is easy enough to get them using model.prototype.fields.
I did this recently to attach dynamic permission setting fields to a "User" model before I loaded the user. Here's an example:
Ext.define('myApp.controller.Main', {
extend: 'Ext.app.Controller',
models: [
'User',
],
stores: [
'CurrentUser', // <-- this is not autoLoad: true
'PermissionRef', // <-- this is autoLoad: true
],
views: ['MainPanel'],
init: function() {
var me = this;
// when the PermissionRef store loads
// use the data to update the user model
me.getPermissionRefStore().on('load', function(store, records) {
var userModel = me.getUserModel(),
fields = userModel.prototype.fields.getRange();
// ^^^ this prototype function gets the original fields
// defined in myApp.model.User
// add the new permission fields to the fields array
Ext.each(records, function(permission) {
fields.push({
name: permission.get('name'),
type: 'bool'
});
});
// update the user model with ALL the fields
userModel.setFields(fields);
// NOW load the current user with the permission data
// (defined in a Java session attribute for me)
me.getCurrentUserStore().load();
});
}
});
Related
This question already has an answer here:
X is not associated to Y
(1 answer)
Closed 2 years ago.
I have read all the documentation on Stack Overflow and Sequelize website.
My database have the correct foreign keys. I associated IMAGES model to CREATION:
Images.associate = (models) => {
Images.belongsTo(models.Creations, {
foreignKey: 'idImagesCreation',
sourceKey: 'id',
onDelete: 'CASCADE',
});
};
In my controller I call like this
list(req, res) {
return Creations
.findAll({
raw: true,
include: [{
model: Images
}]
}).then(creations =>{ etc...
I have tried with "as" including {as: 'Images'} in my model and in my controller but still have the same error :
SequelizeEagerLoadingError: Images is not associated to Creations!
I have doubts on '(models)' parameter, where does associate find the models ?
I import them in the index file of the models folder. Is this sufficient?
Or does the error come from another source?
That's because as Sequelize says the models are not associated that way. You have the association from Images to Creations, but not from Creations to Images, so what you need to do is make that association like this:
Creations.associate = (models) => {
Creations.hasOne(models.Images, { as: 'ImagesCreation' });//hasMany depending on your relationship
};
This creates a FK on Images with the name ImagesCreationId, now you do the second association.
Images.associate = (models) => {
Images.belongsTo(models.Creations);
};
Now Sequelize knows the association the way you want.
I would recommed to do the migration so you have now the right association.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Want to iterate over this routes->bounds->legs->steps and alert(path). I am new to use json , can you please tell how to achieve this .thanks in advance.
JSON is --
{"routes":[{"bounds":{"copyrights":"Map data ©2013 Google"},
"legs":["steps":[{"distance":{"text":"1 ft","value":0},
"path":[{"ib":39.049870000000006,"jb":-76.51013}],
"lat_lngs":[{"ib":39.049870000000006,"jb":-76.51013}],
"start_point":{"ib":39.04987000000001,"jb":-76.51013},
"end_point":{"ib":39.04987000000001,"jb":-76.51013}}],
"via_waypoint":[],"via_waypoints":[]}],"status":"OK"}
The first step would be to parse the JSON string you have received.
Then you're able to access all of it's properties via dot notation:
With jQuery you could do it like this:
//{
// "Name": "Apple",
// "Expiry": "2008-12-28T00:00:00",
// "Price": 3.99,
// "Sizes": [
// "Small",
// "Medium",
// "Large"
// ]
//}
var json = '{"Name": "Apple","Expiry": "2008-12-28T00:00:00","Price": 3.99,"Sizes": ["Small","Medium","Large"]}';
var obj = jQuery.parseJSON(json);
$.each(obj.Sizes, function(index, item) {
$("body").append("<p>" + item + "</p");
});
Look how I access the Sizes property on the parsed JSON string:
obj.Sizes
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
In yii i am creating forget password functionality. after clicking on forgetpassword button, server will provide one php paga with blank text field for entering primary email id. Now how to retrive this email id in controller's method and how to check wheather this email id exist in databse. Please help me...
This will help you get started, you would put a method similar to this in your controller and create a view with a password field on it.
public function actionForgotPassword(){
if(isset($_POST['email']{
$record=User::model()->find(array(
'select'=>'email',
'condition'=>'email=:email',
'params'=>array(':email'=>$_POST['email']))
);
if($record===null) {
$error = 'Email invalid';
} else {
$newpassword = 'newrandomgeneratedpassword';
$record->password = md5($newpassword );
$record->save(); //you might have some issues with the user model when the password is protected for security
//Email new password to user
}
}else{
$this->render('forgetPassword'); //show the view with the password field
}
}
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am using cake php 2.0 version, I need to send a PDF attached email once clicked on survey button in my application?
Any help greatly appreciated.
Try this:
First of all, you should ensure the class is loaded using App::uses():
<?php
App::uses('CakeEmail', 'Network/Email');
in your function/action:
$email = new CakeEmail();
$email->attachments('/full/file/path/file.pdf')
$email->to = 'em...#email.co.uk';
$email->subject = 'Something';
$email->replyTo = $client['Client']['email'];
$email->from = $client['Client']['email'];
$email->emailFormat = 'html';
if($email->send()){
die('Email Sent!');
}else{
die('Failed to send email');
}
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I Want to separate the database functionality and logic part by having the database operations in the model and the logic part in the controller. Earlier I had all the code in the action part of the controller itself. I have tried something, but it doesn't work.
This is what I had earlier:
/* Controller */
function insertFormName(){
$formname=$_POST['formname'];
$ret = $this->Form->query("Select id from forms order by id DESC LIMIT 1");
$newid=$ret[0]['forms']['id'];
$this->Form->updateAll(array('Form.name' => "'$formname'"),array('Form.id' => $newid));
}
And now I changed it a bit, which doesn't work:
/* Controller */
function insertformname()
{
$this->data['Form']['formname']=$this->params['form']['formname'];
$this->Form->save($this->data);
$this->Form->updateAll(array('Form.name' => "'$formname'"),array('Form.id' => $newid));
}
/* Model */
function save($data)
{
$ret = $this->Form->query("Select id from forms order by id DESC LIMIT 1");
$newid=$ret[0]['forms']['id'];
$this->Form->updateAll(array('Form.name' => "'$formname'"),array('Form.id' => $newid));
return $newid;
}
EDIT:
I have tried it another way.. Have the entire functionality in the model and just call that function from the controller.Is this method correct?
/* Model */
function saveFormName($data)
{
$this->formname=$data[$this->name]['formname'];
$ret = $this->Form->query("Select id from forms order by id DESC LIMIT 1");
$newid=$ret[0]['forms']['id'];
$this->Form->updateAll(array('Form.name' => "'$formname'"),array('Form.id' => $newid));
}
/* controller */
function insertformname()
{
$this->data['Form']['formname']=$this->params['form']['formname'];
$this->Form->saveFormName($this->data);
}
It looks like you should probably revisit the Cake book (book.cakephp.org) and redo the lessons. If you setup your form correctly, you shouldn't have to manually assign $_POST['formname'] to $this->data. Try setting the field names in your form (in the HTML) to data[ModelName][FieldName].
Next:
$this->Form->updateAll(array('Form.name' => "'$formname'"),array('Form.id' => $newid));
Why are you updating data right after you saved it? Where do the $newid and $formname variables come from? You have them defined in the Model::save, but not in the controller.
This seems like you're trying to fight with the Cake automagic stuff too much. Perhaps you should repost your question, but please spell out your high level description rather than just a "why doesn't this work?" It looks to me like this could be simplified a ton, but, again, I'm not quite sure what your objectives are.
Respectfully,
Travis