Unlimited Plugins, WordPress themes, videos & courses! Unlimited asset downloads! From $16.50/m
  1. Code
  2. Yii

Building Your Startup: Using Routes for Schedule With Me

This post is part of a series called Building Your Startup With PHP.
Building Your Startup: Leveraging Bootstrap, Ajax, and jQuery
Building Your Startup: Leveraging Crowdfunding
Final product image
What You'll Be Creating

This tutorial is part of the Building Your Startup With PHP series on Envato Tuts+. In this series, I'm guiding you through launching a startup from concept to reality using my Meeting Planner app as a real-life example. Every step along the way, I'll release the Meeting Planner code as open-source examples you can learn from. I'll also address startup-related business issues as they arise.

Recently, I asked if our startup series has inspired any of your own entrepreneurial ideas and got you writing code. If so, please share a bit with us in the comments.

Let's Meet, Visit My Schedule With Me Page

For a long time since I began this project, I've wanted Meeting Planner and Simple Planner to have a publicly accessible page you can share with people to schedule a meeting with you. In other words, "Sure, let's meet, just visit my schedule with me page at Meeting Planner, I'm Bernie Sanders (no space)." 

In today's tutorial, I'll show you I've done it using Yii's routing and some of the related issues that came up.

If you haven't tried scheduling a meeting yet, you can see how it's done in this video:


The Schedule With Me page would be something like the PayPal Pay Me page:

Building Your Startup Schedule With Me - Paypal Pay Me

I do participate in the comment threads below, so tell me what you think! You can also reach me on Twitter @lookahead_io. I'm especially interested if you want new features or to suggest topics for future tutorials.

As a reminder, all of the code for Meeting Planner is written in the Yii2 Framework for PHP. If you'd like to learn more about Yii2, check out our parallel series Programming With Yii2.

Let's get started.

Planning the Schedule With Me Page

Building Your Startup Schedule With Me - Bernie Sanders Schedule With Me

Note: Bernie's not actually a Meeting Planner user, as far as I know.

Every Meeting Planner user has a unique username, e.g. berniesanders, and I decided to use this for the schedule with me URL. There were a few challenges to this feature:

  1. Designing the page
  2. Working with Yii Routing to map a root path to each person
  3. Managing the signup, login, and return to schedule

Designing the Page

Inspired by the PayPal Pay Me page (above) and others like it, I wanted to keep things simple initially. I used a responsive grid with offsets and centering:

Here's the /frontend/views/meeting/scheduleme.php view for the page:

The code displays the profile image the user uploaded in user settings or uses a general Gravatar.

Of course, I used /frontend/web/css/site.css to customize the margins, border, and background:

Managing the Yii Routing Changes

The routing for how Yii handles incoming browser requests is handled in /frontend/config/main.php under components. If you're not careful with configuring this, you can destroy your whole application as incoming requests fail out to error pages.

Here's the earlier routing before schedule with me:

I've written a bit before about routes in How to Program With Yii2: Sluggable Behavior, part of our Yii programming series, and you can read more background in the Yii documentation.

In Building Your Startup: Meetings With Multiple Participants, I wrote two episodes about dynamic paths by username for unique meeting URLs as shown below:

'<username>/<identity:[A-Za-z0-9_-]{8}>' => 'meeting/identity',

This broke lots of two-item routes such as meeting/[meeting_id] until I moved up more dynamic mapping above it to take precedence:    

And any second item paths with characters needed to be statically defined because our identity strings for meetings are eight characters, e.g. features.

Routes such as features are fixed, which goes to controller sites and action features as shown above. Remaining features are mapped dynamically as in: '<controller:\w+>/<action:\w+>' => '<controller>/<action>',

Trying to create a one-item dynamic variable route such as /[username], e.g. https://meetingplanner.io/berniesanders, broke lots of single-item routes such as https://meetingplanner.io/about and the reminders page https://meetingplanner.io/reminder.

So I had to begin statically defining many of them. 

Here's the final routing with new static routes for one-word paths:

And you can check out "Bernie's page" and schedule a meeting with him here:


Note: Meeting Planner and Simple Planner work interchangeably, and I run both sites to offer users multiple brands. Simple Planner is for social get-togethers, and Meeting Planner is for more business-related stuff.

Managing Signup and Login From the Schedule With Me Page

Most people who initially visit a schedule with me page won't have an account with us. So they'll be redirected when they click Schedule With Me to the signup or login page.

After they log in, we want to return them to the meeting creation page pre-loaded with the owner of the schedule with me page added as a participant. We use setReturnUrl to do this:

It updates the session (usually through a cookie) so that after a person signs up or logs in, they are returned to the target page.

Here's the full /frontend/controllers/MeetingController.php actionScheduleme method:

Adding the Schedule Page Owner as a Participant

Here's the /frontend/controllers/MeetingController.php actionCreate method:

It processes the user id of the schedule with me page owner as $with_id to add them as a participant. And it also checks first to make sure there isn't already a meeting in place between these two people—to prevent duplicates:

I originally added the feature to prevent users from creating new meetings when there was already another empty new meeting they'd created previously.

Looking Ahead

There will be some things about this page I'll clean up in the future as I speak to real users and gather feedback. Perhaps I'll automatically share the user's most frequent days and times for meetings. And I'll create a user setting to turn off your scheduling page in case you don't want it.

In Closing

All the work I've done recently with Bootstrap to create a better responsive interface for Meeting Planner made it easier for me to quickly code the schedule with me page.

Making sure the new Yii routes worked and didn't break anything on the site was the hardest part of this. I also went and checked all of my Ajax calls to make sure none of them were affected.

I hope today's tutorial was useful to you in learning to customize site URLs for your user base and the basics of MVC routing.

Have your own thoughts? Ideas? Feedback? You can always reach me on Twitter @lookahead_io directly. Watch for upcoming tutorials here in the Building Your Startup With PHP series. Some cool features are on their way.

Again, if you haven't tried out Meeting Planner or Simple Planner yet, go ahead and schedule your first meeting

Related Links

Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.