Welcome Guest, Not a member yet? Register   Sign In
Where to put certain code
#1

[eluser]jaswinder_rana[/eluser]
Hi:

I have just downloaded CodeIgniter. I am not sure about where to place certain code.

I have started my own application. My first part is to build authentication system. I have the tables and logic planned out. I have already done many authentication system but I wanted to do it with CodeIgniter this time.

I have few questions:

- Where do I place code for login
- Where do I place code for checking login for users


Some different topics are:
- If I have a header view, do I need to include it in every Controller? Or is there a way to automatically include it in every controller?
- If I have sidebars, and some content might be page specific and some application wide. What is the best way to deal with them? Call Models in every controller?


As you can see, it's overwhelmed me a little.

I know (and am reading) CodeIgniter manual. But, are there some sample applications, say a sample blog system or something, that I can look at and see how they do things?

Oh and totally off topic question, is there plan to write PHP5 only CodeIgniter?

Please help.

Thanks
#2

[eluser]Mossab Alzeeny[/eluser]
[quote author="jaswinder_rana" date="1229209507"]Hi:

I have just downloaded CodeIgniter. I am not sure about where to place certain code.
well, Welcome to CI world,
useally your php code will be in the controller (never use html codes there, put all htmls in the view file


I have started my own application. My first part is to build authentication system. I have the tables and logic planned out. I have already done many authentication system but I wanted to do it with CodeIgniter this time.

I have few questions:

- Where do I place code for login
- Where do I place code for checking login for users
hmmm what you think if you take a look at the DX_auth library ? it's totally AMAZING, and as the author says, it's Very well documented,

Some different topics are:
- If I have a header view, do I need to include it in every Controller? Or is there a way to automatically include it in every controller?
yes, you will have to include the view file everytime in your Controllers

- If I have sidebars, and some content might be page specific and some application wide. What is the best way to deal with them? Call Models in every controller?
yeah i think, Smile or maybe i didn't get the question..

As you can see, it's overwhelmed me a little.

I know (and am reading) CodeIgniter manual. But, are there some sample applications, say a sample blog system or something, that I can look at and see how they do things?
ofc Smile CI Tutorials

Oh and totally off topic question, is there plan to write PHP5 only CodeIgniter?
no idea, i hope NO, there still some ppl loves PHP4[/quote]
#3

[eluser]jaswinder_rana[/eluser]
Thanks Mossab.

That DX_auth project is really good. It was breeze to set it up.
One quick question. It says that DX_auth is based on CL Auth. CL Auth has just released a new version. if you (or anyone) has tested it then is it better to go with DX_auth or CL Auth (http://www.jasonashdown.co.uk/cl_auth_do...nshots.php)??

------------------

About the sidebars. Say, I have left side bar. On the top, I want to display user specific links ((if logged in) like My account, or something like that. Below that I want to print a list of, say, 5 latest blog entries by ANYONE.

I am not sure how to proceed here. I just can't understand it logically. I went through both video tutorials on this site and one at http://video.derekallard.com/videoplay. None of them go through the logic or sidebars.

I know its simple (for you guys) but I am having trouble understanding it.

- How do I place code for sidebars?
- Will it go in headers?
- If in header then how do I pass data to it? (Header (including left bar), body, footer (including right bar))

As you can see I have confused myself unnecessarily. Please help

THanks
-
#4

[eluser]jaswinder_rana[/eluser]
I also found few bugs with DX_auth. I couldn't find any contact information so not sure who to talk to.

That's why I am asking about CL Auth because it seems that CL Auth has more suuport
#5

[eluser]Mossab Alzeeny[/eluser]
Well, since the last change on CL auth was at 17/08/2008, and dx_auth was published on 01/12/2008 i think you will get everything that was in Cl auth,

about the sidebar, if you're using DX_auth ( and i really encourage you to ) then the "if logged" thing should be just ,, piece of cake,
in your view file put :

Code:
<?  if ($this->dx_auth->is_logged_in()){ ?>
you Are logged (full html code here)
<? }else{ ?>
click here to login (full html code here)
<? } ?>

, as for the sidebar, if i was you i would put it in the same template with header, or maybe with footer ( depends on your knowledge with HTML )

and if you want to pass data to a view file, thats so easy, :
go here read the whole thing about loading a view file
and exactly, "Loading multiple views" section
example for the code :
Code:
<?

$data['welcome'] = 'Welcome to my website';

$this->load->view('header');

?>

and in your view file you will print this as a variable, not from the $data array, example:
<p>$welcome</p>


im not sure if thats what you really meant, but im sure you got the point,


Regards.
Mossab
#6

[eluser]jaswinder_rana[/eluser]
Thanks Mossab.

Yes, I have installed DX_Auth and have started using it as it has everything I need. Only thing I'll need to change will be User Profile. So, I thank for suggesting this.

Yes, I did mean exactly what you said about views. I was wondering about multiple items on sidebars. So, as I understand it, I'll have to pass it data for each item on the sidebar in each controller.

I have read on views and have seen how multiple views can be loaded.

I was hoping that there is a global class where I can initialize global data that will be available throughout the application. Like it will set all the data for header, sidebars and footers as that will be common (for specific data i'll do it in specific controller). But, I think that won't be good application design or will it?

I can always change Main Controller constructor and do it there but is that good idea?

Thanks
#7

[eluser]Mossab Alzeeny[/eluser]
Well, maybe you can auto-load a library that contains the data you want to pass ? then you will be able to use it in every view file you make, without loading the library manually in the Constructor,
#8

[eluser]jaswinder_rana[/eluser]
AH. A simple answer. Thanks. Din't think of that. Still new to CI architecture. Much appreciated.

Thanks
#9

[eluser]Mossab Alzeeny[/eluser]
my pleasure, well as i always say, if there's no Step 1, there will be no Step 2, right ? so it's only matter of time for all of us to get tot he next step,

P.S: i just started using CI a month ago, and everyday it proves that this is the right framework Smile

<3 CI Big Grin
#10

[eluser]jaswinder_rana[/eluser]
I agree. In 2 days I have full framework and authentication API. I am that fast. Smile Big Grin hehe




Theme © iAndrew 2016 - Forum software by © MyBB