I have a same problem with this How to change an error displayed in codeigniter
I tried the solution from Jordan Arseno, because that was the most logically answer that could be, but the problem is the class that he suggested can't be loaded so it stuck with the default error from Codeigniter.
I want to make a custom error view, so I tried to change file system/core/URI.php directly but it can't use redirect function because :
autoload['helper']="url";can't be loaded in this URI file.
Can anybody know how to solve this?
Change on system/core/Input.php , try this this must work let me know if doesn't work , this works for me
<?php
class MY_Input extends CI_Input {
/**
* Clean Keys
*
* This is a helper function. To prevent malicious users
* from trying to exploit keys we make sure that keys are
* only named with alpha-numeric text and a few other items.
*
* Extended to allow:
* - '.' (dot),
* - '[' (open bracket),
* - ']' (close bracket)
*
* #access private
* #param string
* #return string
*/
function _clean_input_keys($str) {
if (!preg_match("/^[a-z0-9:_\/\.\[\]-]+$/i", $str)) {
/**
* Check for Development enviroment - Non-descriptive
* error so show me the string that caused the problem
*/
if (getenv('ENVIRONMENT') && getenv('ENVIRONMENT') == 'DEVELOPMENT')
var_dump($str);
exit('Disallowed Key Characters.');
}
// Clean UTF-8 if supported
if (UTF8_ENABLED === TRUE) {
$str = $this->uni->clean_string($str);
}
return $str;
}
}
// /?/> /* Should never close php file - if you have a space after can mess your life up */
Related
A problem that we probably didn't know about when switching to PHP 8+:
Very often, in the rules we created earlier, we returned a message like this:
public function message(): array
{
return [$this->validator->errors()->messages()];
}
When using PHP 7.4 - this isn't a problem, but not for PHP 8+
Since looking "deeper" into how the laravel framework forms messages, we get an error in the replaceAttributePlaceholder method of the FormatsMessages class:
/**
* Replace the : attribute placeholder in the given message.
*
* #param string $message
* #param string $value
* #return string
*/
protected function replaceAttributePlaceholder($message, $value)
{
return str_replace(
[':attribute', ':ATTRIBUTE', ':Attribute'],
[$value, Str::upper($value), Str::ucfirst($value)],
$message
);
}
And indeed, if we open any editor and run the same code, but for two different versions, we'll get:
If you return the message like this:
public function message(): array
{
return $this->validator->errors()->messages();
}
We will avoid the error, but accordingly, the format of the message will be different - this doesn't suit me, and the format of the message should remain the same.
Does anyone have any ideas on how to save the format and fix the error?
In my code I prefer to have more than a single line break between methods inside a class to make browsing code a little easier, and I've tried a bunch of rules that sound related to keeping/removing white space, but I cannot find a rule to ignore empty line breaks.
Take the following snippet
<?php
class Foo
{
public function __construct()
{
//
}
/**
* Undocumented function
*
* #param [type] $param1
* #param [type] $param2
*/
public function bar($param1, $param2)
{
//
}
}
php-cs-fixer will remove the white space between the two methods like so
<?php
class Foo
{
public function __construct()
{
//
}
/**
* Undocumented function
*
* #param [type] $param1
* #param [type] $param2
*/
public function bar($param1, $param2)
{
//
}
}
I find this harder to read when scanning through a class file, so I'd like to tell php-cs-fixer to leave the empty line breaks alone. Is this possible?
I've tried setting no_extra_blank_lines to an empty array, or to false as this sounded like the right setting, but it doesn't appear to have any affect.
FYI I'm using VS Code with this extension: https://marketplace.visualstudio.com/items?itemName=junstyle.php-cs-fixer
After leaving this for a couple of days, I've come back to it and managed to find the appropriate rule.
If I change method_separation => false the line breaks are left in tact in class files.
So we have a codebase, which has been developed over the years. As this is a commercial framework, we have several functions in the core PHP files, which are widely used, but won't change that much. We also have some interns on a regular basis, who don't need to have access to the code, but need to view which variables need to be passed and which return to expect.
I want to create a file like standard.php in Eclipse, which only shows the function name and or class names and functions and which variables to pass. I want to create something similar so it eases the development of separate modules, without giving access to the entire codebase.
As I can manually copy the files and strip the code from the functions, this seems to be a bit tedious to do by hand. Also, some functions are being transferred or extended, which means this would need to be done every now and then.
/**
* Check if file is allowed to be added/edited/deleted etc.
*
* #param string $source
*
* #return boolean
*
* #since v9 / WdH / 17-07-2019
*
*/
function get_file_allow_rights($source){
if($source == ""){
if($_SESSION["did"] > 0){
$source = get_def("smkb_main_file", "source", "WHERE did = $_SESSION[did]", 1);
}elseif(isset($_POST["source"])){
$source = secure($_POST["source"], "string");
}
}
if($source != "" && get_r(get_source_property("modulename", $source), "edit")){
$allow = true;
}else{
$allow = false;
}
return $allow;
}
should be changed to
/**
* Check if file is allowed to be added/edited/deleted etc.
*
* #param string $source
*
* #return boolean
*
* #since v9 / WdH / 17-07-2019
*
*/
function get_file_allow_rights($source){}
So is there a function in PHP or some other program like Eclipse to accomplish just this?
Is there anyway to give text editors summary information in a tooltip for custom functions/classes etc. in the way that they can do for standard libraries while coding?
Failing this what is the standard way to highlight the purpose, required params etc. for a function/class in PHP.
Check out PHPDocumentor.
An example would be:
/**
* Set the data
*
* #access public
* #param string $field
* #param mixed $value
*/
public function __set($field, $value)
{
$this->_data[$field] = $value;
}
/**
* Get the data
*
* #access public
* #param string $field
* #return mixed
*/
public function __get($field)
{
return isset($this->_data[$field]) ? $this->_data[$field] : NULL;
}
As the comments self-explain, you use #access to show the visibility of the method (if the code being summarized is a method, of course), #paramto show each parameter, and #return to show the type of the data being returned. There are many different tags to document many different aspects of the code.
You can use the PHPDoc standard for letting your IDE give you hints about, for example, a function.
Just before a function declaration you could have:
/**
* This is a DocBlock comment
*/
function foo(){
//....
}
I've used it in Netbeans and can say that it works quite nicely.
When creating form elements with Zend (using Zend Studio for Eclipse), I'd like some auto completion or hints. Here's what I'm thinking. I'm sure these exist, but I don't know how to get them.
I type createElement and auto-completes gives me the signature createElement($type, $name). Great, I select it.
but when I try to set the $type I don't get any hints like DateTextBox or ValidationTextBox. Being new, I see how this can be useful. What do you do to remember all the options?
for the array of attributes like require, invalidMessage, I'd like to get a list of those to choose from, and/or auto-complete when I start typing one.
// Date field
$date = $this->createElement('DateTextBox', 'date',
array('require' => 'true', 'invalidMessage' => 'Invalid date format')
);
$date->setLabel('date')->setRequired(true);
You have few options to help yourself, without waiting for any plugin:
learn it and remember ;)
extend your phpDoc blocks with all available options:
Example (to be honest I don't know if Eclipse supports html in phpDoc or even any text after variable name in #param, but it works fine in Netbeans):
/**
* [...]
* #param string $type Can be: <ul><li>DateTextBox</li><li>ValidationTextBox</li></ul>
* #param string $name Whatever
* #param array|Zend_Config $options Array with following keys: <ul><li>require</li><li>invalidMessage</li></ul>
* #return Zend_Form_Element
*/
public function createElement($type, $name, $options = null)
extend Zend class and create your own methods to simplify your work
Example:
class My_Zend_Form_Element extends Zend_Form_Element
{
public function createDateTextBox($name, $options = null)
{
return $this->createElement('DateTextBox', $name, $options);
}
}
declare some well named constants and provide some hint in phpDoc
Example: (type ZFE_OPTIONS and IDE should show hint with some constants to use as array keys)
/**
* Can be true or false
*/
define('ZFE_OPTIONS_REQUIRE','require');
create your own helper classes with methods to produce valid options array
Example:
class ZFE_Options
{
protected $opts = array();
/**
* #param bool $req
* #return ZFE_Options
*/
public function setRequired($req){
$this->opts['require'] = (bool)$req;
return $this;
}
/**
* #param string $txt
* #return ZFE_Options
*/
public function setInvalidMessage($txt){
$this->opts['invalidMessage'] = (string)$txt;
return $this;
}
/**
* #return array
*/
public function toArray(){
return $this->opts;
}
}
$zfe_options = new ZFE_Options();
$opts = $zfe_options
->setRequired(true)
->setInvalidMessage('Please provide valid email address')
->toArray();
That's not possible. It's not how autocompletion works. The hints you get are taken directly from ZF's code documentation. Nothing more, nothing less. Everything you see as hints is taken directly from the DocBlock and method signature, e.g.
/**
* Create an element
*
* Acts as a factory for creating elements. Elements created with this
* method will not be attached to the form, but will contain element
* settings as specified in the form object (including plugin loader
* prefix paths, default decorators, etc.).
*
* #param string $type
* #param string $name
* #param array|Zend_Config $options
* #return Zend_Form_Element
*/
public function createElement($type, $name, $options = null)
Eclipse can tell you to insert a string or an array and it will know that the method returns a Zend_Form_Element, but it cannot tell you what these strings should be.
The only place where I know something like what you describe exists is for CSS files. For some reason, when I type in display: it will give me an autocomplete box with possible values for this declaration. If you want more sophisticated autocomplete like this, consider filing this as a feature request to Zend.