Welcome Guest, Not a member yet? Register   Sign In
jumping into the pool: 1st App
#1

[eluser]number1chump[/eluser]
Hello,


well, today I finished one old style web of mine and managed to try what I most wanted. The MVC OOP waters.

I thought that creating a login page would be pretty much ideal to grasp how this works. I put the connection and queries to the DB in the Models folder, the form with the input fields in the Views and the traffic cop in the Controllers folder. However, some questions arouse:

I created a folder CI within htdocs and that is where I installed CI. Then, I went to the Application folder, and I could see the subfolders of MVC. Fine. But, what about when I want to start another project ? Because if I put all of the files inside their respective MVC folders, what happens with those of the other projects? Do you just create a folder, say "Project1" within M, V and C and then files inside of them?

The second question. Alright I have my (OOP fashion) code to access the DB which I put in the Models folder. I called it login_db.php and then a simple form in the Views that I called login.php and then another file in the Controllers, about which I was asking myself how to write it so that it would call both files and somehow put them together. By just mimic I wrote as this (I know it is not correct after getting the error)

Code:
<?php

class Login extends Controller {

    function Login()
    {
        parent::Controller();    
    }
    
    function login()
    {
        $this->load->view('login.php');
                $this->load->model('login_db.php');
    }
}


And the third question, well, I managed to access the page through the localhost syntax and it was like this http://localhost/ci/index.php/login/login

but it came up with this "foreseen" error

Fatal error: Cannot redeclare Login::login() in C:\xampp\htdocs\CI\system\application\controllers\login.php on line 10

because yes, what I feared, that syntax of declaring it twice cant be.

I think these are easy things yet it is necessary to understand this very core, and so far I am floating in the pool but looking around where to swim to.

If anybody knows the right way to organize files and call them, I would very much be obligued.

best regards

Al
#2

[eluser]adhardy213[/eluser]
I dont know about setting up multiple applications in one CI install but as far as your login Id probably say what you are trying to do is login a user.

Id be more inclined to want to write /user/login

You'd have a controller called user with a login method, your model would be called user_model or something similar.

My point is login is more of an action on object not a thing.

I think as well functions Login and login equate to the same thing in CI but Im not sure.
#3

[eluser]Bart v B[/eluser]
Hmm... is this not a better idea? Wink
Code:
<?php

class Login extends Controller {

    function __construct()
    {
        parent::Controller();
        // just use the name and not the extention ;)
        $this->load->model('login_db');
  
    }
    
    // This is the default action when noting is happen..
    function index()
    {
         //this is the view.
        $this->load->view('login');
    }

    function user()
    {
        // here we want to do something with the model..
        $this->login_db->doSomething();
    }
}
#4

[eluser]number1chump[/eluser]
certainly! anything is a better idea since I basically had no clue about how the syntax had to look like. I am studying yours now to have it sink in my hollow head.

thank you a lot

Al

update 4 minutes later:

so this "__" that you wrote is part of the syntax for the constructor then.

I follow you into how you are loading my Model code, alright, but the question, why do you need to create a construct ? then I see that you load the view alright, and then you create a function where you say, "we want to do something with the model. That leaves it too abstract for me, how do you mean "do something"?

And I still have the query of what do you do when you are creating another project, where do you create it so that you can distribute your MVC files, do you create subfolders inside each of the M and V and C folders ?

thank you gracias
#5

[eluser]Bart v B[/eluser]
[quote author="number1chump" date="1286850826"]certainly! anything is a better idea since I basically had no clue about how the syntax had to look like. I am studying yours now to have it sink in my hollow head.

thank you a lot

Al[/quote]

See my edits Wink
I did make some changes to make it understandeble..
#6

[eluser]adhardy213[/eluser]
@bart that looks cool to me

@number1chump

try this its old but I think it might help

http://codeigniter.com/wiki/Multiple_Applications/
#7

[eluser]number1chump[/eluser]
[quote author="adhardy213" date="1286851090"]@bart that looks cool to me

@number1chump

try this its old but I think it might help

http://codeigniter.com/wiki/Multiple_Applications/[/quote]

thank you! I am reading it right now

_________

Ok I ve read it. They actually talk about multiple applications within one site. That would be less commong.

What I was refering to was to multiple websites, which is something that you are going to be doing all the time.

You are not going to be installing CI every time you create a new website, are you ? so, if your CI is located in the htdocs folder, then, what happens when you have another client who wants another website.

greetings

Al
#8

[eluser]Bart v B[/eluser]
[quote author="number1chump" date="1286850826"]certainly! anything is a better idea since I basically had no clue about how the syntax had to look like. I am studying yours now to have it sink in my hollow head.

thank you a lot

Al

update 4 minutes later:

so this "__" that you wrote is part of the syntax for the constructor then.

I follow you into how you are loading my Model code, alright, but the question, why do you need to create a construct ? then I see that you load the view alright, and then you create a function where you say, "we want to do something with the model. That leaves it too abstract for me, how do you mean "do something"?

And I still have the query of what do you do when you are creating another project, where do you create it so that you can distribute your MVC files, do you create subfolders inside each of the M and V and C folders ?

thank you gracias[/quote]

with the __construct() your model is loaded in the whole Login object.
So when you have more functions say for example, you want to check if the user has admin rights, you can do that in the same model. It's difficult to explain because i am dutch.

doSomething() can be a function that checks that admin rights for you.

When is see the reply above me, i think you are searching more like modules.
I can not find it very quick, but that is also an option what i use a lot.
http://www.pure-intuitie.nl/webshop/ for example, is a module (in development Wink ).
When you drop /webshop/ then it is just a CI with MVC as normal.
#9

[eluser]adhardy213[/eluser]
Yes I would probably do a fresh install of CI everytime I had a new client. Unless I was doing 2 websites for the same client with shared logic.
#10

[eluser]Bart v B[/eluser]
[quote author="adhardy213" date="1286852207"]Yes I would probably do a fresh install of CI everytime I had a new client. Unless I was doing 2 websites for the same client with shared logic.[/quote]

Or just put your codeigniter with your system folder outside the htdocs folder and put it on a safe place else where on your server.. And the application folder inside your htdocs You only need to change a few paths to where you your ci/system is standing Wink




Theme © iAndrew 2016 - Forum software by © MyBB