I have a standard (auto-generated) index.php bootstrap file for my Yii application. It contains:
defined('YII_DEBUG') or define('YII_DEBUG', TRUE);
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL', 3);
When I put these two lines:
var_dump(defined('YII_DEBUG'));
var_dump(YII_DEBUG);
below definition of these two Yii constants, I'm getting an excepted behavior (two times true).
When I comment first line of first code block (YII_DEBUG definition) I'm also getting an expected results -- false + Notice: Use of undefined constant YII_DEBUG.
Strange things starts to happen, when I leave definition of YII_DEBUG commented, but move these two var_dump lines from index.php and put them in the beginning of my configuration file.
I expected the very same behavior (nothing has changed, YII_DEBUG remains undefined), but instead I'm getting true + false.
What has happened? What I'm missing? At which point of Yii application life-cycle the YII_DEBUG constant has become defined?
EDIT: Adding print_r(get_defined_constants(true)['user']); below these two var_dump confirms, that YII_DEBUG is defined in second scenario and undefined in first one.
YII_DEBUG is set to false in YiiBase.php, that gets called by yii.php, that is included in your index.php
Related
This route need a little extra work in order for it to work properly, but I am not able to see what I need to do:
'http://<caregiverName:\w+>.' . $domain . '/<controller:\w+>/<action:\w+>' => '<controller>/<action>',
When I make call like this controller/action, everything works fine. When I make this call controller (without the explicit index) in order to make call to actionIndex, I am not able to catch caregiverName param. But when I make this call controller/index (index explicitly specified), it works normally.
What I need to rework in the router?
Two things:
Rule for calls without index
You need a second rule with the index as a static value when it is not provided. Add this after your first rule like so:
'http://<caregiverName:[\w-.]+>.' . $domain . '/<controller:\w+>/<action:\w+>' => '<controller>/<action>',
'http://<caregiverName:[\w-.]+>.' . $domain . '/<controller:\w+>' => '<controller>/index',
The reason for this is that yii will to this normally, but not for your explicitly defined rule. The reason to put it after is that it would otherwise match before the other and always put you on the index page ;-).
Regex corrections for domain-characters
In you rule you use \w+ as a placeholder for a domain name. the way you specified your rule, it won't work with any other characters than "word-characters" (a-zA-Z0-9_). The dot (subdomain) and the dash (-) are missing! For the domain perfectly.valid-subdomain.com your rule won't work. You can find an axplanation of the regex shorthands here.
Check out my example above how I specified the character classes. You could of course also validate the length etc, but this is not the scope of this answer...you should get the gist.
Tell me if you need more information!
I am upgrading the yadcf version on my site from 0.6.9 to 0.8.8. (I'm also upgrading from datatables 1.9.4 to 1.10.10)
See the 0.6.9 version at my production site and the 0.8.8 version at my sandbox site
I have updated my calls to yadcf.exFilterColumn from two calls to a single call because now the defaults take an array of pairs.
But my filtered dataset is empty when the page loads, and I need to select a gender then click all for all the data to show up.
I'm sure it's something I'm not quite getting for the new interface.
Update: Simplified sandbox version here. See file TestStandings.js
Update 2: Daniel pointed out that "-1" for gender filter won't work. Apparently usegender = "-1" doesn't behave the same way in 0.8.8 as it did in 0.6.9 for some reason. I could try to figure out why it used to work, but that seems unproductive.
I added the following code after the exFilterColumn call (it's necessary for the gender to be filtered in some use cases)
// reset gender column if didn't mean to filter
if (usegender == "-1") {
yadcf.exResetFilters( _rrwebapp_table, [genderCol] )
}
but this gets exception at line 3624 of jquery.dataTable.yadcf.js because settingsDt.aanFeatures.f is undefined
Update 3: while debugging on the datatables side, I changed sDom from '<"H"Clpr>t' to the default 'lfrtip'. The exception mentioned above went away and the table loaded properly.
Here is how you should handle your scenario
Its wrong to ask for filtering for a -1 value because there is no such value in the table, so in order to reset a specific column just before calling exFilterColumn you should use the exResetFilters with noRedraw set to true (grab from 0.8.9.beta.31) you should call this function before your exFilterColumn
Old answer
I might have noticed multiple calls to the exFilterColumn for the same table, while in fact you should call it only once, just set the desired values for each column of the table,
See showcase page (first table)
And notice the relevant code below
yadcf.exFilterColumn(firstTable, [
[1, {
from: 1,
to: 40
}],
[3, "a_value"]
]);
If it still no goodm please provide the your table / yadcf init code and the code for calling the exFilterColumn
Update:
I noticed that your are using the following line of code
yadcf.exFilterColumn(_rrwebapp_table, [[divisionCol, usedivision], [genderCol, usegender]])
Where your usegender is set to "-1" which makes no sense, because its the value of the Select input reset option, so make sure you dont use "-1" as values in your exFilterColumn calls...
In the defined('YII_DEBUG') or define('YII_DEBUG', false); line of code we are checking if debug has defined previously it will do nothing but if not it will set to false.
I did not get this I mean what if we want to override previous value and why we cant simply do define('YII_DEBUG', false); why it necessary to check previous value if we don't want to use that?
I didnt do it but you are not clear about my question, we can only change the YII_DEBUG value in /web/index.php. one more thing if YII_DEBUG has defined anywhere else but after that if we want to change its value what to do for that as 'or' will not change it and it is constant too so cant change its value?
Yes, you are very wrong... You can declare the YII_DEBUG value anywhere where you want, but... if it is redefined:
Notice: Constant YII_DEBUG already defined in...
I think thats the reason of defined() or... TO PREVENT THIS ERROR
You can just change it to true or false to a page on the fly by just doing this:
define('YII_DEBUG', true);
In such cases defined('YII_DEBUG') or define('YII_DEBUG', false); comes in handy it checks if YII_DEBUG was true or false, if it finds YII_DEBUG has already been set to true or false somewhere else then it doesn't executes the or part.
This defined('YII_DEBUG') or define('YII_DEBUG', true); is equivalent to
if (!defined('YII_DEBUG')) {
define('YII_DEBUG', true);
}
So, you see it checks if YII_DEBUG has been defined somewhere else, if not then it sets to true in this case.
Edit:
To debug any page on the fly, you can just do this:
if (isset($_GET['debug'])) define('YII_DEBUG', true);
of course you will have to change your url then, for example:
www.example.com/site/myAction to www.example.com/site/myAction/debug/true
and remove it from index.php
EDIT 2:
Its not mandatory to define YII_DEBUG in index.php, it is aleady defined in Yii applications, you can find it in root yii.php file in case of Yii2 and in case of Yii1 its defined in framework/YiiBase.php
The
<?php
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
are defined in yourApp/web/index.php
and this costant define a level of debug info.
In development enviroment normally this flag is set to true and then in in case of error there are show detailed information regarding the error and the code gerating the error, if false not or few information are show.
Tipically in production eviroment this costant is set to false. so minus information are show to the user.
for the defined or define
is the costant is already defined the not need define otherwise php define the constat. see php doc http://php.net/manual/en/function.defined.php
defined — Checks whether a given named constant exists
You can find more information in Yii2 doc http://www.yiiframework.com/doc-2.0/guide-runtime-handling-errors.html
The error handler adjusts the error display according to the value of the constant YII_DEBUG. When YII_DEBUG is true (meaning in debug mode), the error handler will display exceptions with detailed call stack information and source code lines to help easier debugging. And when YII_DEBUG is false, only the error message will be displayed to prevent revealing sensitive information about the application.
Have a look at YII_DEBUG and YiiBase.php and yii.php
defined('YII_DEBUG') or define('YII_DEBUG', false) checks if the constant YII_DEBUG was defined (regardless of its value), and if it wasn't defined earlier it defines the constant as false.
The line ensures the constant is defined so it can be used and its first part (defined('YII_DEBUG') or) ensures this line won't override it to false if it was set to true earlier.
I'm trying to allow admin to create pages on the root path. So far i have:
get ':path' => "pages#show" ,:as =>:page, :path => /[^\.]+/
Basically i'm trying to ignore all paths with a dot in them (like .png). This does not seem to work as everything is rejected (i only want things in the public directory to be rejected, like fonts, icons, images..)
Thanks
As I explained in my comment above, "everything in public is directly rendered by the webserver" is NOT true if the desired asset does not exist. This will result in your catch-all route catching this undesired side-effect. This could cause a number of problems, as I explained. So, A specific catch-all route is needed to compensate for this:
get ':path' => "pages#show", :as => :page, :constraints => lambda{|req| req.path !~ /\.(png|jpg|js|css)$/ }
you can manipulate the regex how ever you see fit as my goal was just to get you on the right track by showing you that you can pass a block to the :constraints option. Also, I didn't just test req.format because that would exclude requests with header information for js format and would result in the catch all not working for these types of requests (not a usual case for a catch-all, but that's irrelevant). By using req.path instead, the header info is left intact/working and the path dictates whether or not this request is caught by this route.
I hope this helps you.
TESTING:
To test to see if your catch-all is actually catching what you want and not additional public resources, follow these steps. First put a debugger in your catch-all action, in your PagesController. Then make a request to a public file png/js/css file that DOES exist, like localhost:3000/images/example_image.png, and it should not hit your catch-all, as usual. Now, change the path to an image that doesn't exist, localhost:3000/images/no_image.png . If the request does not hit your debugger, your catch-all is not catching the image file request, and your ALL SET. If the request does hit your debugger, that means your catch-all is catching the image file request which means you need to revise your constraints in your catch-all.
By default dynamic segments don’t accept dots – this is because the
dot is used as a separator for formatted routes. If you need to use a
dot within a dynamic segment add a constraint which overrides this –
for example :id => /[^/]+/ allows anything except a slash.
http://guides.rubyonrails.org/routing.html#bound-parameters
So just removing the condition works. There might be another better solution to this problem though.
The website that im trying to make it work on is http://www.phone7forum.com/
The way I get it to show up on the index page is adding this code to the core index.php page right below this:
// Assign index specific vars
'S_AVATAR' => get_user_avatar(
$user->data['user_avatar'],
$user->data['user_avatar_type'],
$user->data['user_avatar_width'],
$user->data['user_avatar_height']
),
Then I can use {S_AVATAR} in my template but it ONLY shows up in the index file... So another phpbb guy suggested that I take that same code from above and place it in the includes/functions.php file right below this:
// The following assigns all _common_ variables that may be used at any point in a template.
I did that, and though it seemed to "try" and work I clicked on a few pages outside the index page and got a fatal error message:
Fatal error: Call to undefined function get_user_avatar() in /home/content/04/6534704/html/phone7forum/includes/functions.php on line 4385
Does anyone have any ideas?
IIRC get_user_avatar() is a function from functions_display. If you want to use it in the functions file, you have to include it.
Put it into an if condition to have it only load if you're on a page where function_display isn't already included:
if(!function_exists('get_user_avatar')){ include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx); }