It seems Yii::t can't work with variables. I was wondering is there any solution or workaround to do something like this:
foreach ($dicts as $dict) {
echo Yii::t($dict,$someRandomWord);
}
Tested it right now. It works fine! I promise, your locales or your $category is unknown/notset. Is your message file ok?
Check this:
http://www.yiiframework.com/wiki/243/how-to-translate-and-do-the-translations-the-easy-way/#hh1
//current language is turkey, system language is english
$category = 'app';
$message = 'english';
echo Yii::t($category, $message);
//İngilizce
Related
Actually,
I have written this code in AppController.php in CakePHP 2.2.2
class AppModel extends Model
{
function getLastQuery()
{
$dbo = $this->getDatasource();
$logs = $dbo->getLog();
$lastLog = end($logs['log']);
return $lastLog['query'];
}
}
I tried following code to print output query
echo $this->AssetModel->getLastQuery();
$this->render('sql');
Is any body know to the point solution for that....?
I use this in CakePHP 2.6.11 to print Queries from Model in browser
debug($this->YOURMODEL->getDataSource()->getLog(false, false)); exit;
Hi you can use the below line to put into your layout file
<?php echo $this->element('sql_dump'); ?>
this will print all running query running in current action.
You can also use cakephp debugkit plugin.
I am trying to list applications installed on particular server below command works fine on WAS 6.x and 7 however I cannot make the same on WAS 5.x
wsadmin> $AdminApp list /WebSphere:cell=cell01,node=node01,server=server1/
Also, $AdminApp help list does not show optional scope parameter.
Could you please advise ?
Thanks
I don't have access to v5 right now to test, but something like this might work:
proc listAppsByTarget {target} {
global AdminApp
set result []
regsub -all / $target "" target
foreach app [$AdminApp list] {
foreach line [split [$AdminApp view $app -MapModulesToServers] "\r\n"] {
if [regexp "^Server: ${target}($|,)" $line] {
lappend result $app
break
}
}
}
return $result
}
This will print any application that has a module targetted to the specified server. Used like this:
wsadmin>listAppsByServerTarget /WebSphere:cell=cell,node=node,server=server1/
DefaultApplication
I found the way, however it's not the same output, it needs to be parsed to get the details.
wsadmin > $AdminControl queryName type=Application,node=node01,process=server1
In case there is another way please let me know.
Currently Im trying to use elliots twitter library for CI at http://www.haughin.com/code/twitter/ after installation, it went well. the source code worked well..
Then I try to add code at index() function which is like this :
function index()
{
echo 'hi there';
$user = $this->tweet->call('get', 'account/verify_credentials');
$dec = json_decode($user);
}
I tried to decode json by using json_decode() function but it return error
json_decode() expects parameter 1 to be string, object given
This is my first time working with json..
Is there something I missed out ?
Thank you..
You should juggling that object into string type...
$user = (string) $this->tweet->call('get', 'account/verify_credentials');
$dec = json_decode($user);
It doesn`t need any variable convertion.
just access object directly like $dec->username
I'm using Codeigniter 2.0.1 and I'd like to put an variable in a language line. For example: if an user wants to register an account, and that username already exists I would like to put in my language line "This username $username is alrady in use". I saw in the validation error language lines that they used %s as variable. But if I put this in my custom authentication error lang file I just get a plain %s instead of a variable.
It doen't look like it is possible with the default Lang class. Personally I did it that way.
First a i18n_helper :
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
if ( ! function_exists('line_with_arguments'))
{
function line_with_arguments($line, $swap)
{
return str_replace('%s', $swap, $line);
}
}
and then I call it in my controller :
<?php
class Home extends CI_Controller
{
public function index()
{
$this->lang->load('test', 'english');
$this->load->helper('i18n');
echo line_with_arguments($this->lang->line('test'), 'Matt');
}
}
and my lang file :
<?php
$lang['test'] = 'Hello %s';
I am trying to create a method in PHP, that will dynamically bind parameters to a PDO query statement. Unfortunately, in my code below, i can only bind 1 parameter, because adding more parameters will override the previous parameters. Nevertheless, is there a good way to fix this problem?
I hope someone can help. Thanks!
function executeQuery($query, $critArr = null) {
$rows = array();
try {
$stmt=$this->pdo->prepare($query);
if (!empty($critArr)) {
foreach($critArr as $cKey=>$cValue) {
$stmt->bindParam($cKey, $cValue); //!!
}
}
$stmt->execute();
You don't need to do that. The execute method already takes an array of parameters:
function executeQuery($query, $critArr = null) {
$rows = array();
try {
$stmt=$this->pdo->prepare($query);
$stmt->execute($critArr);
// ...
The original problem is that bindParam works by reference, and foreach simply reuses the same variables over and over rather than destroy them at the bottom of the loop and (re)create them at the top. You were effectively re-binding the same variable over and over. (Incidentally, this is the same problem that the mysqli extension has, while it also lacks the convenient already-takes-an-array execute method.)
Your function improved with passing foreach $cValue by reference &$cValue. This should solve your problem.
function executeQuery($query, $critArr = null) {
$rows = array();
try {
$stmt=$this->pdo->prepare($query);
if (!empty($critArr)) {
foreach($critArr as $cKey=>&$cValue) {
$stmt->bindParam($cKey, $cValue); //!!
}
}
$stmt->execute();