Yii multisort in CArrayDataProvider - yii

Does Yii supports built in multi column sort for CArrayDataProvider(Yii 1.1.2), if yes please let me know how we can do, i'm new to yii.
Thank You.

Try the following (Yii API Doc example):
$dataProvider=new CArrayDataProvider($rawData, array(
'id'=>'user',
'sort'=>array(
'multiSort'=>true,
'attributes'=>array(
'id', 'username', 'email',
),
),
'pagination'=>array(
'pageSize'=>10,
),
));

Related

Yii2: How to log SQL query?

I want to log every SQL query executed so I can debug it and then copy, paste and test it in my database tool.
I tried this solution (Yii - echo the last query) (and other similar solutions) but it is not working because I think it is for Yii1. I need it for Yii2.
I think the solution is independent of the database (I use PostgreSQL).
Maybe I have to configure it in the common/config/main-local file.
If you need in Yii (1), please update your components array in main.php like this
'components'=>array(
#/*
'fixture'=>array(
'class'=>'system.test.CDbFixtureManager',
),
#*/
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=intakes_manager_test',
'emulatePrepare' => true,
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'enableProfiling'=>true,
'enableParamLogging'=>true,
),
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
'levels'=>'error,trace,info,warning',
//'filter'=>'CLogFilter',
'categories'=>'system.db.*',
'logFile'=>'sql.log'
)
)
),
),
For the same in Yii 2, do like below
'components' => [
'log' => [
'targets' => [
'file' => [
'class' => 'yii\log\FileTarget',
],
'db' => [
'class' => 'yii\log\DbTarget',
],
],
],
to know more about yii 2 logging see doc here
postgresql.conf
log_min_duration_statement = -1 # -1 is disabled, 0 logs all statements
log_min_duration_statement = 0
You would need to restart the Postgresql service

realurl config for tt_news in TYPO3 6.2

For TYPO3 6.2 I cannot manage to have real url setup for tt_news. I use bootstrap package 6.2.8 , realurl 1.12.8 and tt_news 3.6.0.
I get url :
.../blog/articol.html?tx_ttnews[tt_news]=11&cHash=d92d53eafcb2e8c331829520e053c3c7
and should be :
.../blog/articol/title/
I try to add configuration used in version 4.5.32 but nothing was changed.
Any clues on how I should solve it?
check path to your realurlconf.php or real_urlconf.php config file in the extension config
add 'noMatch' => 'bypass' in
'preVars' => array(
array(
'GETvar' => 'no_cache',
'valueMap' => array(
'no_cache' => 1,
),
'noMatch' => 'bypass',
),
also for me day was missing!
array('GETvar' => 'tx_ttnews[day]' ,
'noMatch' => 'bypass',),

git ignore Yii database details

Some of the details in the main.php needed by all application instances (URL details) and some details will be specific to each application instance (database details).
Is there any idea to separate the database details from protected/config/main.php?
Just include the shared configuration from another PHP file:
main.php:
return array
(
....
'components' => array
(
'db' => include('sharedDatabaseConfiguration.php');
)
);
sharedDatabaseConfiguration.php:
return array('host' => ...);
You might have to add a path or something, depending where the file is stored.
Edit: Btw, Yii also has a fancy CMap::mergeArray() function that can do something similar (in case you want to "augment" the contents of a single config file with that from another one. Look at the default generated console.php for an example of that.
You can find an idea here: Manage application configuration in different modes .
Basically it works by importing a different PHP file (your db configuration) and merging the includedarrays:
<?php
return CMap::mergeArray(
require(dirname(__FILE__).'/db-config.php'),
array(
'basePath' => dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name' => 'Page Title',
...
)
);
?>
You can use separate configuration file (e.g. protected/config/production.php), that is based on your main configuration file and that overrides some settings using CMap::mergeArray as this answer suggests:
return CMap::mergeArray(
require(dirname(__FILE__) . '/main.php'),
array(
'components' => array(
'db' => array(
'connectionString' => '...',
'username' => '...',
'password' => '...',
),
),
)
);
Then you can add protected/config/production.php to .gitignore.

Using Bundles in Laravel Migrations

I want to use sentry 1.x with Laravel 3.x in the migrations I use, but when I try to migrate I get this error:
PHP Fatal error: Class 'Sentry' not found in /var/www/laravel.dev/application/migrations/2013_03_06_183713_add_user_to_database.php on line 34
This is what I try to do in function up():
$user_id = Sentry::user()->create(array(
'email' => 'admin#test.com',
'password' => 'testpass',
'metadata' => array(
'first_name' => 'Test',
'last_name' => 'Test'
)
));
What am I missing ?
p.s: I know having the password in PHP is insecure, this is just a test environment.
Thanks,
You need to start the bundle.
Bundle::start( 'sentry' );
Add 'Cartalyst\Sentry\SentryServiceProvider' to the list of service providers in app/config/app.php

YouTube API Upload Video as 'Unlisted' or 'Private'?

I am using a Wordpress plugin called 'YouTube Uploader', it allows you to upload YouTube videos from your WordPress site, it is working for me but the only issue is that it uploads the videos as Public and I need them to go up as Unlisted or Private (either will do). If someone could tell me what to add/change to make it do this, it would be greatly appreciated, thanks!
I uploaded the code to Pastebin as I didn't want to fill this entire post with code, heres the link: http://pastebin.com/GfQjhiiq
Thanks!
I'm not that clued up on Wordpress but what you're looking for is a tag called <yt:private/>
<yt:private/> is a child of media:group so a sample xml schema could look something like the following. (Note where <yt:private/> sits within the code block):
<media:group>
<media:title type="plain">Title here</media:title>
<media:description type="plain">Description here</media:description>
<media:category scheme="http://gdata.youtube.com/schemas/2007/categories.cat">Travel</media:category>
<media:keywords>keyword1</media:keywords>
<yt:private/>
</media:group>
Hope this is of some use.
I think this method is pretty outdated. But there is a work around if you were to use the the Plain PHP API method...
This Part does the trick:
// unlisted upload
$accessControlElement = new Zend_Gdata_App_Extension_Element('yt:accessControl', 'yt', 'http://gdata.youtube.com/schemas/2007', '');
$accessControlElement->extensionAttributes = array(
array(
'namespaceUri' => '',
'name' => 'action',
'value' => 'list'
),
array(
'namespaceUri' => '',
'name' => 'permission',
'value' => 'denied'
));
$myVideoEntry->extensionElements = array($accessControlElement);
In the bigger scheme:
$this->Zend->loadClass('Zend_Gdata_ClientLogin');
$this->Zend->loadClass('Zend_Gdata_YouTube');
$client = Zend_Gdata_ClientLogin::getHttpClient(ZEND_GDATA_CLIENT_EMAIL, ZEND_GDATA_CLIENT_PASS, 'youtube');
$client->setHeaders('X-GData-Key', "key=".ZEND_GDATA_YOUTUBE_DEVELOPER_KEY);
$yt = new Zend_Gdata_YouTube($client);
$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
// unlisted upload
$accessControlElement = new Zend_Gdata_App_Extension_Element(
'yt:accessControl', 'yt', 'http://gdata.youtube.com/schemas/2007', ''
);
$accessControlElement->extensionAttributes = array(
array(
'namespaceUri' => '',
'name' => 'action',
'value' => 'list'
),
array(
'namespaceUri' => '',
'name' => 'permission',
'value' => 'denied'
));
$myVideoEntry->extensionElements = array($accessControlElement);
$myVideoEntry->setVideoTitle('My Test Movie');
$myVideoEntry->setVideoDescription('My Test Movie');
$myVideoEntry->setVideoCategory('Sports');
The whole Gist is over here: https://gist.github.com/1044349