help me
viewhome.php
<li class="main_nav_item">
contact</li>
contact(controller)
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Contact extends CI_Controller {
public function index()
{
$this->load->view('viewcontact.php');
}
}
?>
config
$config['index_page'] = '';
autoload
$autoload['helper'] = array('url','file','form');
but always
Object not found!
help me, please
I can open viewhome, but when I click CONTACT, object not found.
My base URL config =localhost/Final
Change the code as
in viewhome.php
<li class="main_nav_item">
contact</li>
in application/config/routes.php add
$route['contact'] = 'Contact';
Related
On my login controller, I am trying ($this->input->server('REQUEST_METHOD') == 'POST') for submitting form instead of codeigniter form_validation
But when I use redirect() it does not redirect.
Question: Why does the redirects not working when submitting form with ($this->input->server('REQUEST_METHOD') and what is the best solution to get it to work.
Update: Does not seem to submit the form because I use $config['uri_protocol'] = 'QUERY_STRING'; Instead of $config['uri_protocol'] = 'REQUEST_URI';
But need to use $config['uri_protocol'] = 'QUERY_STRING';
Routes.php
$route['route=common/login'] = 'admin/common/login/index';
$route['route=common/dashboard&token=(:any)'] = 'admin/common/dashboard/index';
$route['route=common/logout&token=(:any)'] = 'admin/common/logout/index';
Config.php
$config['base_url'] = 'http://localhost/project-cms/admin/';
$config['index_page'] = '';
$config['uri_protocol'] = 'QUERY_STRING';
Login Controller
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Login extends MX_Controller {
public function index()
{
if ($this->input->server('REQUEST_METHOD') == 'POST') {
$token = md5(mt_rand());
$url_token = '&token=' . $token;
echo "working";
//redirect('index.php?route=common/dashboard' . $url_token);
//$this->response->redirect($this->url->link('common/dashboard', $url_token, 'SSL'));
}
$data['action'] = $this->url->link('common/login', '', 'SSL');
$this->load->view('template/common/login', $data);
}
}
Login View
<form enctype="multipart/form-data" method="post" action="<?php echo $action;?>">
<input type="text" name="username" />
<input type="submit" value="Submit" />
</form>
Version: Codeigniter 3 & XAMPP With Windows 7
REQUEST_METHOD has nothing to do with your redirection issue.
You are using a wrong method to define routes.
$route['common/login'] = 'admin/common/login/index';
$route['common/dashboard/(:any)'] = 'admin/common/dashboard/index/$1';
$route['common/logout/(:any)'] = 'admin/common/logout/index/S1';
And you will get your token (in your controllers) as,
public function index($token)
{
echo $token;
}
And change your login controllers as,
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Login extends MX_Controller {
public function index()
{
if ($this->input->server('REQUEST_METHOD') == 'POST') {
$token = md5(mt_rand());
redirect('common/dashboard/' . $url_token);
}
$data['action'] = $this->url->link('common/login', '', 'SSL');
$this->load->view('template/common/login', $data);
}
}
I want to fetch and update data from database using codeigniter. I am facing some problem. This is my code:
This is my Model by the name of Update_site_model.
<?php
class update_site_model extends CI_Model{
function show_invoice_id($data) {
$this->db->select('*');
$this->db->from('invoices');
$this->where('invoiceId', $data);
$query = $this->db->get();
$result = $query->result();
return $result;
//Update Query For Selected Invoice.
function update($id,$data) {
$this->db->where('invoiceId',$id);
$this->db->update('invoices',$data);
}
}
?>
This is my Controller by the name of update site.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Update_site extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->view('includes/header');
$this->load->view('site/update');
$this->load->view('includes/footer');
//load the model
$this->load->model('update_site_model');
}
function show_invoices() {
$id = $this->uri->segment(3);
$data['single_invoice'] = $this->update_site_model->show_invoice_id($id);
$this->load->view('site/update', $data);
}
function update() {
$id = $this->input->post('invoiceId');
$data = array(
'Date' => $this->input->post('invoiceDate'),
'Client' => $this->input->post('invoiceClient'),
'Amount' => $this->input->post('invoiceAmount'),
'Status' => $this->input->post('invoivceStatus')
);
$this->update_site_model->update($id, $data);
}
}
This is my view by the name of update. it is inside a folder by the name of site.
<div id="content">
<ol>
<?php foreach ($invoices as $invoice): ?>
<li><?php echo $invoice->invoiceId; ?></li>
</ol>
<?php endforeach; ?>
</div>
and this is the problem.
Severity: Notice
Message: Undefined variable: invoices
Filename: site/update.php
Line Number: 11
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: site/update.php
Line Number: 11
Please help me to solve the problem.
Look at this in your controller:
$data['single_invoice'] = $this->update_site_model->show_invoice_id($id);
and now look at this in your view:
<?php foreach ($invoices as $invoice): ?>
did you got your mistake..?
no..?
let me tell you , since you are storing the database result in $data['single_invoice'] you should access this by $single_invoice in the view.
so correct usage in your view is :
<?php foreach ($single_invoice as $invoice): ?>
and next time when you ask any question give appropriate title to it.
Is there a Codeigniter Library or extension which would make possible dynamic templating like in Wordpress or Joomla. What I mean I would like to point my controller to a view which is specified by admin from back.
than I was starting to create by myself but till this point without any success
controller
--main_conroler
here some trying what did not succeed
class MainController extends CI_Controller {
/* Initiate Site
*/
private $method;
private $data;
function __construct() {
parent::__construct();
$this->load->helper('url');
$this->load->helper('language');
$this->method = $this->router->fetch_method();
if ($this->method == "index") {
$this->data['view'] = 'templates/appStrapp';
} elseif ($this->method != 'site' && method_exists(__CLASS__, $this->method)) {
$this->data['view'] = $this->method;
}
if (empty($this->data['view'])) {
show_404();
}
}
View
view
--templates
---default
----index.php
than here I would like to route my template parts
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
if (file_exists(dirname(__FILE__) . '/tmpl/' . $view . '.php')) {
include ( dirname(__FILE__) . '/tmpl/header.php');
include ( dirname(__FILE__) . '/tmpl/navigation.php');
$this->load->view('site/tmpl/' . $view);
include ( dirname(__FILE__) . '/tmpl/footer.php');
} else {
var_dump('test');
show_404();
}
?>
I've used the following for templates in CI and it's a nice setup.
https://github.com/philsturgeon/codeigniter-template
helow, I am a newbie in codeigniter. I want to load my pages into my view dynamically. That means, Using a function.
For example i have 4 page home, about, contact, info. In my my view folder I have created a base layout where i include header and footer which is same for all those pages. now i want when i click those page link it just load into content body without loading full page. Using CI normal procedure i can do it. which is
function home(){
$data['main_content'] = 'home';
$this->load->view('template/layout', $data);
}
function about(){
$data['main_content'] = 'about';
$this->load->view('template/layout', $data);
}
but i want to create a function which call this pages into a single function for example,
function pageload($page){
}
this function check that requested file either exits or not exist. if exist it load the page otherwise load "page not found" 404 error page. How can I make it...plz help.
My view file is:
<nav>
<ul class="sf-menu">
<li class="current"><?php echo anchor('home/index', 'Home');?></li>
<li><?php echo anchor('home/amenities', 'Room & Amenitis');?></li>
<li><?php echo anchor('home/reservations', 'Reservations');?></li>
<li><?php echo anchor('home/photos', 'Photographs');?></li>
<li><?php echo anchor('home/pakages', 'Pakages');?></li>
<li><?php echo anchor('home/explore', 'Explore');?></li>
<li><?php echo anchor('home/contact', 'Contact');?></li>
</ul>
</nav>
And Controller:
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Home extends CI_Controller{
function __construct(){
parent::__construct();
}
function pageload($page){
$data['main_content'] = $page;
$this->load->view('template/layout', $data);
}
}
?>
You can do something lilke this
function pageload($page){
$data['main_content'] = $page;
$this->load->view('template/layout', $data);
}
if u dont want to show controller_name/pageload in url then in application/config/routes.php
add an array
$route['(home|about_us|other_page|another_page)'] = 'controller_name/pageload/$1';
and to load your 404 page just go to the application/config/routes.php
find this line $route['404_override'] and set its value to snything u want like
$route['404_override'] = 'page_not_found';
then in your controller just add a controller named page_not_found.php and load ur desired 404 custom view from that controller.
Try this function i think this will help you
function build_view($flake) {
$this->data['content'] = $this->load->view($flake, $this->data, TRUE);
$this->load->view('header', $this->data);
}
after you add this you need to add to other function like in index function
function index(){
$this->$data['main_content'] = $page;
$this->build_view('template/layout.php')
}
Is there anyway to hide the anchor text of the generated by CI? I know I could hide this via CSS (i.e. negative text-indent), but that seems like a lot of unnecessary work. Why wouldn’t I just use a regular HTML coded anchor?
<?php echo anchor(base_url(),''); ?>
Perhaps they thought that people would likely be passing in a blank string more by mistake than by design, I don't know and can't answer that part of your question.
Using the CodeIgniter anchor method in the URL helper has the advantage of automatically adding in your website's base path if necessary.
If you want to keep using the CodeIgniter helper and have anchors with no anchor text, you have several options:
Option 1: Add a space in the second argument:
<?php echo anchor(base_url(),' '); ?>
Option 2: Extend the URL helper and remove the behaviour:
Go into application\helpers and make a new file, called MY_url_helper.php
You can then put code in there to either replace the anchor method or define an entirely new method.
Here are some code examples of what you could put in the file: (I've adapted the code from the url_helper in a CodeIgniter installation I had handy)
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
if ( ! function_exists('anchor_hide_text'))
{
function anchor_hide_text($uri = '', $title = '', $attributes = '')
{
$title = (string) $title;
if ( ! is_array($uri))
{
$site_url = ( ! preg_match('!^\w+://! i', $uri)) ? site_url($uri) : $uri;
}
else
{
$site_url = site_url($uri);
}
if ($attributes != '')
{
$attributes = _parse_attributes($attributes);
}
return '<a href="'.$site_url.'"'.$attributes.'>'.$title.'</a>';
}
}
or
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
function anchor($uri = '', $title = '', $attributes = '')
{
$title = (string) $title;
if ( ! is_array($uri))
{
$site_url = ( ! preg_match('!^\w+://! i', $uri)) ? site_url($uri) : $uri;
}
else
{
$site_url = site_url($uri);
}
if ($attributes != '')
{
$attributes = _parse_attributes($attributes);
}
return '<a href="'.$site_url.'"'.$attributes.'>'.$title.'</a>';
}