How to set a link using the values from controller - php

I have a link that placed in my view page using codeigniter
<a href='".base_url()."user/pass_confirmation/$encrypted_string/$email'>
But the email and encrypted_string from controller..
that is not get to my view
controller
function email_check()
{
$email=$this->input->post('email');
echo $email;
$data = array(
'user_email' =>$email,
);
$result = $this->UM->email_verify($data);
if($result)
{
echo $result;
$date = date(Y-m-d);
$string = $email."-".$date;
$encrypted_string = md5($string);
echo $encrypted_string;
$res=$this->UM->insert_key($encrypted_string,$result);
redirect(base_url()."user/forgot_pass");
}
}
What can i do?

you need to get it from the uri segments like:
$string = $this->uri->segment(3);
$email = $this->uri->segment(4);

like this in your route.php file:
$route['controllerclass/function/(:any)/(:any)'] = "pass_confirmation/$1/$2";
and your link will be
domain.com/pass_confirmation/someval/someval
and then you can get string and email using segment like
$val1 = $this->uri->segment(3);
$val2 = $this->uri->segment(4);

Related

public variable cannot read by other function codeigniter

why my public variable cannot read by other function?
my public variable :
public $dataku = array();
first i set data to my public variable from model:
function cari() {
$penerima = $this->input->post('penerima');
$tanggal = $this->input->post('tanggal');
$tanggal2 = $this->input->post('tanggal2');
$id_komoditas = $this->input->post('id_komoditas');
$this->dataku['judul'] = $this->judul;
$this->dataku['pencarian'] = $this->mdl->get_data_antara_tanggal($penerima, $tanggal, $tanggal2, $id_komoditas);
$this->dataku['url'] = $this->url;
$title = "Data ".$this->judul;
$subtitle = $this->url;
$content = $this->load->view('cari.php', $this->dataku, true);
$this->load_content($title, $subtitle, $content);
}
but, when i want to read the public variable data again, it hasnt a data :
function check_data(){
$data = isset($this->dataku['pencarian']) ? $this->dataku['pencarian'] : 'no data';
print_r($data);
}
please, i need your help.
you need to access the class properties with $this. Change the following lines:
$this->dataku['judul'] = $this->judul;
$this->dataku['pencarian'] = $this->mdl->get_data_antara_tanggal($penerima, $tanggal, $tanggal2, $id_komoditas);
$this->dataku['url'] = $this->url;
Also edit the following (you have an extra $):
function check_data(){
$data = isset($this->dataku['pencarian']) ? $this->dataku['pencarian'] : 'no data';
print_r($data);
}

How to Resolve Page Redirect issue in Codeigniter

When I click on href the dashboard page is loaded but the the location on the href is a different page.
<li>Add supplier</li>
Controller
public function add_supplier($id = null)
{
$this->tbl_supplier('supplier_id');
if ($id) {//condition check
$result = $this->global_model->get_by(array('supplier_id' => $id), true);
if ($result) {
$data['supplier'] = $result;
} else {
//msg
$type = 'error';
$message = 'Sorry, No Record Found!';
set_message($type, $message);
redirect('admin/purchase/manage_supplier');
}
}
// view page
$data['title'] = 'Add New Supplier';
//$data['editor'] = $this->data;
$data['subview'] = $this->load->view('admin/purchase/add_supplier', $data, true);
$this->load->view('admin/_layout_main', $data);
}
have you tried to do this:
<li>Add supplier</li>
Passing the path into the site_url() helper function will return the correct path what are you looking for.

codeigniter can i stop loading header footer while displaying data in popup

