I use Codeigniter's _remap function to remap all urls to www.website.com. This works for 99% of cases, but I'd like it to ignore certain URLS (specifically /admin,/contact,/submit,/top,/browse). These URLs have content I'd like to display.
How would I achieve this?
public function _remap($urlname)
{
if($urlname == "index") {
// If this is the index, redirect to the most recent startup
redirect("s/".$this->Startup_model->getMostRecent(), 'refresh');
} else {
// If they didn't go to the index, find the startup they were after
$id = $this->Startup_model->matchName($urlname);
// Check to see if the name they entered was a real startup, if not redirect to missing page
if($id == null) {
$data['urlname'] = $urlname;
$this->load->view('header/header');
$this->load->view('content/missing', $data);
$this->load->view('footer/footer');
} else {
// They got the name right! Load the page...
$data['values'] = $this->Startup_model->buildStartup($id);
// If there was no next startup avaiable, pass that info through
$next = $this->Startup_model->findNext($id);
if($next == null) {
$next = '343z61v';
}
// If there was no previous startup avaiable, pass that info through
$previous = $this->Startup_model->findPrevious($id);
if($previous == null) {
$previous = '343z61v';
}
$data['next'] = $next;
$data['previous'] = $previous;
$this->load->view('header/header');
$this->load->view('content/startup', $data);
$this->load->view('footer/footer');
}
}
}
Try this:
function _remap($urlname, $params = array())
{
if(is_callable(array($this, $urlname))){ //If the function exists, is called, if not using the usual
return call_user_func_array(array(&$this, $urlname), $params);
}elseif($urlname == "index") {
// If this is the index, redirect to the most recent startup
redirect("s/".$this->Startup_model->getMostRecent(), 'refresh');
} else {
// If they didn't go to the index, find the startup they were after
$id = $this->Startup_model->matchName($urlname);
// Check to see if the name they entered was a real startup, if not redirect to missing page
if($id == null) {
$data['urlname'] = $urlname;
$this->load->view('header/header');
$this->load->view('content/missing', $data);
$this->load->view('footer/footer');
} else {
// They got the name right! Load the page...
$data['values'] = $this->Startup_model->buildStartup($id);
// If there was no next startup avaiable, pass that info through
$next = $this->Startup_model->findNext($id);
if($next == null) {
$next = '343z61v';
}
// If there was no previous startup avaiable, pass that info through
$previous = $this->Startup_model->findPrevious($id);
if($previous == null) {
$previous = '343z61v';
}
$data['next'] = $next;
$data['previous'] = $previous;
$this->load->view('header/header');
$this->load->view('content/startup', $data);
$this->load->view('footer/footer');
}
}
}
Note:
Function index() should not exist
So you're asking how to selectively not remap certain urls? If so, add this to your if statement before the else:
else if (in_array($urlname, array('admin', 'contact', 'etc')))
{
$this->$urlname;
}
Related
Hi, I have problem with routes, it's always return "Missing Required Parameters".Please see my code below. Thank you! I think my route is wrong, what should I do?
//Controller Code
public function index($id = 0,$dateStart = null, $dateEnd = null)
{
//$current_date = date('Y-m-d');
// $attendances= Attendance::select('Name','CheckIn','CheckOut','Note','Date','TotalHours')-
>where('Date','=',$current_date)->get();
// return view('attendance.index',compact('attendances'))
if($id == 0 && $dateStart == null && $dateEnd == null)
{
$current_date = date('Y-m-d');
$attendances =
Attendance::select('Name','CheckIn','CheckOut','Note','Date','TotalHours')-
>where('Date','=',$current_date)->get();
return view('manage.index',compact('attendances'));
}
elseif ($id != 0)
{
$sUser = User::select('name')->where('id','=',$id)->get();
$attendances =
Attendance::select('Name','CheckIn','CheckOut','Note','Date','TotalHours')->where('user_id','=',$id)-
>get();
return view('manage.index',compact('attendances','sUser'));
}
elseif($dateStart != null && $dateEnd == null)
{
$attendances =
Attendance::select('Name','CheckIn','CheckOut','Note','Date','TotalHours')
>whereBetween('Date',$dateStart,$dateEnd)->get();
return view('manage.index',compact('attendances'));
}
// return view('manage.index');
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
}
And here is my route.
Route::get('manageattendance/{id}/{dateStart}/{dateEnd}',
[App\Http\Controllers\ManageAttendanceController::class, 'index'])->name('manageattendance');
if you set the parameters in function must say for route these parameters are not required are optionally add ? after each parameter
Route::get('manageattendance/{id?}/{dateStart?}/{dateEnd?}',
The orignial code was like this , I want to get landline_no value also in getRecords, How to do that
public function checklead() {
$lead = $_POST['number'];
$check = $this->common_model->getRecords('leads',array("phone_no"=>$lead));
if(count($check) > 0) {
$lead = $this->common_model->getRecored_row('leads',array("phone_no"=>$lead));
if($lead->assignto_self != 0) {
$assignto = $lead->assignto_self;
$key = 'Self Assign';
} else if($lead->assignto_se != 0) {
$assignto = $lead->assignto_se;
$key = '';}
What I have achieved so far,but not getting array values from getRecords
$lead = $_POST['number'];
$check = $this->common_model->getRecords('leads',array("phone_no"=>$lead),array("landline_no"=>$lead));
//echo "<pre>";
//print_r($check);
//echo $check[0]['landline_no'];exit;
if(count($check) > 0) {
$lead = $this->common_model->getRecored_row('leads',array("phone_no"=>$lead,"landline_no"=>$check[0]['landline_no']));
Code for getRecords:
function getRecords($table,$db = array(),$select = "*",$ordercol = '',$group = '',$start='',$limit=''){
$this->db->select($select);
if(!empty($ordercol)){
$this->db->order_by($ordercol);
}
if($limit != '' && $start !=''){
$this->db->limit($limit,$start);
}
if($group != ''){
$this->db->group_by($group);
}
$q=$this->db->get_where($table, $db);
return $q->result_array();
}
// Get Recored row
public function getRecored_row($table,$where)
{
$q = $this->db->where($where)
->select('*')
->get($table);
return $q->row();
}
Check my answer: This code also working well, i have written, but i am not sure , this logic is correct or not kindly check this one.
public function checklead() {
$lead = $_POST['number'];
if($this->common_model->getRecords('leads',array("phone_no"=>$lead)))
{
$check=$this->common_model->getRecords('leads',array("phone_no"=>$lead));
}
else
{
$check=$this->common_model->getRecords('leads',array("landline_no"=>$lead));
}
echo "<pre>";
//echo $check;
//print_r($check); exit;
$p= $check[0]['phone_no'];
$l= $check[0]['landline_no'];
// exit;
if(count($p) > 0 || count($l)>0) {
$lead = $this->common_model->getRecored_row('leads',array("phone_no"=>$p));
$lead1 = $this->common_model->getRecored_row('leads',array("landline_no"=>$l));
if($lead->assignto_self != 0 || $lead1->assignto_self != 0) {
$assignto = $lead->assignto_self;
$key = 'Self Assign';
} else if($lead->assignto_se != 0 || $lead1->assignto_se != 0) {
$assignto = $lead->assignto_se;
$key = '';
}else if($lead->assignto_tl != 0 || $lead1->assignto_tl != 0) {
$assignto = $lead->assignto_tl;
$key = '';
} else if($lead->uploaded_by != 0 || $lead1->uploaded_by != 0) {
$assignto = $lead->uploaded_by;
$key = 'Uploaded by';
}
$user = $this->common_model->getRecored_row('admin',array("id"=>$assignto));
$role = $this->common_model->getRecored_row('role',array("id"=>$user->role));
$this->session->set_flashdata('message', array('message' => 'This Lead Already exist with '.$user->name.' ('.$role->role.') '.' ','class' => 'danger'));
redirect(base_url().'leads');
} else {
redirect(base_url().'leads/add_newlead/'.$lead);
}
}
There does not seem to be any reason to use getRecords(). The $check value has no useful purpose and creating it is a waste of resources.
We don't need $check because getRecord_row() will return the "lead" if found so the only check needed is to see if getRecord_row() returns anything. getRecord_row() uses the database function row() which returns only one row or null if no rows are found. Read about row() here.
If what you want is to find the "lead" that has either a "phone_no" or a "landline_no" equal to $_POST['number'] then you need to use a custom string for the where clause. (See #4 at on this documentation page.) You need a custom string because getRecord_row() does not allow any other way to ask for rows where a='foo' OR b='foo'. Here is what I think you are looking for.
public function checklead()
{
// use input->post() it is the safe way to get data from $_POST
$phone = $this->input->post('number');
// $phone could be null if $_POST['number'] is not set
if($phone)
{
$lead = $this->common_model->getRecored_row('leads', "phone_no = $phone OR landline_no = $phone");
// $lead could be null if nothing matches where condition
if($lead)
{
if($lead->assignto_self != 0)
{
$assignto = $lead->assignto_self;
$key = 'Self Assign';
}
else if($lead->assignto_se != 0)
{
$assignto = $lead->assignto_se;
$key = '';
}
}
}
}
The main difference between getRecords() and getRecord_row() is the number of records (rows of data) to return. getRecord_row() will return a maximum of one record while getRecords() might return many records.
getRecords() accepts arguments that allow control of what data is selected ($db, $select), how it is arranged ($ordercol, $group), and the number of rows to retrieve ($limit) starting at row number x ($start) .
Hello this is my controller in laravel and I am not getting the problem here. It checks the file if I manually enter a dataset with the value of 1 but if I do it with the system it does not update the value and the box remains to 0 with unchecked box.
What I am trying to do is tick the box if the user tick it and keep the box ticked until he ticks it off plus update the database value too. Thank you in advance
public function tickoffUpload($id, $type, User $user) {
$uploads = $this->upload->get($id);
// if($this->request->isMethod('get')) {
// if($user->can('untick', $uploads)) {
// $uploads = $this->upload = 0;
// } else {
// return $uploads = $this->upload = 1;
// }
// }
if($this->request->isMethod('get')) {
if($type == 0) {
$uploads = $this->upload = 1;
} else if($type == 1){
$uploads = $this->upload = 0;
}
}
if(isset($_POST["uploaded"]) && !empty($_POST["uploaded"])) {
$uploads->uploaded = $this->request->uploaded;
$uploads->save();
}
return redirect('/home');
}
I have sorted this out. I was not getting the requesting value from the form as you can see here $uploads->uploaded = $this->upload = 1; so here is the updated code which I did and worked.
public function tickoffUpload($id, $type, User $user) {
$uploads = $this->upload->get($id); //gets upload id
// requesting uploaded value either 0 or 1
if($this->request->isMethod('get')) {
if($type == 0) {
$uploads->uploaded = $this->request->upload = 1;
} else if($type == 1) {
$uploads->uploaded = $this->request->upload = 0;
}
}
$uploads->save(); // saving the value in database
return redirect('/home');
}
Thank you d3r1ck for the help though ... :)
I use codeigniter 3.0.6 query string like
index.php?d=directoryt&c=controller
index.php?d=directory&c=controller&m=function
How ever having two get methods for directory and controller is a bit long.
Question Is there any way to modify the protected function
_set_routing() function using a MY_Router.php to get it so it will pick up the directory and controller by using one query only like example below.
index.php?route=directory/controller
// If need to get function
index.php?route=directory/controller&m=function
What have tried so far
<?php
class MY_Router extends CI_Router {
protected function _set_routing()
{
// Load the routes.php file. It would be great if we could
// skip this for enable_query_strings = TRUE, but then
// default_controller would be empty ...
if (file_exists(APPPATH.'config/routes.php'))
{
include(APPPATH.'config/routes.php');
}
if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/routes.php'))
{
include(APPPATH.'config/'.ENVIRONMENT.'/routes.php');
}
// Validate & get reserved routes
if (isset($route) && is_array($route))
{
isset($route['default_controller']) && $this->default_controller = $route['default_controller'];
isset($route['translate_uri_dashes']) && $this->translate_uri_dashes = $route['translate_uri_dashes'];
unset($route['default_controller'], $route['translate_uri_dashes']);
$this->routes = $route;
}
// Are query strings enabled in the config file? Normally CI doesn't utilize query strings
// since URI segments are more search-engine friendly, but they can optionally be used.
// If this feature is enabled, we will gather the directory/class/method a little differently
if ($this->enable_query_strings)
{
// If the directory is set at this time, it means an override exists, so skip the checks
if ( ! isset($this->directory))
{
$_route = isset($_GET['route']) ? trim($_GET['route'], " \t\n\r\0\x0B/") : '';
if ($_route !== '')
{
echo $_route;
$this->uri->filter_uri($_route);
$this->set_directory($_route);
}
}
// Routing rules don't apply to query strings and we don't need to detect
// directories, so we're done here
return;
}
// Is there anything to parse?
if ($this->uri->uri_string !== '')
{
$this->_parse_routes();
}
else
{
$this->_set_default_controller();
}
}
}
config.php
$config['allow_get_array'] = TRUE;
$config['enable_query_strings'] = TRUE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';
$config['directory_trigger'] = 'd';
// Modifyed in MY_Router.php
$config['route'] = 'route';
I have it working
<?php
class MY_Router extends CI_Router {
protected function _set_routing() {
if (file_exists(APPPATH.'config/routes.php'))
{
include(APPPATH.'config/routes.php');
}
if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/routes.php'))
{
include(APPPATH.'config/'.ENVIRONMENT.'/routes.php');
}
// Validate & get reserved routes
if (isset($route) && is_array($route))
{
isset($route['default_controller']) && $this->default_controller = $route['default_controller'];
isset($route['translate_uri_dashes']) && $this->translate_uri_dashes = $route['translate_uri_dashes'];
unset($route['default_controller'], $route['translate_uri_dashes']);
$this->routes = $route;
}
if ($this->enable_query_strings) {
if ( ! isset($this->directory))
{
$route = isset($_GET['route']) ? trim($_GET['route'], " \t\n\r\0\x0B/") : '';
if ($route !== '')
{
$part = explode('/', $route);
$this->uri->filter_uri($part[0]);
$this->set_directory($part[0]);
if ( ! empty($part[1])) {
$this->uri->filter_uri($part[1]);
$this->set_class($part[1]);
// Testing function atm
if ( ! empty($_GET['function']))
{
$this->uri->filter_uri($_GET['function']);
$this->set_method($_GET['function']);
}
$this->uri->rsegments = array(
1 => $this->class,
2 => $this->method
);
}
} else {
$this->_set_default_controller();
}
}
// Routing rules don't apply to query strings and we don't need to detect
// directories, so we're done here
return;
}
// Is there anything to parse?
if ($this->uri->uri_string !== '')
{
$this->_parse_routes();
}
else
{
$this->_set_default_controller();
}
}
}
Hi I've already installed the CometChat, but I'm facing the following error:
Call to undefined function mcrypt_decrypt() in /home/vagrant/changeglobe/public/cometchat/integration.php on line 89
I'm using Homestead with Nginx for Laravel. I have read at many places that I need to enable mycrypt, but did not found any correct. Please let me know about this issue if you know. Thank you.
Try replacing the getUserID() function in /cometchat/integration.php file with the code below:
function getUserID() {
$userid = 0;
if (!empty($_SESSION['basedata']) && $_SESSION['basedata'] != 'null') {
$_REQUEST['basedata'] = $_SESSION['basedata'];
}
if (!empty($_REQUEST['basedata'])) {
if (function_exists('mcrypt_encrypt') && defined('ENCRYPT_USERID') && ENCRYPT_USERID == '1') {
$key = "";
if( defined('KEY_A') && defined('KEY_B') && defined('KEY_C') ){
$key = KEY_A.KEY_B.KEY_C;
}
$uid = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode(rawurldecode($_REQUEST['basedata'])), MCRYPT_MODE_CBC, md5(md5($key))), "\0");
if (intval($uid) > 0) {
$userid = $uid;
}
} else {
$userid = $_REQUEST['basedata'];
}
}
if (!empty($_COOKIE['laravel_session'])) {
$session= cookie_decrypt($_COOKIE['laravel_session']);
$data = file_get_contents(dirname(dirname(dirname(__FILE__))).'/storage/framework/sessions/'.$session);
if (!empty($data)) {
$k = explode(';i:',$data);
$m = explode(';s:',$k[1]);
$userid = $m[0];
}
}
$userid = intval($userid);
return $userid;
}
If you are still facing issues please create a support ticket https://my.cometchat.com/tickets and our team will assist you.