CodeIgniter Forums
CI total newbie topic - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: CI total newbie topic (/showthread.php?tid=33458)

Pages: 1 2 3


CI total newbie topic - El Forum - 08-27-2010

[eluser]bretticus[/eluser]
[quote author="keevitaja" date="1282914346"]this code gives me the error while loading the database[/quote]

Gives you what error? Do share, please.


CI total newbie topic - El Forum - 08-28-2010

[eluser]keevitaja[/eluser]
controllers/admin.php
Code:
<?php
class Admin extends Controller {
  function index() {
    echo $this->session->userdata['session_id'];
  }
  
  function login() {
    $this->load->library('simple_auth');
    $this->load->view('login');
  }
}

libraries/simple_auth.php
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Simple_auth {
  function __construct() {
    $this->ci =& get_instance();
    $this->ci->load->library('database');
  }
}

http://localhost/site/index.php/admin/login
Quote:An Error Was Encountered

Unable to load the requested class: database

what am i doing wrong? other libraries, like email, do not give the error!


CI total newbie topic - El Forum - 08-28-2010

[eluser]keevitaja[/eluser]
oops...

Quote:Note: The Database classes can not be extended or replaced with your own classes, nor can the Loader class in PHP 4. All other classes are able to be replaced/extended.

so how can i use database in my own libraries?


edit: think i got it!

i have to use model in order to interact with database inside custom library...


CI total newbie topic - El Forum - 08-28-2010

[eluser]davidbehler[/eluser]
Not necessarily, this should work aswell:
Code:
$this->ci->load->library('database');
$this->ci->db->get('table_name');



CI total newbie topic - El Forum - 08-28-2010

[eluser]keevitaja[/eluser]
how to get the called class if the model is allready extended...

Code:
<?php
class Main_model extends Model {
  function __construct() {
    parent::Model();
    
    echo get_class($this);
  }
}

class Final extends Main_model {
  
}

i need to get the name of the last class 'Final' for some db methods like create, update, delete etc. don't want to write them each time.
in order that to work, i have to autoload main_model but this main model is actually abstract and i call methods from Final


CI total newbie topic - El Forum - 08-28-2010

[eluser]keevitaja[/eluser]
and a question about form_validation. in my login form if the username and/or the password are not validating, then is it possible to display error message like the form_validation works with rules...

RESOLVED


CI total newbie topic - El Forum - 08-29-2010

[eluser]keevitaja[/eluser]
if the form doesn't validate, i can only call a function where form was sent in order to get the error messages. i would like to redirect the page...
Code:
function index() {
//output form
}

function send_data {
redirect(index);
}

in that case i don not get the errors... is it possible to fix it? i like to let people refresh the page without sending the form data again!


CI total newbie topic - El Forum - 08-29-2010

[eluser]keevitaja[/eluser]
can controllers be stored in a subfolder and then call like http://mysite.com/subfolder/controller ?


CI total newbie topic - El Forum - 08-30-2010

[eluser]WanWizard[/eluser]
Yes.

With the restriction that you can't have a folder and a controller with the same name. So if you have:

test1.php
test1/test2.php

then you can never load the test2 controller, as CI looks for a matching controller first, and only for a folder if the controller isn't found.


CI total newbie topic - El Forum - 08-30-2010

[eluser]keevitaja[/eluser]
this is strange. i tested to put controllers in separate folder and it didn't work. now it works... probably made mistake first time