HOW TO_ make www.example.com/username

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

HOW TO_ make www.example.com/username

Eric-133

Hi, everybakers

I am quite new to use CAKE.
As the title mentioned, I want to make a blog like the rdBloggery. I
download the code for rd.
It do the way like www.example.com/posts/by/usersname. When You type
like, www.example.com/eric. It will show a default page for eric. Like
normal blog system does.

The rdBloggry defines a funciton BY in the controller.

It works great. BUT, it is quite complex for me, a rookie.

Can Any one help me to give a simple sample tell me how to do it? I
think should do assciation like users hasMany posts and comments,
hasOne profile, belongTo profile.

Thanks. Waiting for your reply!


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: HOW TO_ make www.example.com/username

dejan.ranisavljevic@gmail.com

If you already have users_controller. Define new method view.

in routes you will need something like:

  $Route->connect('/:username', array('controller' => 'users', 'action'
=> 'view'));

and than in your view method, you can get username from url,  if
someone go to htt://www.yoursite.com/eric:

  $username = $this->params['username'];

preatty cool and easy! :)

That's it.


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: HOW TO_ make www.example.com/username

Matt-131


What if you have 20 different controllers? Do still want to create 20
routes for each of the controller? How do you add a static page for example:

yoursite.com/eric - dynamic page
yoursite.com/contact - static page

Matt

[hidden email] wrote:

> If you already have users_controller. Define new method view.
>
> in routes you will need something like:
>
>   $Route->connect('/:username', array('controller' => 'users', 'action'
> => 'view'));
>
> and than in your view method, you can get username from url,  if
> someone go to htt://www.yoursite.com/eric:
>
>   $username = $this->params['username'];
>
> preatty cool and easy! :)
>
> That's it.
>
>
> >
>
>  


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: HOW TO_ make www.example.com/username

gobblez

Check out this article http://bakery.cakephp.org/articles/view/86

Be sure to read the comments to that article.  Someone placed an
alternative route example, and that worked better for me, because I had
admin routes enabled.  Couldn't get the method in the article to work
with admin routes.


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: HOW TO_ make www.example.com/username

Eric-133

I got error message like :

Warning: Missing argument 1 for UsersController::view() in D:\Program
Files\xampp\htdocs\ck\app\controllers\users_controller.php on line 65

Notice: Undefined variable: username in D:\Program
Files\xampp\htdocs\ck\app\controllers\users_controller.php on line 67

The code I set :

$Route->connect('/:username', array('controller' => 'users', 'action'=>
'view'));

function view($username)
 {
$this->set('user', $this->User->read(null, $username));
 }

I change the $id to $username.


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: HOW TO_ make www.example.com/username

Eric-133
In reply to this post by gobblez

I got it!

Thanks...

Cause the sequence  of the route.php. I should put the  following in
the last line.
$Route->connect('/*', array('controller' => 'users', 'action'=>
'view'));
 

Loving Cake!!


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---