divers
This commit is contained in:
@@ -132,4 +132,4 @@ $autoload['language'] = array();
|
|||||||
|
|
|
|
||||||
| $autoload['model'] = array('first_model' => 'first');
|
| $autoload['model'] = array('first_model' => 'first');
|
||||||
*/
|
*/
|
||||||
$autoload['model'] = ['beheer/User'];
|
$autoload['model'] = ['beheer/User_model'];
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ $config['charset'] = 'UTF-8';
|
|||||||
| setting this variable to TRUE (boolean). See the user guide for details.
|
| setting this variable to TRUE (boolean). See the user guide for details.
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
$config['enable_hooks'] = FALSE;
|
$config['enable_hooks'] = TRUE;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -11,3 +11,13 @@ defined('BASEPATH') OR exit('No direct script access allowed');
|
|||||||
| https://codeigniter.com/user_guide/general/hooks.html
|
| https://codeigniter.com/user_guide/general/hooks.html
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
$hook['post_controller_constructor'][] = [
|
||||||
|
'class' => 'EloquentHook',
|
||||||
|
'function' => 'bootEloquent',
|
||||||
|
'filename' => 'EloquentHook.php',
|
||||||
|
'filepath' => 'hooks'
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class Login extends MY_Controller {
|
|||||||
$username = $this->clean_input( 'username' );
|
$username = $this->clean_input( 'username' );
|
||||||
$password = $this->clean_input( 'password' );
|
$password = $this->clean_input( 'password' );
|
||||||
|
|
||||||
$user = $this->User->getUserByUsername( $username );
|
$user = $this->User_model->getUserByUsername( $username );
|
||||||
|
|
||||||
if ( ! $user ) return $this->json( FALSE );
|
if ( ! $user ) return $this->json( FALSE );
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,11 @@ class Main extends MY_Controller {
|
|||||||
{
|
{
|
||||||
if( AUTHENTICATED == FALSE ) return $this->showLoginPage();
|
if( AUTHENTICATED == FALSE ) return $this->showLoginPage();
|
||||||
|
|
||||||
$this->load->view('main_view');
|
$pages = Page::getPages();
|
||||||
|
|
||||||
|
$this->json($pages->toArray());
|
||||||
|
|
||||||
|
//$this->load->view('main_view');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function showLoginPage()
|
private function showLoginPage()
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||||
|
|
||||||
|
class EloquentHook {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holds the instance
|
||||||
|
* @var object
|
||||||
|
*/
|
||||||
|
protected $instance;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets CI instance
|
||||||
|
*/
|
||||||
|
private function setInstance() {
|
||||||
|
$this->instance =& get_instance();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads database
|
||||||
|
*/
|
||||||
|
private function loadDatabase() {
|
||||||
|
$this->instance->load->database();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the instance of the db
|
||||||
|
* @return object
|
||||||
|
*/
|
||||||
|
private function getDB() {
|
||||||
|
return $this->instance->db;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function bootEloquent() {
|
||||||
|
|
||||||
|
$this->setInstance();
|
||||||
|
|
||||||
|
$this->loadDatabase();
|
||||||
|
|
||||||
|
$config = $this->getDB();
|
||||||
|
|
||||||
|
$capsule = new Capsule;
|
||||||
|
|
||||||
|
$capsule->addConnection([
|
||||||
|
'driver' => 'mysql',
|
||||||
|
'host' => $config->hostname,
|
||||||
|
'database' => $config->database,
|
||||||
|
'username' => $config->username,
|
||||||
|
'password' => $config->password,
|
||||||
|
'charset' => $config->char_set,
|
||||||
|
'collation' => $config->dbcollat,
|
||||||
|
'prefix' => $config->dbprefix,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$capsule->setAsGlobal();
|
||||||
|
$capsule->bootEloquent();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
* Time: 19:37
|
* Time: 19:37
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class User extends MY_Model {
|
class User_model extends MY_Model {
|
||||||
|
|
||||||
protected $tablename = "users";
|
protected $tablename = "users";
|
||||||
|
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by Pensare Software.
|
||||||
|
* User: Theo Weijmer
|
||||||
|
* Date: 21/12/2017
|
||||||
|
* Time: 18:05
|
||||||
|
*/
|
||||||
|
|
||||||
|
use \Illuminate\Database\Eloquent\Model as Eloquent;
|
||||||
|
|
||||||
|
class Page extends Eloquent {
|
||||||
|
|
||||||
|
protected $table = "pages";
|
||||||
|
|
||||||
|
public function subpages()
|
||||||
|
{
|
||||||
|
return $this->hasMany( 'Page' );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static function getPages()
|
||||||
|
{
|
||||||
|
$pages = Page::whereRaw( 'id = page_id' )
|
||||||
|
->with( 'subpages' )
|
||||||
|
->get();
|
||||||
|
|
||||||
|
return $pages;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by Pensare Software.
|
||||||
|
* User: Theo Weijmer
|
||||||
|
* Date: 21/12/2017
|
||||||
|
* Time: 18:04
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
use \Illuminate\Database\Eloquent\Model as Eloquent;
|
||||||
|
|
||||||
|
class User extends Eloquent {
|
||||||
|
|
||||||
|
protected $table = "users";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+7
-1
@@ -12,7 +12,13 @@
|
|||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.3.7",
|
"php": ">=5.3.7",
|
||||||
"vlucas/phpdotenv": "^2.4"
|
"vlucas/phpdotenv": "^2.4",
|
||||||
|
"illuminate/database": "5.1.16"
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"classmap": [
|
||||||
|
"application/models/eloquent"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"suggest": {
|
"suggest": {
|
||||||
"paragonie/random_compat": "Provides better randomness in PHP 5.x"
|
"paragonie/random_compat": "Provides better randomness in PHP 5.x"
|
||||||
|
|||||||
Reference in New Issue
Block a user