I am displaying some data in popup but i don't want the header and footer there how can i achieve this in code-igniter
Note : i do not want to hide them by jQuery or CSS
This is my controller function to display data
function singleBookmarksView()
{
$web_url = $this->uri->segment(2);
$url_split_Array = explode('-', $web_url);
$web_id = $url_split_Array['0'];
//print_r($url_split_Array);
$data['singleBookmark'] = $this->bookmark_model->getSingleBookmark($web_id);
$data['bookmarkLabels'] = $this->getBookmarkLabel();
$this->load->view("header_view.php");
$this->load->view("bookmark_view.php", $data);
$this->load->view("footer_view.php");
}
Thanks
To do this you could either
function singleBookmarksView()
{
$web_url = $this->uri->segment(2);
$url_split_Array = explode('-', $web_url);
$web_id = $url_split_Array['0'];
$data['singleBookmark'] = $this->bookmark_model->getSingleBookmark($web_id);
$data['bookmarkLabels'] = $this->getBookmarkLabel();
$this->load->view("header_view.php");
$this->load->view("bookmark_view.php", $data);
$this->load->view("footer_view.php");
}
//create a new route for this
function singleBookmarksViewPopup()
{
$web_url = $this->uri->segment(2);
$url_split_Array = explode('-', $web_url);
$web_id = $url_split_Array['0'];
$data['singleBookmark'] = $this->bookmark_model->getSingleBookmark($web_id);
$data['bookmarkLabels'] = $this->getBookmarkLabel();
$this->load->view("bookmark_view.php", $data);
}
Or
//with this method add an extra value to the URI and it
//will show without the header and footer
function singleBookmarksView($popup = null)
{
$web_url = $this->uri->segment(2);
$url_split_Array = explode('-', $web_url);
$web_id = $url_split_Array['0'];
$data['singleBookmark'] = $this->bookmark_model->getSingleBookmark($web_id);
$data['bookmarkLabels'] = $this->getBookmarkLabel();
if (!$popup) {
$this->load->view("header_view.php");
}
$this->load->view("bookmark_view.php", $data);
if (!$popup) {
$this->load->view("footer_view.php");
}
}

Sending two data arrays to view from controller in codeigniter

I want to send two data arrays from my controller to view how can I do it ?
Following is my controller code
class Home extends CI_Controller {
public function box() {
$url = $this->pageURL();
$id_from_url = explode('/', $url);
$id = $id_from_url[6];
$query = $this->db->get_where('mc_boxes', array('idmc_boxes' => $id));
$row = $query->row();
$rowcount = $query->num_rows();
if ($rowcount <= 0) {
echo 'ID not found';
} else {
$box_id = $row->idmc_boxes;
$customer_id = $row->customers_idcustomers;
$language_id = $row->languages_idlanguages;
$template_id = $this->getTemplateID($box_id);
$template_data = $this->getTemplateData($template_id);
$variables_data = $this->getVariables($customer_id, $language_id);
$title = $variables_data[0]['value'];
$this->load->view('template', $template_data);
}
}
}
In my template view when I echo $title it says it is undefined
how can I send the whole $variables_data array with $template_data array
Thanks :)
Instead of using each array ,all do set to one
Like that,giving important sections only
...................
$data['template_data'] = $this->getTemplateData($template_id);
$data['variables_data'] = $this->getVariables($customer_id, $language_id);
$data['title'] = $variables_data[0]['value'];
$this->load->view('template', $data);
you can take $template_data and $variables_data in view files
Generally you pass in data as:
$data['template_data'] = $template_data;
$data['title'] = $$title;
....
$this->load->view('template', $data);

Very Strange Input issue

