Welcome Guest, Not a member yet? Register   Sign In
Unable to render an actual view with a vanity url since no view exists with that user name
#1

[eluser]johnmerlino[/eluser]
Hey all,

While I can generate the vanity url in the url, since there is no view with such a name, I'm not sure how to render a view.

For example, I have this in routes:

Code:
$route['blogs/(:any)'] = "blogs/get_blogger";

Basically if someone types in blogs/johnmerlino in the url, it will call the get_blogger method, which does this:

Code:
public function get_blogger(){
            $user_name = $this->uri->segment(2);
            $u = new User();
            $u->where('user_name',$user_name);
            $u->get();
            $data = $u->post->get();
            $options['records'] = $data;
            
            
            $defaults = array('head' => 'Blog', 'subhead' => 'This is the' . $u->first_name . ' ' . $u->last_name . 'blog page.' , 'current_user' => $this->current_user());
            $result = array_merge($defaults,$options);
            $this->template->render_content('template', "/blogs/{$u->user_name}", $result);
        }

So basically I find the user record in the database that matches the uri second string. I then return the user record as an object and posts associated with that user as an object. However, when I go to load the page with the render_content method which does the same thing as the default codeigniter method but places the code in a template, I get the following error:

Code:
An Error Was Encountered

Unable to load the requested file: /blogs/johnmerlino.php

I get this error because I have no view in my blogs directory called johnmerlino. However, it doesn't sound feasible to dynamically create a view file for that user when they sign up in that directory. So I am curious how everyone else does it?

Thanks for response.
#2

[eluser]johnmerlino[/eluser]
An easy resolution is just to have it map to blogs/index and pass the data from get_blogger() into there. That would work. But what I render on that page is just the blog categories that belong to that specific user. In other words, once they go to their vanity url e.g. blogs/johnmerlino. I want them to be able to create a new category dynamically which will get stored in the categories table in the database. Then they can begin adding blogs to that category. My question is how can I setup my routing so I can have a vanity url which relates to the username they give at sign up (e.g. johnmerlino) and then when they view their personal page, allow them to create categories which take them to that category url (e.g. mysite.com/blogs/my_category) where they can begin adding posts on that page my_cateogry and where people can comment on that post.

Any suggestions at all?

Thanks for response.
#3

[eluser]johnmerlino[/eluser]
I'm trying to get a regex that will only look at:

'blogs/[a-zA-Z0-9]' (e.g. blogs/johnmerlino but not blogs/johnmerlino/categories or blogs/categories/johnmerlino)

And then another regex that would look at:

'blogs/categories/[a-zA-Z0-9]+' (e.g. blogs/categories/health but not blogs/health or blogs/categories/)

The two routes I am currently trying to use fail at doing this:

$route['blogs/([a-zA-Z0-9])'] = "blogs/get_blogger";
$route['blogs/categories/([a-zA-Z0-9])+'] = "blogs/categories/view_category";

Thanks for response.
#4

[eluser]johnmerlino[/eluser]
ok I figured out the dynamic routing and how to render views based on it. But still I am not certain how to reference a link the the vanity url. For example, when a person wants to create a new category, and then be redirected back to the vanity url that they were just looking at, what path can I specify in the redirect link? I can't hard code the vanity url, because that will change depending on the vanity url the person is currently viewing.

Thanks for response
#5

[eluser]johnmerlino[/eluser]
any resolution on this? A user clicks a link which takes them to vanity url (e.g. /blogs/johnmerlino). But they could have clicked another vanity url (e.g. /blogs/johnsmith). Now the user can create a new category. So he is taken to /category/new_category page, if category is successfully created, I want to navigate him back to /blogs/johnmerlino if that is the vanity url he was coming from when creating the new category. However, I cannot put redirect('blogs/johnmerlino') because he might have been coming from blogs/johnsmith. I need a variable to put in my redirect function which will reload the vanity url page that he was coming from when clicking on /category/create link.

Thanks for response.

Ok I think best solution is just to include the vanity url as part of link to new page.
#6

[eluser]CroNiX[/eluser]
Use session and store the last url they were on in there. Then you can recall it and redirect back if necessary. You might also be able to access the last page they were on with $_SERVER['HTTP_REFERER'], although that is set by the browser and shouldn't explicitly be trusted.
#7

[eluser]johnmerlino[/eluser]
Thanks for response. I'll try it.




Theme © iAndrew 2016 - Forum software by © MyBB