I have used Codeigniter before and it has a feature that will echo the last database query - really useful for debugging.
eg...
$this->getSomeData->findAll();
Yii command to output this single query e.g SELECT * FROM TABLE...
Does Yii have a similar feature to simply show the very last query executed?
Try this in your config file. You can see the query and other details at the bottom of the page.
'db'=>array(
'enableProfiling'=>true,
'enableParamLogging' => true,
),
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
…
array(
'class'=>'CProfileLogRoute',
'levels'=>'profile',
'enabled'=>true,
),
),
),
Related
I am using Sonata Page Bundle to build a set of page with information about items -- one item per page. On each page, I want to include multiple synonyms for the item. I have created a Synonym entity with two fields.
I now want to use an add() method within my configureFormFields definition to add a reference to my new Synonym entity. The following code yields an error saying that The current field 'Synonym' is not linked to an admin. Please create one for the target entity : '':
->add('Synonym', 'sonata_type_collection', array(
'label' => "Synonyms",
'cascade_validation' => true,
'required' => false
), array(
'edit' => 'inline',
'inline' => 'table'
))
... and I have tried modifying the code so it looks like:
'cascade_validation' => true,
'required' => false,
'target_entity' => 'AppBundle\Entity\Synonym'
), array(
... which results in the same error.
How do I tell my admin class that this is a reference to a set of Synonym objects that I want to edit inline?
Edit:
I have also tried
'targetEntity' => 'AppBundle\Entity\Synonym'
... with no luck. The application is still seemingly having trouble figuring out what the entity I'm targeting is.
An at least partial answer was found in adding an "admin_code" definition to my array, as described at
https://symfony.com/doc/master/bundles/SonataAdminBundle/reference/form_types.html
I still get an error, but it is now at least a different error.
Yii framework 1.1.14
I have set the following in my controller:
public function accessRules()
{
return array(
array(
'deny',
'controllers' => array(
'site',
'hotels',
'channels'
),
'roles' => array('General')
)
);
}
I have created a custom CDbAuthManager called CDbAuthManagerExtension, declared in config/main.php:
'authManager' => array(
'class' => 'CDbAuthManagerExtension',
'connectionID' => 'db'
),
In CDbAuthManagerExtension I have declared my getRoles($user_id) function.
But when I run the code I get the following error:
CDbCommand failed to execute the SQL statement: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'h2g.AuthAssignment' doesn't exist. The SQL statement executed was: SELECT *
FROM `AuthAssignment`
WHERE userid=:userid
I don't want to set up the AuthAssignments table and I don't see why it's looking at it when I've specified the roles in the accessRules function? Does anyone know how to stop it looking for the AuthAssignments table?
You are using a DbAuthManger meaning it has to lookup a DB table to get the assignments, it is not looking for the roles as such it is looking for the role assignments to users and determines whether the current user has the authorizations computed both based on the roles assigned to him and the roles that are allowed an action.
If you don't want to use the name AuthAssigment for the table and use another table you can specify it in your config like this
'authManager' => array(
'class' => 'CDbAuthManagerExtension',
'connectionID' => 'db'
'assignmentTable'=>'MyCustomTable'
),
There are two other tables you can modify their locations as well read CDbAuthManager doc here
If you however do not wish to have a table at all then you should not use the DbAuthManager and use the PHPAuthManager, which stores the assignment data in a php file as an array It is configured by CPhpAuthManager see doc here. You can extend this class with your customization and use it in your config instead
'errorHandler' => array(
'class' => 'ErrorHandler',
'errorAction' => 'page/find',
),
http://shot.qip.ru/008pAk-4IA4wMhU6/
I have standard error handling with beautiful error page. But for develop environment I need standard stacktrace on it below.
Examlpe: http://shot.qip.ru/008pAk-4IA4wMhU7/
If I comment 'errorAction' I can see just standart stacktrace, in other case I cant display this stacktrace.
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class' => 'CWebLogRoute',
'categories' => 'application, exception.*',
'levels'=>'error, warning, trace, profile, info',
'showInFireBug' => true,
'enabled' => YII_DEBUG,
),
array(
'class'=>'ext.yii-debug-toolbar.YiiDebugToolbarRoute',
'ipFilters'=>array('127.0.0.1','192.168.0.100'),
),
array(
'class'=>'CProfileLogRoute',
'report'=>'summary',
// Shows the execution time of each labeled with a code block.
// The value of "report" can also be specified as a "callstack".
),
),
),
Error handler by default uses two types of views for
Production named as error.php;
Development named as named as exception.php;
Based on your routing and error handler code. I see you have defined a custom error action
You will have to place your custom Errors views in either of the following folders, in the format specified in the link below and use the standard error action.
themes/ThemeName/views/system: when a theme is active.
protected/views/system
See this Documentation for detailed explanation
Reference: http://www.yiiframework.com/doc/api/1.1/CErrorHandler
Try this extenstion http://www.yiiframework.com/extension/yii-debug-toolbar/
The Yii Debug Toolbar is a configurable set of panels that display various debug information about the current request/response and when clicked, display more details about the panel's content.
It is a ported to PHP famous Django Debug Toolbar.
i have enabled profiling to be displayed in yii as below shown.
'db'=>array(
'connectionString'=>'pgsql:host=localhost;port=5432;dbname=ijob_css',
'username'=>'postgres',
'password'=>'allion123',
'enableProfiling'=>true,
'schemaCachingDuration'=>604800
),
but still i am not getting anything displayed under the pages of website and its empty.
before it worked and recently i swiotched off by
'enableProfiling'=>false
why doesn't it work ? i must be missing something.
Adding this to main config resolved the issue. 'class'=>'CProfileLogRoute',
'components'=>array(
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
'levels'=>'error, warning',
),
array(
'class'=>'CProfileLogRoute',
),
After extensive search on the web, I still can't figure this out. CWebLogRoute doesn't show SQL debug info, but CFileLogRoute does. Any ideas on how to get CWebLogRoute to work? Thanks!
Here is my config file:
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=myname',
'emulatePrepare' => true,
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'enableParamLogging'=>true,
'enableProfiling'=>true,
),
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
'levels'=>'error, warning, trace, info',
),
array(
'class'=>'CWebLogRoute',
'levels'=>'error, warning, trace, info',
),
)
Does it show at least something? It's working fine on my local. Try to add profile into CWebLogRoute.levels.
BTW I prefer CProfileLogRoute for sql:
array(
'class'=>'CProfileLogRoute',
'enabled'=> YII_DEBUG,
),
This doesn't directly answer your question, but I've found the Yii debug toolbar to be a fantastic add-on on a job I've been doing recently. It will display not only the SQL statements you are running (the literal ones, not the parameterized versions), but also has a lot of other information that you actually do need fairly regularly ...
You can get it here: http://www.yiiframework.com/extension/yii-debug-toolbar/
what's the version of your yii framework?
and set the levels '' .
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
// 'levels'=>'error, warning',
),
// uncomment the following to show log messages on web pages
array( // configuration for the toolbar
'class'=>'XWebDebugRouter',
'config'=>'alignRight, opaque, runInDebug, fixedPos, collapsed, yamlStyle',
// 'levels'=>'error, warning, trace, profile, info',
'allowedIPs'=>array('127.0.0.1','::1','192.168.10.195','192\.168\.1[0-5]\.[0-9]{3}'),
),
),
),