internal error undefined index - angularjs

I am getting internal error
in AdminController.php line 85
at HandleExceptions->handleError('8', 'Undefined index: name', 'C:\wamp64\www\laravel\dev.oasis-portal.my\app\Http\Controllers\AdminController.php', '85', array('data' => array())) in AdminController.php line 85
when I run
public function courseDelete()
{
$data = Input::all();
$student = Course::where('name', '=', $data["name"]);
if($student->delete()) {
User::find($data["name"])->delete();
return json_encode(array('success' => true));
} else {
return json_encode(array('success' => false, 'errors' => "Unable to remove student."));
}
}
My route is: Route::get('/course/delete/', 'AdminController#courseDelete');

$data["name"] is not set, and therefore an exception is thrown. A better solution would be to get parameters by using the request() shorthand:
ie. request()->get('name'); //will return null if not set

Related

Wordpress React JS based template website not working after upgrading to PHP 8.1

After switching from PHP 7.4.30 to PHP 8.1, my WordPress website, which was built by the original developer using React JS, started acting strangely. The menus stopped working and the home page became frozen and immovable.
Enable the debug and below are some of them.
Deprecated: Optional parameter $menu declared before required parameter $location is implicitly treated as a required parameter in \app\public\wp-content\themes**\functions\classes\Settings\Menu.php on line 22
**
<?php
namespace ThemeClasses\Settings;
class Menu
{
public function __construct()
{
add_action('after_setup_theme', [$this, 'registerNavMenus']);
add_filter('getMenuTree', [$this, 'getMenuTree'], 10, 2);
}
public function registerNavMenus()
{
register_nav_menus([
'header_menu' => __('Header Menu', 'siri'),
'footer_menu' => __('Footer Menu', 'siri'),
'footer_columns' => __('Footer Columns', 'siri'),
]);
}
public function getMenuTree($menu = [], $location)
{
$flatMenu = $menu;
$flatMenu = $this->getMenuItems($menu, $location);
$treeMenu = [];
$itemsRefs = [];
foreach ($flatMenu as $menuItemObj) {
$itemId = $menuItemObj->ID;
$parentId = $menuItemObj->menu_item_parent;
$itemsRefs[$itemId] = [
'name' => $menuItemObj->title,
'url' => $menuItemObj->url,
'target' => $menuItemObj->target,
'active' => $menuItemObj->active,
'ID' => $itemId,
'parentId' => $parentId,
'children' => [],
];;
if ($parentId == 0) {
$treeMenu[] = &$itemsRefs[$itemId];
} elseif (isset($itemsRefs[$parentId])) {
$itemsRefs[$parentId]['children'][] = &$itemsRefs[$itemId];
}
}
return $treeMenu;
}
private function getMenuItems($menu, $location)
{
// Get all locations
$locations = get_nav_menu_locations();
// Get object id by location
$menuObject = wp_get_nav_menu_object($locations[$location]);
// Check menu exists
if (!is_object($menuObject)) return [];
// Get menu items by menu slug
$menu = wp_get_nav_menu_items($menuObject->slug);
// Return menu post objects
return $menu;
}
}
**Deprecated: parse_str(): Passing null to parameter #1 ($string) of type string is deprecated in public\wp-content\themes**r\functions\classes\WordPressSecurity.php on line 364
// add the filter
add_filter('wp_admin_css', function($url, $file) {
errol_log($url);
// make filter magic happen here...
return $url;
}, 10, 2 );
}
public function removeWPVersion($src)
{
global $wp_version;
parse_str(parse_url($src, PHP_URL_QUERY), $query);
if (!empty($query['ver']) && $query['ver'] === $wp_version) {
$src = remove_query_arg('ver', $src);
}
return $src;
}

Check if "data" contain items of Array

canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean {
return new Promise((resolve, reject) => {
this.securityService.securityActions().subscribe(
data => {debugger;
if(data = this.authorized.find(k => k=='AGREEMENTS_VIEW','AGREEMENTS_INSERT_UPDATE')){
resolve(true);
}
if(data != this.authorized){
resolve(false);
}
},
error => {
Utils.notifyErrors(error, this.notificationsService);
}
)
});
}
I want to set true if data contains some items of "authorized".
Authorized is formed like this:
authorized = [
'AGREEMENTS_VIEW',
'PROSPECTS_VIEW',
'AGREEMENTS_INSERT_UPDATE',
'PRODUCTS_INSERT_UPDATE',
'PROSPECTS_INSERT_UPDATE',
'DOCUMENTS_VIEW',
'DOCUMENTS_INSERT_UPDATE',
];
So for example set true if data contains 'AGREEMENTS_VIEW'.
Right now if i set 2 value on K it doesnt work
Use some, which returns true if the condition is matched.
return arrayOne.some(itemOfArrayOne => arrayTwo.includes(itemOfArrayOne));
You can replace includes with indexOf(XXX) !== -1.
It seems you have a syntax error:
data === this.authorized.find(k => k=='AGREEMENTS_VIEW')
//---^^^-----here

Cakephp 2 validation message on beforesave model callback

I am using CakePhp 2.5 and in a beforeSave model Callback i do return false if some information (MyIndex) is not provided.
How can i display the error message ?
I try :
$this->validationRuleErrors = 'You need to choose MyIndex';
But did not see any error message.
if( in_array( 'MyIndex', array_keys( $this->data) ) == FALSE )
{
$this->validationRuleErrors = 'You need to choose MyIndex';
debug($this->validationErrors);
return false;
}
The validationErrors property set in your beforeSave can be accessed from your controller.
Example controller:
try {
$this->Model->save($data);
if (!empty($this->Model->validationErrors)) {
// just echo $this->Model->validationErrors if you don't want to use an exception
throw new Exception($this->Model->validationErrors);
}
} catch (Exception $e) {
$this->data = [
'success' => false,
'message' => $e->getMessage()
]
}

