CodeIgniter create a layout/template library - php

Before I begin I have to say that I have recently started learning CodeIgniter, so I'm sorry if I repeat this subject once again.
In procedural php I would do something like this
// the header.php
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="blah blah">
<title>My Site</title>
<link href="css/main.css" rel="stylesheet" media="screen">
<php? if($current_page == 'about.php'): ?>
<link href="css/secondary.css" rel="stylesheet" media="screen"> // or some embed styles (<stlye> ... </style>)
<?php endif; ?>
<script src="http://code.jquery.com/jquery.js"></script>
<script src="js/main_script.js"></script>
<php? if($current_page == 'contact.php'): ?>
<script src="js/validation.js"></script>
<?php endif; ?>
</head>
<body>
// end of header.php
include('template/header.php');
<h1>Heading1</h1>
<p>Lorem Ipsum...</p>
include('template/footer.php');
//footer.php
//maybe some js and here
</body>
</html>
So I would like to do something similar and in CI. All pages/views will have the same main styles or scripts, but in some cases, some specific pages (like contact.php) may include, and only in these pages, some specific styles or scripts (like the validation.js).
I have found this video that shows how to create a template/layout library using CI, but I'm not quite sure how I can apply this functionality to work properly.

Put the bottom class in libraries/Layout.php (your app not the sys). In the autoload add the library:
$autoload['libraries'] = array('layout');
In your controller just write $this->layout->render();
The class will render the layout views/layouts/default.php and the view views/$controller.views/$method.php
In the default layout just put
<?php $this->load->view($view,$data); ?>
and thats it.
The code is
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Layout
{
public $data = array();
public $view = null;
public $viewFolder = null;
public $layoutsFodler = 'layouts';
public $layout = 'default';
var $obj;
function __construct()
{
$this->obj =& get_instance();
}
function setLayout($layout)
{
$this->layout = $layout;
}
function setLayoutFolder($layoutFolder)
{
$this->layoutsFodler = $layoutFolder;
}
function render()
{
$controller = $this->obj->router->fetch_class();
$method = $this->obj->router->fetch_method();
$viewFolder = !($this->viewFolder) ? $controller.'.views' : $this->viewFolder . '.views';
$view = !($this->view) ? $method : $this->view;
$loadedData = array();
$loadedData['view'] = $viewFolder.'/'.$view;
$loadedData['data'] = $this->data;
$layoutPath = '/'.$this->layoutsFodler.'/'.$this->layout;
$this->obj->load->view($layoutPath, $loadedData);
}
}
?>

I'm doing layout thing is like bellow.
I get content to data['content'] variable.
This is my controller.
class Article extends MY_Controller {
function __construct() {
parent::__construct();
$this->load->model('article_model');
}
public function index() {
$data['allArticles'] = $this->article_model->getAll();
$data['content'] = $this->load->view('article', $data, true);
$this->load->view('layout', $data);
}
This is my Layout.I'm using bootstrap layout.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Starter Template for Bootstrap</title>
<base href="<?php echo base_url(); ?>" />
<!-- Bootstrap core CSS -->
<link href="assets/bootstrap3.0.1/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<!-- <link href="starter-template.css" rel="stylesheet">-->
<!-- Just for debugging purposes. Don't actually copy this line! -->
<!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#"> Article Management System</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#"> Admin <span class="caret"></span></a>
<ul class="dropdown-menu">
<li>Add Article</li>
<li>All Article</li>
</ul>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
<div class="container" style="margin-top: 80px;">
<?php echo $content; ?>
</div><!-- /.container -->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="assets/bootstrap3.0.1/js/bootstrap.min.js"></script>
</body>
</html>
This is my content view
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="page-header">
<h4>All Articles </h4>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Title</th>
<th>Description</th>
<th></th>
</tr>
</thead>
<tbody>
<?php foreach ($allArticles as $row) { ?>
<tr>
<td><?php echo $row->title; ?></td>
<td><?php echo substr($row->description,0,100); ?> ....</td>
<td></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>

I have achieved the same thing with the following:
Put this code in your ./application/core/MY_Controller.php file:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Controller extends CI_Controller
{
protected $layout = 'layout/main';
public function __construct()
{
parent::__construct();
}
protected function render($file = NULL, &$viewData = array(), $layoutData = array())
{
if( !is_null($file) ) {
$data['content'] = $this->load->view($file, $viewData, TRUE);
$data['layout'] = $layoutData;
$this->load->view($this->layout, $data);
} else {
$this->load->view($this->layout, $viewData);
}
$viewData = array();
}
}
Create a layout folder inside ./application/views directory and then create your files with the entire html in it. Just put the <?php echo $content; ?> in that file where you want to put the dynamic content in it. Then in your controllers use $this->render(); and pass your file path and data. If you want to use a different layout for specific page just put the $this->layout = 'path_to_your_layout_file'; it will override the layout file to be used.

I have struggled with a similar problem not long ago. My solution to it was the following :
In your controller constructor create 2 arrays one of css files and one of js files and put in them the files common to all views.
And in each function in the controller add to them logic specific files.
For your example you'll have something like this :
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Home extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->page_data = array();
$this->page_data['css']=array('main.css','bootstrap.css');
$this->page_data['js']=array('main.js','bootstrap.js');
}
public function about()
{
array_push($this->page_data['css'],'secondary.css');
$this->load->view('main_layout',$this->page_data)
}
public function contact()
{}
}
And in your view file you'll just iterate over the $css and $js array and include them one by one.
You can extend that easily to include header and footer templates by pushing them into the page_data array.
I ended up switching to doing all the templating on the client-side with Backbone and using Code Igniter as a REST API only but this technique gave me relatively clean code for what I needed.

