codeigniter - Backbone js model get method returns "(an empty string)" even if modobj.attributes is correctly set -
i french, sorry poor english. beginner backbone js. have app uses codeigniter 2.1.3 (with mysql) , backbone js 1.0.0
i don't know why model getter
console.log(obj.get("x"));still returns "
(an empty string)"
here js code :
var questionnaire = backbone.model.extend({ // contain 3 attributes. // these default values urlroot: site_url + '/api/questionnaire/id/', defaults: { label_questionnaire: '', id_visuel: '', intro_questionnaire: '', version_questionnaire: '', type_questionnaire: '' } }); // create collection of questionnaires var questionnaires = backbone.collection.extend({ url: site_url + '/api/questionnaires', model: questionnaire }); var q =new questionnaire({id: '7'}); q.fetch(); console.log(q.get("type_questionnaire")); console.log(q.attributes);
the obj.attributes values (correct) :
id "7" id_questionnaire 7 id_visuel null intro_questionnaire "" label_questionnaire "my infos
" type_questionnaire 1 version_questionnaire 0
the php api code :
require(apppath.'/libraries/rest_controller.php'); /* * based on : * https://github.com/philsturgeon/codeigniter-restserver */ class api extends rest_controller { public function __construct() { parent::__construct(); $this->load->model('type_questionnaire_model'); } function questionnaire_get() { if(!$this->get('id')) { $this->response(null, 400); } $questionnaire = $this->survey_model->get_survey( $this->get('id') ); if($questionnaire) { $this->response($questionnaire, 200); // 200 being http response code }else{ $this->response(null, 404); } } ... }
the database mysql table structure :
create table if not exists `questionnaire` ( `id_questionnaire` int(11) not null auto_increment, `label_questionnaire` text character set utf8 not null, `id_visuel` int(11) default null, `intro_questionnaire` text character set utf8 not null, `version_questionnaire` int(11) not null, `type_questionnaire` int(11) not null, primary key (`id_questionnaire`) ) engine=innodb default charset=latin1 auto_increment=18 ;
is problem come defaults values ? can me please ?
Comments
Post a Comment