Disable notice yii - yii

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);

Related

POST Request working with / at the end of URL but not without /

I have a small script on my server to catch a POST request, like this:
<?php
$jsonformat = json_encode($_POST);
$jsonFile = fopen("data.json", "w") or die("Unable to open file!");
fwrite($jsonFile, $jsonformat);
fclose($jsonFile);
echo "success";
?>
Above script is named index.php and placed in http://example.com/data/report/
I have another script for sending the POST request like this:
<?php
$url = 'http://example.com/data/report/';
$data = array('key1' => 'value1', 'key2' => 'value2');
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
var_dump($result);
?>
The two script are working great. But in another situation the $url is like this: 'http://example.com/data/report' Notice no "/" at the end of the url. In the situation without "/" at the end the json-file on server is still generated but it is empty.
I have no possibility adding the "/" to the url. Its a device where I can not edit the code but I know it is missing "/" at the end so code above is just my example. I have reproduced the issue, I think.
So my question is:
- Why is it working with "/" but not without?
- Can I do anything on the server so http://example.com/data/report will be the same as http://example.com/data/report/
I have access to .htaccess on the server
Have you got a .htaccess file or anything that is rewriting your URLs?
For example I have a line in mine like:
RewriteRule ^([^\.]+)$ $1.php [L,NC,QSA]
This removes the file extension from the browser URL bar. So if I go to mywebsite.com/mydirectory/myfile it will automatically presume it means mywebsite.com/mydirectory/myfile.php.
If I went to mywebsite.com/mydirectory it would try to rewrite this as mywebsite.com/mydirectory.php unless I put the / at the end so it knows it's a directory.

how to display image in yii using CHtml::image()?

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); ?>

Flash Message in YII Framework

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
),
)); ?>

Session variables don't get passed to the third page after session start

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"];

Joomla User login check

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