5 Simple Steps to create CodeIgniter Template:
Step #1
Template.php # libraries
Step #2
Write following code
/* Start of file Template.php */
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Template {
var $template_data = array();
function set($name, $value)
{
$this->template_data[$name] = $value;
}
function load($template = '', $view = '' , $view_data = array(), $return = FALSE)
{
$this->CI =& get_instance();
$this->set('contents', $this->CI->load->view($view, $view_data, TRUE));
return $this->CI->load->view($template, $this->template_data, $return);
}
}
/* End of file Template.php */
/* Location: ./system/application/libraries/Template.php */
Step #3
open config/autoload.php
at line 55 replace
$autoload['libraries'] = array('database', 'session','encrypt');
with this code
$autoload['libraries'] = array('database', 'session','encrypt', 'template');
Step #4
On my controller call template as
//start
$this->template->load(TEMPLATE_NAME, VIEW_NAME , $this->data);
//end
Step #5
On views
create a file as custom_template.php
And place there following code--
//start
<?php $this->load->view('elements/header'); ?>
<div><?php echo $contents;?></div>
<?php $this->load->view('elements/footer'); ?>
//end
N.B. In views in elements folder create two files as header.php And footer.php

I use this, in older version of CodeIgniter and it works for version 3 as well.
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Layout
{
var $obj;
var $layout;
function Layout($layout = "layout_main")
{
$this->obj =& get_instance();
$this->layout = $layout;
}
function setLayout($layout)
{
$this->layout = $layout;
}
function view($view, $data=null, $return=false)
{
$loadedData = array();
$loadedData['content_for_layout'] = $this->obj->load->view($view,$data,true);
if($return)
{
$output = $this->obj->load->view($this->layout, $loadedData, true);
return $output;
}
else
{
$this->obj->load->view($this->layout, $loadedData, false);
}
}
}
?>
and to call this in the controller I use:
$this->layout->view('apps/apps', $data);

Related

Generate Web Page Using PHP Class

