Welcome Guest, Not a member yet? Register   Sign In
Application Root
#1

[eluser]myjeep_2003[/eluser]
NewBie Question...


How can I use something like this in my controller??

require_once("application/users.inc");

DO I add it to Route.php??
#2

[eluser]TheFuzzy0ne[/eluser]
No, you'd just include/require it from within the controller. Routes are for rerouting URIs to controllers.
#3

[eluser]myjeep_2003[/eluser]
So if my

Folder looks like this

/system/application/includes

then

require_once ("includes/users.inc") should do it...

But its not............

What should it be??
#4

[eluser]TheFuzzy0ne[/eluser]
require_once(APPPATH . 'includes/users.inc');

APPPATH contains the path to your application directory.
#5

[eluser]Colin Williams[/eluser]
FuzzyOne's solution is best, but just keep in mind that when you're in a controller, the current working directory is system/application/controllers, so you need to resolve your path from there.

Also, I don't know the nature of your users.inc file, but it might make sense to use it like a library or helper, then you can use CI's loader class and benefit from the built-in conventions
#6

[eluser]myjeep_2003[/eluser]
Thanks guys but I was wondering where you set the APPPATH??

I looked at index.php at the root and my application folder

$application_folder = "application";

So I did not changed anything...

Under application I have /includes

So I am trying to call includes/users.inc

by require_once(APPPATH . 'includes/users.inc');

Unfortunately is not getting called..
#7

[eluser]TheFuzzy0ne[/eluser]
APPPATH is automatically set at the beginning of the "non-editable" stuff, in the index.php. So long as your system directory path, and application directory path are set, CodeIgniter will take care of the rest.

Are you getting any kind of error? If it's a required file and it's not available, you should see an error, unless your suppressed errors, in which case, please re-enable them.
#8

[eluser]myjeep_2003[/eluser]
error is as follows..........



A PHP Error was encountered

Severity: Warning

Message: include_once(../../includes/users.conf) [function.include-once]: failed to open stream: No such file or directory

Filename: includes/users.inc

Line Number: 21
#9

[eluser]Colin Williams[/eluser]
That means the error is in your users.inc file, not your controller anymore. If users.conf is in the same includes folder, then you should just do include_once('users.conf');

And I can't help but think you're going down the wrong path here. CI already has conventions in place for what you seem to be doing: The Config class and Libraries.

Code:
// ./system/application/libraries/Users.php

class Users {

  function Users($props = array())
  {
     // $props comes from $config array in ./system/application/config/users.php automagically
  }

}
#10

[eluser]TheFuzzy0ne[/eluser]
I second that. Loading the script as a library makes much more sense.




Theme © iAndrew 2016 - Forum software by © MyBB