i have stored pdf.png in C:\wamp\www\pipelinespark\images\pdf.png
i have used $imghtml=CHtml::image('pdf.png');
then i getting error like.
"NetworkError: 404 Not Found -
pipelinespark/administrator/index.php/spark/pdf.png".
Thanks in advance.
This works for me!
<?php
echo CHtml::image(Yii::app()->request->baseUrl.'/path_to/images /'."$model->logo","$model->Name",array('width'=>100,'height'=>100));?>
<?php echo CHtml::image(Yii::app()->baseUrl . "/images/" . $data->image); ?>
Where $data is the returned value form actionIndex
All of them works for me
<?=CHtml::image(Yii::app()->request->baseUrl."/path-to-images/logo.png", "LOGO")?>
<?=CHtml::image(Yii::app()->baseUrl."/path-to-images/logo.png")?>
<?php echo CHtml::image(Yii::app()->basePath."/../images/profile-image/".$data->avatar); ?>
Related
After I send the request, I will announce the result to the user via SET FLASH. What is the way to show a message when the user sends a request?
For example when sending a message form : Display -> form is being send and then a flash message is displayed
Check the wiki on the Yii framework website:
http://www.yiiframework.com/wiki/21/how-to-work-with-flash-messages/
In your controller you can put:
Yii::app()->user->setFlash('success', "Form posted!");
In your view you can echo the flash message by:
<?php echo Yii::app()->user->getFlash('success'); ?>
Optionally you can check if a flash message exists by using the hasFlash method, so the code in your view would look like this:
<?php if(Yii::app()->user->hasFlash('success')):?>
<?php echo Yii::app()->user->getFlash('success'); ?>
<?php endif; ?>
Add setFlash in your controller. Something like this:
if($comment->save())
{
Yii::app()->user->setFlash('commentSubmitted','Thank you for your comment.');
$this->refresh();
}
And in your views, display flash message something like this:
<?php if(Yii::app()->user->hasFlash('commentSubmitted')): ?>
<div class="flash-success">
<?php echo Yii::app()->user->getFlash('commentSubmitted'); ?>
</div>
<?php endif; ?>
In your controller you can put:
if(conditions)
Yii::app()->user->setFlash('success', "Success text");
else
Yii::app()->user->setFlash('error', "Error text");
In your view you can echo the flash message by:
<?php
if(Yii::app()->user->hasFlash('success'))
Yii::app()->user->setFlash('success', '<strong>Well done!</strong> '.Yii::app()->user->getFlash('success').'.');
else
Yii::app()->user->setFlash('error', '<strong>Error!</strong> '.Yii::app()->user->getFlash('error').'.');
$this->widget('bootstrap.widgets.TbAlert', array(
'block'=>true, // display a larger alert block?
'fade'=>true, // use transitions?
'closeText'=>'×', // close link text - if set to false, no close link is displayed
'alerts'=>array( // configurations per alert type
'success'=>array('block'=>true, 'fade'=>true, 'closeText'=>'×'), // success, info, warning, error or danger
),
)); ?>
after starting a new session in my login.php i rediredct to home.php and load session variables successfully.But when i try to open menu.php from home.php and use session variables , those same variables are unndefined now. I echoed the session id after both page changes and its exactly the same. So can anyone please tell me why am i losing these variables?
login.php:
session_start();
$_SESSION["user"]=$puser;
$_SESSION["loggedin"]=true;
echo "<script>window.open('../home.php','_self')</script>";
?>
home.php
require("php/objects.php");
session_start();
if(isset($_SESSION["loggedin"]) && $_SESSION["loggedin"]==true)
{
$user=$_SESSION["user"];
$_SESSION["loggedin"]=true;
echo session_id();
echo $_SESSION["loggedin"];
}
else
{
echo "Login Error";
echo "<script>window.open('default.html','_self')</script>";
exit();
}``
?>
menu.php
require("objects.php");
session_start();
echo session_id();
echo $_SESSION["loggedin"];
/*if(isset($_SESSION["loggedin"]) && $_SESSION["loggedin"]==true)
{
$user=$_SESSION["user"];
$utype=isset($user->salary)?"staff":"client";
}
else
{
echo "Login Error";
echo "<script>window.open('../default.html','_self')</script>";
exit();
}*/``
?>
when i click a link in home.php with href=menu.php i get an error that index loggedin is undefined
I don't know what is in your objects.php, calling session should probably come before that.
session_start();
require("objects.php");
echo session_id();
echo $_SESSION["loggedin"];
How disable notice , i try in idex.php But Notice is echo , how i can disable this .
<?
define("YII_ENBLE_ERROR_HANDLER",false)
define("YII_ENBLE_EXCEPTION_HANDLER",false)
?>
in php.ini
<?display_errors = off ?>
Update public/index.php
<?php
define('YII_ENABLE_ERROR_HANDLER', false);
define('YII_ENABLE_EXCEPTION_HANDLER', false);
// Turn off all error reporting
// error_reporting(0);
// Report all errors except E_NOTICE
// This is the default value set in php.ini
error_reporting(E_ALL ^ E_NOTICE);
I would like to get content (posts) from a google+ page and post it to my website, as a feed. Is there any info how?
I read that current API does not allow that, but those topics were from the last year.
Thanks.
You can perform activities.list, without having to authenticate, by passing your "simple" key from the API console for a project created that has the Google+ service turned on. Access to the API calls is restricted to the authorized origins you set up in your project.
After you create the project, in the section "Simple API Access" there is an API key. Build your client with this key, your client id, and client secret:
<?
$client = new Google_Client();
$client->setDeveloperKey("YOUR_API_KEY");
$plus = new Google_PlusService($client);
$activities = $plus->activities->listActivities("+GooglePlusDevelopers", "public");
?>
<html><body><pre><? echo print_r($activities);?></pre></body></html>
A final note, make sure you use the latest Google+ PHP client.
After some time I found it.
http://code.google.com/p/google-plus-php-starter/
and this
https://developers.google.com/+/api/latest/activities/list
The only problem is that you need to log into your google app to do this. Any sugggestions would be apprecited.
Updating the correct answer, the class name has changed to Google_Service_Plus
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__ .'/vendor/google/apiclient/src');
require_once __DIR__.'/vendor/autoload.php';
$client = new Google_Client();
$client->setDeveloperKey("YOUR_API_KEY");
$plus = new Google_Service_Plus($client);
$activities = $plus->activities->listActivities("+GooglePlusDevelopers", "public");
?>
$items = $activities->getItems();
foreach($items as $item) {
$object = $item->getObject();
?>
<div class="gpost">
<p><?php echo $object->getContent(); ?></p>
Read more
</div>
<?php } ?>
First I am not a joomla developer. My friend has a web site created with joomla 1.5. In webroot there are some joomla files. I created a directory in webroot "mydirectory" and i have an index file in this directory. I try to access joomla's user info in this page i grab the user object but it doesn't work.
//i included joomla core files
$user =& JFactory::getUser();
if ($user->get('guest')) {
echo 'guest';
} else {
echo 'not guest';
}
when I log in to my account, it says 'guest' again.
Also, I can't find anything in Joomla's session class.
$session =& JFactory::getSession();
Thanks
You should do this:
$user =& JFactory::getUser();
if (!$user->guest) {
echo 'You are logged in as:<br />';
echo 'User name: ' . $user->username . '<br />';
echo 'Real name: ' . $user->name . '<br />';
echo 'User ID : ' . $user->id . '<br />';
}
This is from here: http://docs.joomla.org/JFactory/getUser
Try print_r($user) to see what items you are getting back.
Try to check for $user->id
See if you are missing including any file e.g. framework.php