1. Trang chủ
  2. » Công Nghệ Thông Tin

Tạo mạng xã hội với PHP - part 18

10 6 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 10
Dung lượng 3,65 MB

Nội dung

Profiles and Statuses Profile link The link to view a user''s profile will simply be: profile/view/userid,. This enacts the profile controller, which in turn passes control to the profile information controller. We need to add this link to the following templates we already have: • • Views/default/templates/members/list.tpl.php Views/default/templates/members/search.tpl.php The link is shown below: DINO SPACE! Members List {letter} {name} Keeper of {dino_name} a {dino_gender} {dino_breed} {form_relationship} The profile information controller (controllers/profile/ profileinformationcontroller.php) needs to communicate with the model, Controller to get the data for the profile, and have the data assigned to template variables. We already have a method in the controller to do this,...

Profiles and Statuses Profile link The link to view a user's profile will simply be: profile/view/userid, This enacts the profile controller, which in turn passes control to the profile information controller We need to add this link to the following templates we already have: • • Views/default/templates/members/list.tpl.php Views/default/templates/members/search.tpl.php The link is shown below: DINO SPACE! Members List {letter}

{name}

Keeper of {dino_name} a {dino_gender} {dino_breed}

{form_relationship} Controller The profile information controller (controllers/profile/ profileinformationcontroller.php) needs to communicate with the model, to get the data for the profile, and have the data assigned to template variables We already have a method in the controller to this, so it should be a fairly trivial task: include the model, and call the toTags method to push the profile information to template tags, as highlighted in the code below: Template The template for this aspect of the profile is shown below (views/default/ templates/profile/information/view.tpl.php); the highlighted aspects show the common template information shared by all aspects of the profile (including aspects we may add in the future) Friends
  • {users_name}
  • View all
  • View mutual friends
  • [ 153 ] Download from www.eBookTM.com This material is copyright and is licensed for the sole use by RAYMOND ERAZO on 25th October 2010 3146 KERNAN LAKE CIRCLE, JACKSONVILLE, 32246 Profiles and Statuses
Rest of my profile
  • Status updates
{profile_name}

{p_bio}

My Dinosaur Name {p_dino_name} DOB {p_dino_dob} Breed {p_dino_breed} Gender {p_dino_gender} In action If we now visit a user's profile (http://localhost/folder-containingsocialnetwork/profile/view/1), we see the user's profile on the screen as shown in the following screenshot: [ 154 ] Download from www.eBookTM.com This material is copyright and is licensed for the sole use by RAYMOND ERAZO on 25th October 2010 3146 KERNAN LAKE CIRCLE, JACKSONVILLE, 32246 Chapter Relationships—some improvements At present, our relationships controller is only set to either list our relationships with other users, or pending relationship requests It isn't set up to show all of the contacts of a user, or all of the mutual contacts we have in common with a user Let's extend our relationships controller to facilitate these; after all, we have placed a link to them on our profile pages All contacts To get a list of all the contacts of a user, we simply require the relationships model, and call the getRelationships method, passing the user whose profile we were viewing: /** * View all users connections * @param int $user * @return void */ private function viewAll( $user ) { if( $this->registry->getObject('authenticate')->isLoggedIn() ) { require_once( FRAMEWORK_PATH 'models/relationships.php'); $relationships = new Relationships( $this->registry ); $all = $relationships->getByUser( $user, false, ); $this->registry->getObject('template')[ 155 ] Download from www.eBookTM.com This material is copyright and is licensed for the sole use by RAYMOND ERAZO on 25th October 2010 3146 KERNAN LAKE CIRCLE, JACKSONVILLE, 32246 Profiles and Statuses >buildFromTemplates('header.tpl.php', 'friends/all.tpl.php', 'footer.tpl.php'); $this->registry->getObject('template')->getPage()->addTag('all', array( 'SQL', $all ) ); require_once( FRAMEWORK_PATH 'models/profile.php'); $p = new Profile( $this->registry, $user ); $name = $p->getName(); $this->registry->getObject('template')->getPage()->addTag( 'connecting_name', $name ); } else { $this->registry->errorPage( 'Please login', 'Please login to view a users connections'); } } Template We need a template file called views/default/templates/friends/all.tpl.php to act as the template for viewing all of a user's friends Connections of {connecting_name}
  • {plural_name} with {users_name}

In action Now, if we click the view all contacts link on a user's profile, we are shown a list of all of their contacts as shown in the following screenshot: [ 156 ] Download from www.eBookTM.com This material is copyright and is licensed for the sole use by RAYMOND ERAZO on 25th October 2010 3146 KERNAN LAKE CIRCLE, JACKSONVILLE, 32246 Chapter Editing the profile Again, our model will make things much easier for us here, as it allows us to get all of the information from the profile (to populate the edit form fields) and includes provisions for saving changes to a profile It won't, however, deal with a user requesting to change their password or update their e-mail address; we will discuss that separately Controller additions Our controller needs to have a new method added to display an edit page, and process the form submission when a user edits their profile This will then interact with the model, calling the save method to save the profile changes in the database Uploading a photograph—an image handler As we are going to be uploading and scaling a user's photograph to act as their profile picture, we should consider developing an image handler class, which can process uploads, save images, and deal with resizing, keeping all of our image related code in a single place Following is the code for such a file (lib/images/imagemanager.class.php) Some important aspects are highlighted and discussed within

Ngày đăng: 08/05/2021, 17:34