I am facing A PHP Error was encountered

When I try to access my website member login area, I experiencing multiple errors those were not there earlier.
Please help me look into it.
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: number
Filename: controllers/Site.php
Line Number: 42
Backtrace:
File:
/home/internetsunivers/2xcash.internetsuniversity.com/application/controllers/Site.php
Line: 42 Function: _error_handler
File: /home/internetsunivers/2xcash.internetsuniversity.com/index.php
Line: 315 Function: require_once A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by
(output started at
/home/internetsunivers/2xcash.internetsuniversity.com/system/core/Exceptions.php:271)
Filename: helpers/url_helper.php
Line Number: 564
Backtrace:
File:
/home/internetsunivers/2xcash.internetsuniversity.com/application/controllers/Site.php
Line: 50 Function: redirect
File: /home/internetsunivers/2xcash.internetsuniversity.com/index.php
Line: 315 Function: require_once
Following is the code in site.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Site extends MY_Controller {
public function index()
{
$this->header(':::SONNY SERVER:::');
$data['site_name'] = $this->site_name;
$this->load->view('home');
$this->footer();
}
public function about() {
$this->header('About | '.$this->site_name);
$data['site_name'] = $this->site_name;
$this->load->view('about');
$this->footer();
}
public function faq() {
$this->header('FAQ | '.$this->site_name);
$data['site_name'] = $this->site_name;
$this->load->view('faq');
$this->footer();
}
public function support() {
$this->header('Contact Support | '.$this->site_name);
$data['site_name'] = $this->site_name;
$this->load->view('support');
$this->footer();
}
public function login() {
$this->header('Login');
$this->form_validation->set_rules('number', 'Phone Number', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
if ($this->form_validation->run()) {
if ($this->core_model->login()) {
$query = $this->db->get_where('users', array('number' => $number));
$result = $query->row_array();
$name = $result['name'];
$bank_details = $result['bank_details'];
$session_data = array('number' => $_POST['number'], 'loggedin' => TRUE, 'name' => $name);
$this->session->set_userdata($session_data);
redirect(site_url('dash'));
}
elseif ($this->db->get_where('users', array('number' => $this->input->post('number'), 'is_blocked' => 'true'))->num_rows() > 0) {
$this->session->set_flashdata('error', 'Account has been blocked, contact suppport');
} else {
$this->session->set_flashdata('error', 'Login failed');
}
$this->load->view('login');
} else {
$this->load->view('login');
}
}
public function register() {
$this->header('Register | '.$this->site_name);
$data['site_name'] = $this->site_name;
$this->form_validation->set_rules('name', 'Fullname', 'required');
$this->form_validation->set_rules('number', 'Phone Number', 'required');
$this->form_validation->set_rules('location', 'Location', 'required');
$this->form_validation->set_rules('bundle', 'Bundle', 'required');
$this->form_validation->set_rules('bank_details', 'Bank Details', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
$this->form_validation->set_rules('c_password', 'Confirm Password', 'required|matches[password]');
if($this->form_validation->run()) {
$this->core_model->register();
//register session
$session_data = array('number' => $_POST['number'], 'loggedin' => TRUE, 'name' => $_POST['name'], 'bank_details' => $_POST['bank_details']);
$this->session->set_userdata($session_data);
$this->session->set_flashdata('msg2', 'Successfully registered');
redirect(site_url('spillover'));
$this->load->view('register');
} else {
$this->load->view('register');
}
$this->footer();
}
public function logout() {
$data = array('number', 'loggedin', 'name');
$this->session->unset_userdata($data);
redirect('login');
}
}

Cakephp Render XML errors in custom Exception.renderer

Based on the information here: Using a custom renderer with Exception.renderer to handle application exceptions
I'm creating a custom error renderer that renders in XML format.
Below is the sample code for the render function in app/Lib/Error/AppExceptionRenderer:
public function render() {
if (isset($this->controller->request->params['xml'])) {
$this->controller->viewClass = "MyXml";
$error = array(
'app' => array(
'error' => 'An unexpected error has occured.'
)
);
$this->controller->set('error', $error);
$this->controller->set('_serialize', 'error');
}
}
However nothing gets returned. I have done some echo within the if condition and that shows.
So is it because the viewClass is not initialized while its in AppExceptionRenderer::render() stage?
There were no errors either.
"MyXml" viewClass works perfectly in normal controllers too.
So apparently I was missing the render and send methods.
Here's the full working example.
<?php
class AppExceptionRenderer extends ExceptionRenderer {
public function __construct($exception) {
parent::__construct($exception);
}
public function render() {
// Handle errors
if (isset($this->controller->request->params['xml'])) {
Cakelog::error($this->error->getMessage());
$this->controller->viewClass = "MyXml";
$error = array(
'app' => array(
'error' => 'An illegal operation has been detected.'
)
);
$this->controller->set('error', $error);
$this->controller->set('_serialize', 'error');
$cakeResponseObject = $this->controller->render();
$this->controller->response->send($cakeResponseObject);
} else {
if ($this->method) {
call_user_func_array(array($this, $this->method), array($this->error));
}
}
}
}

Resources