Portable functions in OOP? |
[eluser]Ludwig Wendzich[/eluser]
Hey all, sorry for double - well technically triple - posting and bumping the thread. I'm working against the clock at the moment and 15 hours is a long time. And I know that a) I'm not paying you guys and b) it's almost Christmas, but I was hoping someone may have come accross this before or understand what it means.. Someone from EllisLabs maybe? I've googled and googled and I can't find out what that error means...
[eluser]tonanbarbarian[/eluser]
it has become rather confusing trying to work out where the problem lies as it is no longer clear what error you are getting and where it is appearing along with the process flow you are trying to use to get there However a thought just came to me I have seen a few instances where people have come across problems be using the same name for some methods as for objects. So strange as it may sound try the following change the login method in the auth_model to something like check_login and of course change all the code that calls it the issue might be that you have a controller class with a method called login, and a model with a method called login. Despite the fact that you are calling $this->auth_model->login() there is issues because of the way CI instanciates models and controllers. Have seen the same issue with people who have methods called "view" and then they try to call $this->load->view and they get unexpected errors or weird things happening if that does not work then turn on the debugging in the config file and put break points in the code and step through it yourself and you should be able to trace the code from index.php all the way to the error and eventually you will find the problem. In most cases I find that is quicker than posting on the forums, particularly if time lines are tight
[eluser]Ludwig Wendzich[/eluser]
I changed the names of the auth_model login() function to check_login() but am getting the same error. I'm not sure how breakpoints would work (though I have turned on debugging to 4, but am getting no new messages), mainly because the script fails to before it's even run. Code: function login() { Right after check_point 1 is echoed, and anything happens the script throws up the error. I don't understand why? Am I not following the MVC model? I'm so sorry, I'm trying to get the hang of CI but it's not quite working out so well.
[eluser]tonanbarbarian[/eluser]
ok after trying to wrap my head around what you are doing I think I might have finally found the problem Code: class Student extends Controller { This shows that you are loading a library called "auth" and in the index method of the controller you are calling "auth->logged_in" to see if the user is logged in or not. But the problem is that the "auth" library that you created is extending the controller object. This is a big NO because of the way the controller object is built at the end of any method it tries to display something so "auth->logged_in" will try to output at the end of it so you will need to create the auth library as something like this Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); I am not sure how accurate the above code in Auth is, but what you WILL need from the code is the Object Constructor which creates a reference to the Controller ($this->CI) so that you can use any of the methods you normally use in the controller. Most libraries that you create should be base classes If you want to extend a base class like Controller, Model or a library like Input, Loader, Session etc then you create a library named MY_whatever i.e. MY_Controller, MY_Model and put those in the library folder as well. CI will then automatically look for those when loading the base class and load the MY_ version of the class as well. You CAN create a library that extends another library without using the MY if you want but the MY is easier So basically make your Auth library into a true library so that it is not extending the controller and things should work better, although you will have to use $this->CI if you want to reference methods that previously existing in the controller, i.e. $this->CI->session->sess_destroy()
[eluser]Ludwig Wendzich[/eluser]
W00t! It works, though I'm not sure what we did. Would you mind explaining how to write a "true" library as I'm sure I'll need this again.. Anyway, now to load the login form or process the login information I call: controller Code: $this->load->model('student/auth_model'); whichever/view/im/loading Code: $this->auth_model->check_login(); I also changed: Code: function check_login($email, $password) { to Code: function check_login($email = null, $password = null) { So I don't get PHP warnings (I think I'm setting default variables...) Anyway, please explain the whole true library thing, thanks ![]() THANKS FOR EVERYTHING ![]()
[eluser]tonanbarbarian[/eluser]
probably best to read the user guide to explain about creating libraries it probably says it better than i can Creating Libraries and not sure if you have but reading the user guide all the way thru really helped me, gave me lots of ideas about how I could do things. Then if i am still having problems understanding things i dive into the core code and work out how and why it is doing things but that is just me...
[eluser]Ludwig Wendzich[/eluser]
I have read the User Guide all the way through, I just don't get a lot of it. Like extending something, what's that mean? And I don't quite get what a class is... I think this is fundamental PHP stuff...and yea, I could go read my PHP books but I find I learn much better when I'm solving a problem like this, I've been working with the code and I figure out what stuff does... I'm not sure what to do because I've read about "class" and I don't get it. Maybe you could explain it in plain 'ol English ![]() Thanks a lot for helping ![]() |
Welcome Guest, Not a member yet? Register Sign In |