I am starting to learn Yii framework. In the tutorial video i copied the code where were using setFlash for error messages on a form. I have inspected the code a lot of times and im pretty sure its identical to the video however i keep getting an error message that is referring to this line:
Yii:app()->user->setFlash('failure', "There was a problem saving the data!");
The error says:
Fatal error: Label 'Yii' already defined in C:\wamp\www\photogallery\protected\controllers\AlbumController.php on line 77
public function actionCreate()
{
$model=new Album;
// Uncomment the following line if AJAX validation is needed
$this->performAjaxValidation($model);
if(isset($_POST['Album']))
{
$model->attributes=$_POST['Album'];
if($model->save()){
Yii:app()->user->setFlash('saved', "Data saved!");
$this->redirect(array('update','id'=>$model->id));
} else{
Yii:app()->user->setFlash('failure', "There was a problem saving the data!");
}
}
$this->render('create',array(
'model'=>$model,
));
}
Maybe its a typo im missing but its exactly the same as the video tutorial and it seems to work for him and i took a look at some other similar code online and it seemed to use 2 instances of Yii:app() in an if/else statement. The error message didnt return any similar issues on google so im guessing its something simple
You need to use a double colon, not single, when using the static method.
Yii::app() not Yii:app()
Related
I've run into this issue before, but I can't remember how to solve it. I have created a bare bones (can't get any simpler) controller, and am just trying to echo something to the browser, and I am getting this message:
Fatal error: Uncaught exception 'Zend_Session_Exception' with message 'Session must be started before any output has been sent to the browser ...
Here's my entire controller. It's displaying 'success', but it also displays the error message. How can I silence that error message so I can simply echo something to the browser?
<?php
class CacheController extends Zend_Controller_Action
{
public function clearAction()
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
try {
$result = Model_Cache::emptyCache(array('foobar'=>1));
if ($result['status'] == true) {
echo 'Success';
} else {
echo 'Error: ' . $result['message'];
}
} catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}
}
}
From memory, this error is usually due to non-PHP code starting the output before intended (and session initialisation). Usually it's due to whitespace or carriage returns after unnecessary ?> tags. This is the first thing I'd check for.
What the error sounds like it is saying is that you are not starting the Zend_Session before data is being sent to the browser. Typically I have something like I pasted below in my bootstrap to start the Zend_Session.
protected function _initSessions()
{
Zend_Session::start();
}
That should get you going in the Zend Framework. If you are using this tool outside the framework just use that inner line of code near the top of your PHP scripts before you echo or print anything.
Hope that helps!
I found a similar post on this problem:
PHPUnit output causing Zend_Session exceptions
I had the same problem but the solution that was proposed on the previous link did not worked for me, so after some testing I found that there is a variable on the class Zend_Session
/**
* Whether or not Zend_Session is being used with unit tests
*
* #internal
* #var bool
*/
public static $_unitTestEnabled = false;
If you set this variable to "true" the phpunit execution works without any problem. At least that is what happened in my case.
Hope this help
I encountered same problem and my issue was that I was echoing a STRICT warning that was being put to the screen.
A good way to debug this is issue is the use ob_start() and ob_get_contents();
Hope it helps
For some reason, I was trying to set some session variable in my index.php file after the application had finished bootstrapping. Not sure why this didn't cause a problem before, but when I removed this from my index.php, it worked.
$userSession = new Zend_Session_Namespace('Auth');
$userSession->forcePasswordChange = false;
Possible the session is started through your application.ini or php.ini (session autostart) ? If you use an ide try to search for "spaces".
Sometimes searching for " " (with spaces) helps.
I had the same error message. But only for one action. Problem has been caused by these two lines in controller's action:
$customersModel = new Default_Model_DbTable_Customers();
$this->view->customers = $customersModel->fetchAll();
In my database were more than 6000 customers. So it is not good to push a lot of records to view.
Please forgive me if this is a duplicate question. I have searched but cant come up with an answer.
I am getting a PHP fatal error: call to undefined in my Wordpress site.
I know why this is, I am calling a method in my template file that is defined in a plugin - if the plugin isnt installed, then the template throws the error.
Is there any way I can encapsulate this method so that if it fails, the fatal error doesnt stop the rest of the page loading?
Many thanks.
You can check if the function is defined before calling it.
<?php
if (function_exists('plugin_function')) {
plugin_function();
} else {
error_log('plugin is not activated');
die();
}
?>
I am running an Ajax tutorial example and a line gives error in controller file. What I'm doing is if a field is blank and user blurs out of it an error will display below the field.
Here is the whole function in MessagesController.php
public function validate_form()
{
if($this->RequestHandler->isAjax())
{
$this->request->data['Message'][$this->request->params['form']['field']] = $this->request->params['form']['value'];
$this->Message->set($this->request->data);
if($this->Message->validates())
{
$this->autoRender = FALSE;
}
else
{
$error = $this->validateErrors($this->Message);
$this->set('error', $error[$this->request->params['form']['field']]);
}
}
}
The error line is this:
$this->request->data['Message'][$this->request->params['form']['field']] = $this->request->params['form']['value'];
And error is this
Undefined index: form [APP\Controller\MessagesController.php, line 30]
Actually the tutorial was based on previous version of Cake but I have made proper changes compatible with current version but still error shows. Can someone please tell me what might be wrong in this line or elsewhere in the code. Thanks a lot.
$this->request->params does not contain a form index.
I think you should be looking at your $this->request->data?
$this->request->params has only information about your request: the action, the controller, any named parameters and so on.
The error you get is actually normal.
Add comment with link to tutorial.
I have been looking around and following each tutorials,there is one which stands out. http://blog.lysender.com/2011/02/kohana-3-1-migration-custom-error-pages/ <-- i followed this tutorial and everything went smoothly
the error is being detected
the exception is being handled
but there has been an exception that i cant seem to find. im currently having this exception
Fatal error: Exception thrown without a stack frame in Unknown on line 0
all of my codes are thesame to the site-link. please help me.. im bugging around for this since ever, i've looked through here also Kohana 3 - redirect to 404 page but since im a beginner, its really hard understanding it. I've also found out that there is a major revamp from KO 3.0 to 3.1 how about KO 3.2? Thank you for your help guys :)
From the kohana source-code.
- > If you receive *Fatal error: Exception thrown without a stack frame in Unknown on line 0*, it means there was an error within your exception handler. If using the example above, be sure *404.php* exists under */application/views/error/*.
Maybe it helps. This probably has been fixed, but I'm not following the kohana development that much. It's related to pull request #246: https://github.com/kohana/core/pull/246 and this is the source: https://github.com/kohana/core/pull/246/files#L208L76
here is how I do it with Kohana 3.2
Add exceptions handling stuff in index.php
try
{
$request = $request->execute();
}
catch(Kohana_HTTP_Exception_404 $e)
{
$request = Request::factory('errors/404')->execute();
}
catch(Exception $e)
{
$request = Request::factory('errors/500')->execute();
}
echo $request->send_headers()->body();
Then write Errors controller
class Controller_Errors extends Controller
{
public function __construct($request, $response)
{
parent::__construct($request, $response);
}
public function action_404()
{
$this->response->body(View::factory('errors/404'));
}
public function action_500()
{
$this->response->body(View::factory('errors/500'));
}
}
Create 2 corresponding error pages (404.php and 500.php in views/errors)
Add new route to your bootstrap.php or use default one (depends on you project's structure), just make sure Controller_Errors can be reached when exception is thrown
Now every time you throws the exception in your controller, it will display the custom error page, like this
throw new HTTP_Exception_404;
I was trying to implement some new functionality, decided not to, tried to roll back, and now am stuck with this error:
Fatal error: Call to a member function insert() on a non-object in /app/code/core/Mage/Core/Model/Mysql4/Resource.php on line 96
The functionality I mentioned seems simple enough (remove a couple links from the customer account sidebar), and I believe I've removed the 3 files and the edit to local.xml, but just for full view on things, here's exactly what i did.
Add'l info: I've got one custom module in place that I built for this site, and it was working prior to this glitch, but I'm wondering if something got screwed up in there maybe? (And I'm also thinking I might not have committed my last/working change, and now I'm in "doubt" territory about whether I screwed that up. It's a simple one though: 1 controller, 1 route.)
I've got no access to PHP error logs or the shell (exec() works great though), and the /var/system.log isn't adding anything more on my subsequent page-refreshes. And so this is where I'm stuck - Got any ideas on how to track this down? Thanks in advance!
Edit / here's the function that's throwing the error:
function setDbVersion($resName, $version)
{
$dbModuleInfo = array(
'code' => $resName,
'version' => $version,
);
if ($this->getDbVersion($resName)) {
self::$_versions[$resName] = $version;
$condition = $this->_write->quoteInto('code=?', $resName);
return $this->_write->update($this->_resTable, $dbModuleInfo, $condition);
}
else {
self::$_versions[$resName] = $version;
// this is line 96:
return $this->_write->insert($this->_resTable, $dbModuleInfo);
}
}