0

I want to know if its possible to create urls dynamically in MVC. Example i am building a shopping store in which i have categories and products. Now if i use product before calling category name or product name it works (http://www.example.com/products/mycategory). But i don't want to use products in the center the URL that i require is http://www.example.com/mycategory.

Same this i want for the content pages.

Can any body help me out on this matter.

6
  • You may use some htaccess to redirect http://www.example.com/mycategory to http://www.example.com/products/mycategory Commented Oct 14, 2014 at 5:07
  • What framework are you using? You want to set up a controller that allows you to harness that end point. Commented Oct 14, 2014 at 5:07
  • I am building my own framework @Darren. Kamran in MVC you don't need to define links in htaccess because every thing is controling in Controllers Commented Oct 14, 2014 at 5:19
  • @WaqarAzeem Just set up a controller called mycategory with an index method which would allow you to simply access www.mysite.com/mycategory Commented Oct 14, 2014 at 5:23
  • 1
    @WaqarAzeem you might find this helpful: stackoverflow.com/a/19309893/727208 Commented Oct 14, 2014 at 5:57

1 Answer 1

1

I'll throw it up in an answer here for you. Basically if you're following MVC structure and all, your controllers are always your endpoints that are visible to the user.

Sine that is the case, all you want to do is create a new controller that matches the term you want to use.

class mycategoryController extends Controller {

    function index() {
        // do your stuff...
    }

}

I can't say exactly how you create your controllers, but that will give you the general gist of things.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.