Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

one staff member one page ?¿?¿?


Reply


2 Posts   828 Views

Avatar
carlossg

Community Member, 13 Posts

4 August 2008 at 11:18pm

Edited: 04/08/2008 11:18pm

Hi all,
Still hanging around same problem.
Want that every staff member(teacher) in the school edits its own profile.
The straight way to do it is creating lots of TeacherPage.php in siteTree, and give permissions to each one.
But.. what about if the number of teachers is around 100, 100 pages?¿?¿.
Same for news list, do I need one page for each new added?¿?¿.

Thinking to have just one ManageTeacherPage with dropdownField to filter out.. but looks difficult.

Appreciate help and ideas...

Thanks a lot.

Avatar
Willr

Forum Moderator, 5513 Posts

4 August 2008 at 11:43pm

Edited: 04/08/2008 11:47pm

You could have a dataobject 'Teacher' and a 'ManageTeachers' page. Say you have a ManageTeachers.php page and on the site you give it the url http://mysite.com/teachers/

You could have a method in the ManageTeachers page called edit() and one called view(). What both these methods would do (see the forum module for how it does this as an example) is you could pass the ID of the teacher page then based on the action (edit or view) display a form or the data. (Im going to cut out alot of the nice stuff for the sake of writing this)

// in ManageTeachers.php
class ManageTeacher_Controller extends Page_Controller {

function view() {
// check to see if the URL structure is correct

if(isset(Director::urlParams('ID')) && is_numeric(Director::urlParams('ID')) {

// it is so try and get the teachers Info
$teacher = DataObject::get_by_id("Teacher", Director::urlParams('ID'));
}

return array(
"Teacher" => $teacher
);
}


Now you can call that method in the URL by going http://mysite.com/teachers/view/102 - which will get the teacher with ID 102. You can now access that teachers data in the template by going <% Control Teacher %> or $Teacher.Name

Now the edit ones a bit more tricky as you are going to have to construct the form etc so what you would have is under that view method

function edit() {

// check to see if the URL structure is correct
if(isset(Director::urlParams('ID')) && is_numeric(Director::urlParams('ID')) {

// it is so try and get the teachers Info
$teacher = DataObject::get_by_id("Teacher", Director::urlParams('ID'));
}

// CHECK PERMISSIONS - admin & user should only be able to edit this.
// LEFT THIS OUT.

$fields = new FieldSet(
// define the fields you want to edit on your teacher object
);
$actions = // whatever actions

$form = new Form($this, $fields, $actions);
$form->loadData($teacher);
return array(
"Form" => $form
);
}


So basically the edit method is a bit harder as you will need to construct forms and call loadData on the teacher object - which will load all the data from the Teacher into the form. And you also need to complete the permissions bit to check for correct user etc.