I have got a very strange input issue in which it seems that my seo description box and main content box are linked due to if I input any data into the seo input box it changes in the database in the content area as well but not the otherway around.
View:
<?php
//Setting form attributes
$formpageEdit = array('id' => 'pageEdit', 'name' => 'pageEdit');
$formInputTitle = array('id' => 'title', 'name' => 'title');
$formSEODescription = array('id' =>'seoDescription', 'name' => 'seoDescription');
$formTextareaContent = array('id' => 'textContent', 'name' => 'textContent');
?>
<?php print_r($page);?>
<div id ="formLayout" class="editPage">
<?php echo form_open('admin/editpage/index/'.$page[0]['id'].'/'.url_title($page[0]['name'],'dash', TRUE),$formpageEdit); ?>
<?php echo form_fieldset(); ?>
<h4>You are editing: <?= $page[0]['name']; ?> </h4>
<section id = "validation"><?php echo validation_errors();?></section>
<?php
if($success == TRUE) {
echo '<section id = "validation">Page Updated</section>';
}
?>
<label><?php echo form_label ('SEO Description:', 'description');?><span class="small">Required Field</span></label>
<?php echo form_input($formSEODescription, $page[0]['description']); ?>
<label><?php echo form_label ('Content:', 'content');?><span class="small">Required Field</span></label>
<?php echo form_textarea($formTextareaContent, $page[0]['content']); ?>
<script type="text/javascript">CKEDITOR.replace('textContent');</script>
<?php echo form_submit('submit','Submit'); ?>
<?php echo form_fieldset_close();
echo form_close(); ?>
</div>
Model
<?php
/**
* This model handles the sql for the checking of the username in the database
*/
class Page_model extends CI_Model
{
function __construct()
{
parent::__construct();
}
function Page_model(){
parent::Model();
}
function getCMSContent($id = NULL) {
$this->db->where('id', $id);
$query = $this->db->get('pages', 1);
if($query->num_rows() > 0) {
$row = $query->result_array();
return $row;
}else{
return FALSE;
}
}
function updatePage($id = NULL, $data = NULL){
#set the $data passed to the function into an array, content being the column name.
$data = array('content' => $data, 'description' => $data);
$this ->db->where('id',$id);
$this->db->update('pages', $data);
return TRUE;
}
}
?>
Controller
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Editpage extends CI_Controller {
function __construct(){
parent::__construct();
}
function index($id){
if(!$this->session->userdata('logged_in'))redirect('admin/home');
if ($this->input->post('submit')){
#The User has submitted updates, lets begin!
#Set The validation Rules
$this->form_validation->set_rules('textContent', 'Content', 'trim|required|xss_clean');
$this->form_validation->set_rules('seoDescription', 'SEO Description', 'trim|required|xss_clean');
#if the form_validation rules fail then load the login page with the errors. Otherwise continue validating the user/pass
if ($this->form_validation->run() == FALSE){
$data['cms_pages'] = $this->navigation_model->getCMSPages($id);
#connect to getCMSCotent and set the page info equal to the $data['page'] where the row is equal to the passed $id from the URL.
$data['page'] = $this->page_model->getCMSContent($id);
$data['sales_pages'] = $this->sales_model->getSalesPages();
$data['content'] = $this->load->view('admin/editpage', $data, TRUE);
$this->load->view('admintemplate', $data);
}
#Form Validation passed, so lets continue updating.
#lets set some variables.
$content = $this->input->post('textContent', TRUE);
$content = $this->input->post('seoDescription', TRUE);
$this->db->escape($content);
#Now if updatePage fails to update hte database then show "there was a problem", you could echo the db error itself
if($this->page_model->updatePage($id, $content)) {
$data['cms_pages'] = $this->navigation_model->getCMSPages($id);
#connect to getCMSContent and set the page info equal to the $data['page'] where the row is equal to the passed $id from the URL.
$data['page'] = $this->page_model->getCMSContent($id);
$data['success'] = TRUE;
$data['content'] = $this->load->view('admin/editpage', $data, TRUE);
$this->load->view('admintemplate', $data);
}//END if updatePage
}else{
$data['cms_pages'] = $this->navigation_model->getCMSPages($id);
$data['sales_pages'] = $this->sales_model->getSalesPages();
#connect to getCMSCotent and set the page info equal to the $data['page'] where the row is equal to the passed $id from the URL.
$data['page'] = $this->page_model->getCMSContent($id);
$data['content'] = $this->load->view('admin/editpage', $data, TRUE);
$this->load->view('admintemplate', $data);
}//END if post submitted
} //END function index()
}
Found it:
$content = $this->input->post('textContent', TRUE);
$content = $this->input->post('seoDescription', TRUE);
[update below]
You are overwriting the $content variable with the content of seoDescription so textContent never reaches your db.
You need to update your updatePage function:
function updatePage($id = NULL, $content = NULL, $description = NULL){
#set the $data passed to the function into an array, content being the column name.
$data = array('content' => $content, 'description' => $description);
$this ->db->where('id',$id);
$this->db->update('pages', $data);
return TRUE;
}
and call it appropriately:
[...]
#Form Validation passed, so lets continue updating.
#lets set some variables.
$content = $this->input->post('textContent', TRUE);
$description = $this->input->post('seoDescription', TRUE);
$this->db->escape($content);
$this->db->escape($description);
#Now if updatePage fails to update hte database then show "there was a problem", you could echo the db error itself
if($this->page_model->updatePage($id, $content, $description)) {
[...]
By the way are you sure you are using db->escape correctly? The way you're calling it will only work if the escape function accepts parameters by reference (e.g. using & in front of the parameter name, and setting this value to the escaped value). I'd expect this code to be the correct version, but I don't know your db class so I may be wrong:
$content = $this->db->escape($this->input->post('textContent', TRUE));
$description = $this->db->escape($this->input->post('seoDescription', TRUE));

Categories