I am a university student experimenting with OOP and PHP. I was wanting to build up a page using a BuildPage class.
<?php
Class BuildPage {
private $title;
private $style;
private $head;
private $header;
private $page;
private $footer;
private $finalPage;
public function __construct($title, $style)
{
$this->title = $title;
$this->style = $style;
}
public function addHead()
{
$this->head = "
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='utf-8'>
<title>$this->title</title>
<link href='$this->style' rel='stylesheet' type='text/css'>
<link rel='stylesheet' href='style.css'>
</head>";
}
public function addToPage($partOfPage)
{
if(empty($this->page) || !isset($this->page))
{
$this->page = $partOfPage;
}
else {
$this->page .= "<br> " . $partOfPage;
}
}
public function addHeader($header)
{
$this->header = "<body><div class='container'><header> " . $header . "
</header>";
}
public function addFooter($footer)
{
$this->footer .= "<BR><footer> " . $footer . " </footer></div></body>
</html>";
}
public function getPage()
{
$this->finalPage = $this->head . $this->header . $this->page .
$this->footer;
return $this->finalPage;
}
}
?>
However, when I try to build the page using the functions, I cannot understand how to use PHP within the argument as below:
$buildPage->addToPage("
<!-- Here is our page's main content -->
<!-- Use function to display songs -->
<?php $music->displaySongs('xmlfiles/songs.xml'); ?>
");
If I escape the $ like \$ to try and make it a string, for some reason the becomes a comment in HTML. Is it possible for this approach to work at all?
Many Thanks
EDIT:
This is the index page below, i call the class at the bottom with an echo.
<?php
require_once('phpclasses/Connect.php');
require_once('phpclasses/BuildPage.php');
require_once('phpclasses/MusicIE.php');
$dbconnect = new Connect();
$music = new MusicIE();
$buildPage = new BuildPage("Music Website", "style.css");
$buildPage->addHead();
$buildPage->addHeader("
<!-- Here is the main header that is used accross all the pages of my
website
-->
<div class='PageHeading'>Available Music Listed Below:</div>
<nav>
<ul>
<li><a href='#'>Home</a></li>
<li><a href='#'>Register</a></li>
<li><a href='#'>Login</a></li>
</ul>
</nav>
<form>
<input type='search' name='q' placeholder='Search query'>
<input type='submit' value='Go!'>
</form>
");
$buildPage->addToPage("
<!-- Here is our page's main content -->
<!-- Use function to display songs -->
" . $music->displaySongs('xmlfiles/songs.xml'));
$buildPage->addFooter("
<!-- And here is my footer that is used across all the pages of our website
-->
<p>©Copyright 2017 by Kris Wilson. All rights reversed.</p>
");
echo $buildPage->getPage();
?>
Since you are passing a string to the function BuildPage::addToPage($partOfPage) you could try to pass the result of $music->displaySongs('xmlfiles/songs.xml') instead of the literal function call as a string. Like so:
$buildPage->addToPage("
<!-- Here is our page's main content -->
<!-- Use function to display songs -->
". $music->displaySongs('xmlfiles/songs.xml'));
Seems that your code is wrong on the addToPage function call. you should call it like this:
$buildPage->addToPage("
<!-- Here is our page's main content -->
<!-- Use function to display songs -->
".$music->displaySongs('xmlfiles/songs.xml'));
You should add the $music->displaySongs('xmlfiles/songs.xml') output to the end of the string.

Codeigniter login with facebook nothing happens

I want to create a login with Facebook in my website. I found a code in the internet that made it simple loading the library of Facebook php sdk. I tried the code but it doesn't work in me. Please help me how to do login with facebook in codeigniter.
Here is the code :
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once( APPPATH . 'libraries/facebook/src/facebook.php' );
class FacebookApp extends Facebook {
var $ci;
var $facebook;
var $scope;
public function __construct() {
$this->ci =& get_instance();
$this->facebook = new Facebook(array('appId' => $this->ci->config->item('app_id'),'secret' => $this->ci->config->item('app_secret'), 'cookie' => true));
$this->scope = 'public_profile';
}
public function login_url() {
$params = array('scope' => $this->scope);
return $this->facebook->getLoginUrl($params);
}
public function logout_url() {
return $this->facebook->getLogoutUrl(array('next' => base_url() .'logout'));
}
public function getFbObj(){
return $this->facebook;
}
public function get_user() {
$data = array();
$data['fb_user'] = $this->facebook->getUser();
if ($data['fb_user']) {
try {
$data['fb_user_profile'] = $this->facebook->api('/me');
return $data;
} catch (FacebookApiException $e) {
$this->facebook->destroySession();
$fb_login_url = $this->facebook->getLoginUrl(array('scope' => $this->scope));
redirect($fb_login_url, 'refresh');
}
}
}
here is my controller :
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class User_Authentication extends CI_Controller
{
function __construct() {
parent::__construct();
// Load user model
$this->load->model('auth/user_model');
$this->load->library('facebook/FacebookApp');
}
public function index(){
$obj_fb = new FacebookApp();
$fb_user_data = $obj_fb->get_user();
$data['fb_login_url'] = $obj_fb->login_url();
}
}
and here is my view:
<div class="modal fade" id="choose" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header btn-success">
<h3 class="modal-title">Connect with</h3>
</div><!-- modal-header -->
<div class="modal-body">
<div class="connectwith">
<form class="form-horizontal" id="payment">
<button onclick="<?php echo base_url()?>User_authentication" class="btn btn-primary"> Continue with Facebook </button>
</form><!-- form-horizontal -->
</div>
</div><!-- modal-body -->
</div><!-- modal-content -->
</div><!-- modal-dialog -->
</div><!-- choose -->
it shows no error when i check it on my console, i don't know what's happen, i am a beginner in adding libraries. Please help me with this. Thanks
First of all load url helper so you can use base_url().Load helper in controller...
function __construct() {
parent::__construct();
//Load Helper
$this->load->helper('url');
// Load user model
$this->load->model('auth/user_model');
$this->load->library('facebook/FacebookApp');
}
In your view replace
onclick="<?php echo base_url()?>User_authentication"
To
onclick="<?php echo base_url('user_authentication');?>"
Use this github https://github.com/bhawnam193/php-programs/tree/master/facebook-login for using fb login .
Firstly make a facebook app and replace the
$app_id ,$app_secret, $site_url
in file fbaccess.php.

Laravel - Load common header and footer to view

I am new to Laravel and I am trying to load header, footer and the view file from controller in a common template and display the data from controller in the view file. But I get error
View ['admin.dashboard'] not found.
The dashboard file is present in the admin folder inside views.
Controller
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class common extends Controller
{
public function login()
{
$data['title'] = 'Dashboard';
$data['template'] = 'admin/dashboard';
return view('common_template', compact('data'));
}
}
common_template.blade View
<?php echo View::make('includes/header'); ?>
<?php echo $template = "'".$data['template']."'";
echo View::make($template); ?>
<?php echo View::make('includes/footer'); ?>
When I add 'admin/dashboard' instead of $data['template'] directly in $template, it loads the dashboard file whereas it doesn’t load when i pass it as string from controller.
dashboard.blade view
<p><?php echo $data['title']; ?></p> // Printing the data from the controller
To include a Blade template into another template, use #include:
#include('admin.dashboard')
Or
#include($data['template']) // This should be the name of template, like 'admin.dashboard', but not path
Also, check if the view has the correct name and is in the right directory:
resources/views/admin/dashboard.blade.php
First of all, your code requires correction as per the Laravel Blade code standard. Try the below code:
common_template.blade View
#include('includes.header')
#yield('content')
#include('includes.footer')
dashboard.blade view
#extends('common_template')
#section('content')
{{$data['title']}}
#endsection
To include a Blade template into another template,
layouts/index.blade.php
<!DOCTYPE html>
<html lang="en" class="no-js">
<head>
<!-- Site Title -->
<title>{{ $title }}</title> // Dynamic title
<link rel="stylesheet" href="{{ asset('website/css/main.css') }}">
#stack('css') // Internal CSS
</head>
<body>
#include('../website/layouts/header') // Include header
#yield('content') // Include content
#include('../website/layouts/footer') // Include footer
<!-- Start footer Area -->
<!-- End footer Area -->
<script src="{{asset('website/js/vendor/jquery-2.2.4.min.js ') }}"></script>
#stack('js') // Internal js
</body>
</html>
layouts/footer.blade.php
// Footer code
<h1>This area for footer code
layouts/header.blade.php
// Header code
<h1>This area for headercode
/home.blade.php
<?php $title = "dynamic title"; ?> // Title
#extends('layouts/index') // Include index page
#Push('css') // This is for internal js
*{
color: black;
}
#endpush
#section('content') // Section for content
This area for home page content
#stop // Content ended
#Push('js') // This is for internal js
<script>
$(document).ready(function() {
var loggedIn = {!! json_encode(Auth::check()) !!};
$('.send').click(function() {
if(!loggedIn) {
moda.style.display = "block";
return false;
}
});
});
#endpush

Code Iginiter Error 'The address wasn't understood'

i' newbie code iginiter 3 with mysql database, and xampp v3.2 .
Error 'The address wasn't understood' when i click login button.
help me ...
this config
<code>`enter code here`
$config['base_url'] = 'localhost:8087/hris/';
$config['index_page'] = 'login.php';
</code>
and my route.php
<code>
$route['default_controller'] = 'user_authentication';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
</code>
how to fix this error....
user_authentication.php
Class User_Authentication extends CI_Controller
{
//session_start(); //we need to start session in order to access it through CI
public function __construct()
{
parent::__construct();
// Load form helper library
$this->load->helper('form');
// Load form validation library
$this->load->library('form_validation');
// Load session library
$this->load->library('session');
// Load database
$this->load->model('login_database');
}
// Show login page
public function index()
{
$this->load->view('login');
}
// Show registration page
public function user_registration_show()
{
$this->load->view('registration_form');
}
// Validate and store registration data in database
public function new_user_registration()
{
// Check validation for user input in SignUp form
$this->form_validation->set_rules('username', 'Username','trim|required|xss_clean');
$this->form_validation->set_rules('email_value', 'Email', 'trim|required|xss_clean');
$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('registration_form');
} else
{
$data = array(
'user_name' => $this->input->post('UserID'),
'user_email' => $this->input->post('email_value'),
'user_password' => $this->input->post('password')
);
$result = $this->login_database->registration_insert($data);
if ($result == TRUE)
{
$data['message_display'] = 'Registration Successfully !';
$this->load->view('login_form', $data);
} else {
$data['message_display'] = 'Username already exist!';
$this->load->view('registration_form', $data);
}
}
}
// Check for user login process
public function user_login_process()
{
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');
if ($this->form_validation->run() == FALSE)
{
if(isset($this->session->userdata['logged_in']))
{
$this->load->view('admin_page');
}else{
$this->load->view('login_form');
}
} else {
$data = array(
'username' => $this->input->post('username'),
'password' => $this->input->post('password')
);
$result = $this->login_database->login($data);
if ($result == TRUE)
{
$username = $this->input->post('username');
$result = $this->login_database->read_user_information($username);
if ($result != false)
{
$session_data = array(
'username' => $result[0]->user_name,
'email' => $result[0]->user_email,
);
// Add user data in session
$this->session->set_userdata('logged_in', $session_data);
$this->load->view('admin_page');
}
} else {
$data = array(
'error_message' => 'Invalid Username or Password'
);
$this->load->view('login_form', $data);
}
}
}
// Logout from admin page
public function logout()
{
// Removing session data
$sess_array = array(
'username' => ''
);
$this->session->unset_userdata('logged_in', $sess_array);
$data['message_display'] = 'Successfully Logout';
$this->load->view('login_form', $data);
}
}
?>
this models login_database.php
Class Login_Database extends CI_Model
{
// Insert registration data in database
public function registration_insert($data)
{
// Query to check whether username already exist or not
$condition = "user_name =" . "'" . $data['user_name'] . "'";
$this->db->select('*');
$this->db->from('user_login');
$this->db->where($condition);
$this->db->limit(1);
$query = $this->db->get();
if ($query->num_rows() == 0)
{
// Query to insert data in database
$this->db->insert('user_login', $data);
if ($this->db->affected_rows() > 0)
{
return true;
}
} else {
return false;
}
}
// Read data using username and password
public function login($data)
{
$condition = "user_name =" . "'" . $data['username'] . "' AND " . "user_password =" . "'" . $data['password'] . "'";
$this->db->select('*');
$this->db->from('user_login');
$this->db->where($condition);
$this->db->limit(1);
$query = $this->db->get();
if ($query->num_rows() == 1) {
return true;
} else {
return false;
}
}
// Read data from database to show data in admin page
public function read_user_information($username) {
$condition = "user_name =" . "'" . $username . "'";
$this->db->select('*');
$this->db->from('user_login');
$this->db->where($condition);
$this->db->limit(1);
$query = $this->db->get();
if ($query->num_rows() == 1) {
return $query->result();
} else {
return false;
}
}
}
this view ( login.php )
$this->load->helper('form');
if (isset($this->session->userdata['logged_in'])) {
header("location: http://localhost/login/index.php/user_authentication/user_login_process");
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Global stylesheets -->
<link href="https://fonts.googleapis.com/css?family=Roboto:400,300,100,500,700,900" rel="stylesheet" type="text/css">
<link href="assets/css/icons/icomoon/styles.css" rel="stylesheet" type="text/css">
<link href="assets/css/minified/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="assets/css/minified/core.min.css" rel="stylesheet" type="text/css">
<link href="assets/css/minified/components.min.css" rel="stylesheet" type="text/css">
<link href="assets/css/minified/colors.min.css" rel="stylesheet" type="text/css">
<!-- /global stylesheets -->
<!-- Core JS files -->
<script type="text/javascript" src="assets/js/plugins/loaders/pace.min.js"></script>
<script type="text/javascript" src="assets/js/core/libraries/jquery.min.js"></script>
<script type="text/javascript" src="assets/js/core/libraries/bootstrap.min.js"></script>
<script type="text/javascript" src="assets/js/plugins/loaders/blockui.min.js"></script>
<!-- /core JS files -->
<!-- Theme JS files -->
<script type="text/javascript" src="assets/js/plugins/forms/styling/uniform.min.js"></script>
<script type="text/javascript" src="assets/js/core/app.js"></script>
<script type="text/javascript" src="assets/js/pages/login.js"></script>
<!-- /theme JS files -->
</head>
<body>
<!-- Main navbar -->
<div class="navbar navbar-inverse">
<div class="navbar-header">
<a class="navbar-brand" href="index.html"><img src="assets/images/logo_light.png" alt=""></a>
<ul class="nav navbar-nav pull-right visible-xs-block">
<li><a data-toggle="collapse" data-target="#navbar-mobile"><i class="icon-tree5"></i></a></li>
</ul>
</div>
</div>
<!-- /main navbar -->
<!-- Page container -->
<div class="page-container login-container">
<!-- Page content -->
<div class="page-content">
<!-- Main content -->
<div class="content-wrapper">
<!-- Content area -->
<div class="content">
<?php
echo form_open('user_authentication/user_login_process');
?>
<!-- Advanced login -->
<form action="" method="post">
<div class="panel panel-body login-form">
<div class="text-center">
<div class="icon-object border-slate-300 text-slate-300"><i class="icon-reading"></i></div>
<h5 class="content-group">Login to your account <small class="display-block">Your credentials</small></h5>
</div>
<div class="form-group has-feedback has-feedback-left">
<input type="text" class="form-control" placeholder="Username" name="userid" id="userid" required>
<div class="form-control-feedback">
<i class="icon-user text-muted"></i>
</div>
</div>
<div class="form-group has-feedback has-feedback-left">
<input type="text" class="form-control" placeholder="Password" name="pass" id="pass" required>
<div class="form-control-feedback">
<i class="icon-lock2 text-muted"></i>
</div>
</div>
<div class="form-group login-options">
<div class="row">
<div class="col-sm-6">
<label class="checkbox-inline">
<input type="checkbox" class="styled" checked="checked">
Remember
</label>
</div>
<div class="col-sm-6 text-right">
Forgot password?
</div>
</div>
</div>
<div class="form-group">
<button type="submit" class="btn bg-blue btn-block">Login <i class="icon-arrow-right14 position-right"></i></button>
</div>
<?php echo form_close(); ?>
<div class="content-divider text-muted form-group"><span>Don't have an account?</span></div>
Sign up
</div>
</form>
<!-- /advanced login -->
</div>
<!-- /content area -->
</div>
<!-- /main content -->
</div>
<!-- /page content -->
</div>
<!-- /page container -->
</body>
</html>
</pre></code>
try to change your form open in to this
<?php
echo form_open(base_url('User_Authentication/user_login_process'));
?>
For anyone who face the problem of The address wasn't understood when clicking a link for example, just make sure to add http:// to the $config['base_url'] value, in the case of the question above, you should replace :
$config['base_url'] = 'localhost:8087/hris/';
by
$config['base_url'] = 'http://localhost:8087/hris/';
Hope this help :)

How to set dynamic title to extended public variable with OOP?

I hope someone can help me. How can I best dynamically change page title, desc, or key vs..vs..by extending the original class? Here is what I have so far:
<?php
class siteGlobal
{
public $arr = array('title'=>'Page Default title','desc'=>'Page default description');
public function pageHeader()
{ ?>
<!doctype html><html>
<?php }
public function metaTags()
{ ?>
<head>
<meta charset="utf-8">
<title><?php echo $this->arr['title'];?></title>
<meta name="description" content="<?php echo $this->arr['desc'];?>">
<?php }
public function pageBody()
{ ?>
</head>
<body>
<?php }
public function pageFooter()
{ ?>
</body>
</html>
<?php }
} ?>
OTHER PAGE
require_once('siteGlobal.php');
class pageDetail extends siteGlobal
{
public function __construct()
{
$this->pageHeader();
$this->newMetas();
$this->startBody();
$this->sayfaBilgileri();
$this->pageFooter();
}
public function newMetas()
{
parent::metaTags();
}
public function sayfaBilgileri()
{
//HOW I can write a new title and description in this function to siteGlobal.php (public $metaInfo) ?>
<div style="width:640px; margin:0 auto;">
<h1>Page New Title</h1>
<h2>Page New Subtitle</h2>
<p>Lorem Ipsum, bla bla....</p>
</div>
<?php }
}
$writePage = new pageDetail(); ?>
You can try to create a method in the parent class say:
protected function setTitle($title){
$this->arr['title'] = $title;
}
and use it in the extended class this way:
parent::setTitle("My title");

Categories