php - backbone.js, views and routing -


i developing app using slim, backbone.js , jquery mobile mysql backend.

the workflow along lines of:

1) search uni module. 2) list matching modules. 3) select , view module details page. 4) list lecturers associated module. 5) select , view lecturer.

i have steps 1 through 4 complete, cannot lecturer detail page display. think might passing id api call wrong, or routing messed up.

in index.php have list of api calls:

$app = new slim();

$app->get('/modules', 'getmodules'); $app->get('/modules/:id', 'getmodule'); $app->get('/modules/search/:query', 'getmodulesbyname'); $app->get('/modules/:id/students', 'getstudents'); $app->get('/modules/:id/lecturers', 'getlecturers'); $app->get('/modules/lecturers/:id/lecturer', 'getlecturer');

the last 2 relate pulling list of lecturers associated module, , pulling individual lecturer when tap on them, showing details.

getlecturers works, , here reference:

function getlecturers($id) { $sql = "select l.staffnumber, l.firstname, l.lastname, l.moduleno1, l.moduleno2, l.email, m.moduleno lecturertable l, moduletable m m.moduleno=:id , (l.moduleno1=:id or l.moduleno2=:id)";

try {     $db = getconnection();     $stmt = $db->prepare($sql);     $stmt->bindparam("id", $id);     $stmt->execute();     $lecturer = $stmt->fetchall(pdo::fetch_obj);     $db = null;      if (!isset($_get['callback'])) {         echo json_encode($lecturer);     } else {         echo $_get['callback'] . '(' . json_encode($lecturer) . ');';     }  } catch(pdoexception $e) {     echo '{"error":{"text":'. $e->getmessage() .'}}'; } } 

getlecturer (single) here:

function getlecturer($id) { $sql = "select l.staffnumber, l.firstname, l.lastname, l.moduleno1, l.moduleno2, l.email lecturertable l l.staffnumber=:id";

try {     $db = getconnection();     $stmt = $db->prepare($sql);     $stmt->bindparam("id", $id);     $stmt->execute();     $lecturer = $stmt->fetchobject();     $db = null;      if (!isset($_get['callback'])) {         echo json_encode($lecturer);     } else {         echo $_get['callback'] . '(' . json_encode($lecturer) . ');';     }  } catch(pdoexception $e) {     echo '{"error":{"text":'. $e->getmessage() .'}}'; } } 

here routes in main.js:

var approuter = backbone.router.extend({

routes:{     "":"list",     "list":"list",     "modules/:id":"moduledetails",     "modules/:id/students":"modulestudents",     "modules/:id/lecturers":"modulelecturers",     "modules/:id/lecturers/:id/lecturer":"lecturerdetails" }, 

and matching modulelecturers , lecturerdetails functions:

modulelecturers:function (id) { var module = new module({id:id}); module.lecturers.fetch(); this.changepage(new modulelecturerspage({model:module.lecturers})); },

lecturerdetails:function (id) {     var lecturer = new lecturer({id:id});     var self = this;     module.lecturers.lecturer.fetch({         success:function (data) {             self.changepage(new lecturerview({model:data}));         }     }); }, 

i have lecturers , lecturer models, along lecturers collection:

window.lecturers = backbone.model.extend({

urlroot:"../api/lecturers",  initialize:function () {     this.lecturers = new lecturerscollection();     this.lecturers.url = '../api/modules/' + this.id + '/lecturers'; } 

});

window.lecturerscollection = backbone.collection.extend({

model:lecturers,  url:"../api/lecturers", 

});

//new

window.lecturer = backbone.model.extend({

urlroot:"../api/lecturer", 

});

and lecturer view pointing 'lecturer-details' html template, 1 isn't showing:

window.lecturerview = backbone.view.extend({

initialize:function () {     this.template = _.template(tpl.get('lecturer-details')); },  render:function (eventname) {     $(this.el).html(this.template(this.model.tojson()));     return this; } 

});

the lecturer list item, when tapped on should detail view show, contains link: href='#modules/<%= moduleno %>/#lecturers/<%= staffnumber %>'

though url seems correct in browser (...jquerymobile/#modules/999003/#lecturers/123001) lecturer detail page doesn't show.

i have been breaking head 1 couple of days - if can spot out of place, appreciate greatly!

you cannot use double hashtag, fix link:

you have:

href='#modules/<%= moduleno %>/#lecturers/<%= staffnumber %>' 

the right must be:

href='#modules/<%= moduleno %>/lecturers/<%= staffnumber %>' 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -