How to remove red underlines at Codeigniter 3 on session, model? - php

Visual studio code show syntax error in Codeigniter 3
Visual studio code is showing syntax error on session and model those are already injected on the controller. It did not happen before. Note: I use PHP Intelephense extension.
How can I get rid of it?
I was injecting models into controller with this $this->load->model('cart_model'); Previously, no underline at cart_model after $this-> when $old_cart_data = $this->cart_model->get_all(['user_id' => $user_id]);

Related

findOrFail Laravel 8 method not found

I am working on Laravel 8 , I have tried to use findOrFail method in order to set redirection to 404 error not found instead of displaying error but it is showing this error method findOrFail not found,
this is the line of code in ProfilesController that is causing the error
$user = User::findOrFail($user);
this is the output of the error
enter image description here
Thanks in advance,
Look like your code works fine. The issue Php Strom not able to identify methods.
I always use query() method to get autocomplete model methods
$user=User::query()->findOrFail($user);
or you might need to install any extension which can able to identify laravel methods

error variable in Zend_View (ZF1)

I have a new project to inspect and manage. It is written with ZF1.
There are views, contained in .phtml files which contain following code:
echo $this->partial('error.phtml', array('error'=>$this->error));
My issue is that no business logic, controller code or other application code sets
that error variable explicitly. I am hunting it down and need to figure out if this
error is set by Zend Framework itself.
My main lead is the CallbackHandler.php in Stdlib folder. It seems to be responsible for setting
an error flag to true, when its errorHandler is executed. Problem is that I'm not sure.
My second guess is that it is dead code and if $this->error is simply not used anywhere.
Any guesses ?
It depens on kind of displayed error.
For system errors write something like ErrorController and redirect to error page after handling of exeption(in dev mode you can add displaying of stack traces, etc).
For form validation "errors" there is build-in instruments to display it in forms.

Zend Framework 2 not displaying errors when instantiating classes which don't exist

I'm having problems debugging my code whilst trying to learn Zend Framework 2.
Intially I have been trying to implement Zend\Captcha\ReCaptcha and kept receiving black pages. However I have worked it back to the fact that when I attempt to instantiate an object from a non-existent class I do not get any errors. Just a blank page.
E.g:
public function indexAction()
{
new Zend\Captcha\ReCaptcha();
//or
new Some_Class_Which_Doesnt_Exist();
}
The result is a blank page. If I comment the instantiations out I get my standard layout page.
My PHP error reporting is set as:
error_reporting = E_ALL | E_STRICT
I'm guessing this is something to do with Zend Framework. Can I force it to display errors to help me with debugging?
Check display_errors option in php.ini, maybe it is set to 0.

CakePHP 2.0+ custom error views using exceptions

I have been reading the following question here: CakePHP 2.0 - How to make custom error pages?
About creating custom views for exception handling in CakePHP 2.0+ and have been using it as a base to start doing the same in my own application hence starting my own question.
However I'm not following the logic. For example how does the Throw NotFoundException know to call the notFound method in the Errors Controller as I don't see any direct relationship in terms of the naming... Unless I'm missing the point?
In any case I'm looking to add 404, 403, and 401 errors and then be able to create custom views and call them using the exception handler throughout my app.
Can anyone shed more light on this? I'm using the latest version of Cake 2.1
So I have the following code:
App::uses('ExceptionRenderer', 'Error');
class AppExceptionRenderer extends ExceptionRenderer {
public function notFound($error) {
$this->controller->redirect(array('controller' => 'errors', 'action' => 'error404'));
}
}
And I want to replace that redirect with rendering a custom error view:
I've tried:
$this->controller->layout = null;
$this->controller->render('/Errors/error404');
But that just shows a blank page... Can anyone help me out as I don't want to do the redirect and would much rather follow conventions and render actual views with the same url when getting errors.
Update: Also noticed that the custom views ONLY get called when exceptions are manually called in the controller, and not for actual errors such as domain.com/garbageurl or something else... So it doesn't seem to be doing what I thought!
Have a look at these files from core Cake:
Cake/Error/ErrorHandler.php
Cake/Error/ExceptionRenderer.php
Here's what's happening:
ErrorHandler::handleException() is your exception handler. It gets called when an exception is thrown.
ErrorHandler::handleException() calls ExceptionRenderer::__construct() (your custom exception renderer must extend ExceptionRenderer) which parses the name of the Exception that was thrown, and from that, sets $this->method.
ErrorHandler::handleException() then calls ExceptionRenderer::render() which uses call_user_func_array() to call the method whose name is $this->method.
I was just looking for the same thing and could not find a neat way to do this using AppExceptionRenderer. It just won't allow you to have separate error403 and error404 template files.
So I just did this in my /app/View/Errors/error400.ctp file instead...
<? if ($error instanceof ForbiddenException) { ?>
<h4>Whoops! The page you attempted to access
requires permissions that you don't have.</h4>
<? } else { ?>
<h4>Whoops! We couldn't find the page you were looking for, sorry!</h4>
<? } ?>

kohana 3.0.12 how to log

i am working on an website on kohana 3.0.12 and i have installed a module that loggs me some errors. All works fine, except that, when i want to effectively log an error, i get an error and i don;t know how to manage it.
Here is the messy code:
public static function handler(Exception $e)
{
// It's a nice time to log :)
Kohana::$log->add(Kohana::ERROR, Kohana_Exception::text($e));
etc code here
well that Kohana_Exception::text($e) causes an exception like: Call to undefined method Kohana_Exception::text() ? i guess it is a framework bug. any idea of how i can solve the problem? (i guess i should use another instance but Kohana_Exception:: but what instance?)
thank you
You get this error because neither Kohana_Exception nor Exception classes don't have text() method. I think the author of the module wanted to write like this:
Kohana::$log->add(Kohana::ERROR, Kohana::exception_text($e));
I belive the exception handling in 3.0 is located in the Kohana class. Try Kohana::exception(), or look in api guide if that isn't it.

Categories