How to display login username throughout session?

  • (2 Pages)
  • +
  • 1
  • 2

21 Replies - 6051 Views - Last Post: 18 November 2012 - 03:09 PM Rate Topic: -----

#16 kiasta  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 257
  • Joined: 18-November 07

Re: How to display login username throughout session?

Posted 15 November 2012 - 12:25 AM

I think I may be getting the idea, though I'm still not as advanced when it comes to logic, so my code may seem a bit... primitive?

So I have something like this:

Spoiler


The rest of the files are empty, I've just been trying to figure out to make the basic shell before I start coding any real logic. I believe I'm finally starting to understand it a bit. One thing I'm going to have a hard time with is displaying data from the database. I'm not entirely sure how I will go about doing that since I have to get the data with the controller and pass it to the view and then I'm going to need to somehow format the templates with the information without knowing anything about anything. I'm still going to be working hard on it for a good portion of the night, but I'm taking a break.
Was This Post Helpful? 0
  • +
  • -

#17 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1253
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: How to display login username throughout session?

Posted 15 November 2012 - 07:08 PM

Here's a simple MVC structure and example.

---

Sergio is trying to find a list of people who are from Bolivia.

www.dreamincode.net/people/find/bolivia

It's a safe assumption to say that in an MVC framework the parameters of the URL are going to passed as such:
/people             /find             /bolivia
Controller name     Action method     Method parameters


The first thing your application would do when receiving a request from that URL would be to find the controller it needs. In this case the 'people' controller.

Something like:

class PeopleController extends AppController {

}


So it found the controller and next it needs to find what to do? What METHOD was invoked? What action is needed?

class PeopleController extends AppController {

    function find() {
    }

}



So far so good, we know where the request has to go, and we know what method needs to run, but what about the third parameter, the actual "parameter"? Well that's in the function signature.

class PeopleController extends AppController {

    function find($location = null) {
        $this->set('foundpeople', someORM('find' => 'people', 'where' => 'location = '.$location);
    }

}


So we now have the actual list of people - the MODEL.

We can then pass that sucker to the view and display it easily as needed. Have you seen the cakephp cookbook?

http://book.cakephp....0/en/index.html

This post has been edited by Sergio Tapia: 15 November 2012 - 07:57 PM

Was This Post Helpful? 4
  • +
  • -

#18 kiasta  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 257
  • Joined: 18-November 07

Re: How to display login username throughout session?

Posted 18 November 2012 - 01:02 AM

Yeah I was looking at cakephp but it seemed a little intimidating and overwhelming. It's a lot of code for me to go through. I was able to set it up, even though I was having trouble with URL rewriting since I'm using a shared hosting server and had to mess around with .htaccess. From what I understand of cakephp it is very efficient and makes coding very simple. But the problem I have is I have to know how something works, I can't just use a framework (or cms for that matter) and be content without knowing everything about it and how it ticks. I guess I'm a bit weird but I get really frustrated using something I don't understand fully, I feel like I'm cheating some how. I'll read the cookbook and study how they made their framework but as for right now I just want to be able to code professionally and proficiently without the need for google (which currently is my only source of information and learning aside from DIC). Thanks for your advice Segio :)
Was This Post Helpful? 0
  • +
  • -

#19 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6062
  • View blog
  • Posts: 23,513
  • Joined: 23-August 08

Re: How to display login username throughout session?

Posted 18 November 2012 - 09:34 AM

Quote

want to be able to code professionally and proficiently without the need for google


You're being ridiculous. I've been doing this for 15 years, and I use Google CONSTANTLY. Any professional developer will, unless you're doing the same rote things everyday.
Was This Post Helpful? 3
  • +
  • -

#20 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3718
  • View blog
  • Posts: 5,990
  • Joined: 08-June 10

Re: How to display login username throughout session?

Posted 18 November 2012 - 10:43 AM

Yea, you'll never really be able to memorize everything you'll need, and even if you could, the programming languages and especially the frameworks and other 3rd party stuff used with them evolve so rapidly that it would pretty much be a wasted effort. Programming is as much about finding the answer as knowing them.

(I'm sure I just stole that last line from somewhere, but I can't remember from where :P)
Was This Post Helpful? 3
  • +
  • -

#21 kiasta  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 257
  • Joined: 18-November 07

Re: How to display login username throughout session?

Posted 18 November 2012 - 03:05 PM

View PostJackOfAllTrades, on 18 November 2012 - 11:34 AM, said:

Quote

want to be able to code professionally and proficiently without the need for google


You're being ridiculous. I've been doing this for 15 years, and I use Google CONSTANTLY. Any professional developer will, unless you're doing the same rote things everyday.


I see, well perhaps I am being a little ridiculous. I just meant that using gogle for every little tiny thing like proper usages of classes, syntax, etc. Mostly I want to be able to know the basics without resorting to google for tutorials and such. I don't mind using google for code snippets or better ways of doing things. I guess I should have been more specific. I'm probably still being a little ridiculous, though.

View PostAtli, on 18 November 2012 - 12:43 PM, said:

Yea, you'll never really be able to memorize everything you'll need, and even if you could, the programming languages and especially the frameworks and other 3rd party stuff used with them evolve so rapidly that it would pretty much be a wasted effort. Programming is as much about finding the answer as knowing them.

(I'm sure I just stole that last line from somewhere, but I can't remember from where :P/>)


Yeah, I suppose you're right. I'm obsessive and a little ocd. I'm always trying to memorize everything I constantly re-write code over and over to make sure I know it by heart. It's something that I will have to break apparently if I want to get anywhere.
Was This Post Helpful? 0
  • +
  • -

#22 laytonsdad  Icon User is online

  • Cheese and Sprinkles
  • member icon

Reputation: 439
  • View blog
  • Posts: 1,866
  • Joined: 30-April 10

Re: How to display login username throughout session?

Posted 18 November 2012 - 03:09 PM

I use Google for most things I have a question about while coding so I can check for syntax so I don't have to search for errors later.

I think that it is good to use to get better. I also spend every second I have extra reading posts here and searching for things to learn. You can never know it all so let Google be your friend.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2