I am currently doing a site on cakephp 2.6.2.
I use a plugin for comments, as follows: Comment plugin.
Everything works fine until I try to add a comment to a post, it then returns the following error:
Strict (2048): Declaration of Comment::afterSave() should be compatible with Model::afterSave($created, $options = Array)
[APP/Plugin/Comment/Model/Comment.php, line 2]
I do not understand why this error is raised and how I can resolve it.
I searched issues already covered but I do not understand what how I should proceed. I try several times but without success: s
I have in comment.php:
public function afterSave($created){
if ($created) {
$model = ClassRegistry::init($this->data[$this->alias]['ref']);
// Manual countercache, it's more flexible, no need to add complex relation on Comment Model
if($model->hasField('comment_count')){
$model->id = $this->data[$this->alias]['ref_id'];
$model->saveField('comment_count',$this->find('count',array(
'conditions' => array('ref'=>$this->data[$this->alias]['ref'],'ref_id'=>$this->data[$this->alias]['ref_id'])
)));
}
$this->getEventManager()->dispatch(new CakeEvent('Plugin.Comment.add', $this));
}
}
and CommentsController.php:
$this->Comment->create($this->request->data, true);
the changes I've tried to do:
$this->Comment->create($this->request->data, true);
to $this->Comment->create($this->request->data);
or $this->Comment->create(controller $this->request->data, true);
I'm sorry but i'dont understand what i exactly have to do :s
Related
Running Joomla 3.3.0-dev
I'm following the info posted here about adding tag support to a third-party component.
I've added the content type to the #__content_types table and modified my table file like this:
class MycomponentTableElement extends JTable
{
public $tagsHelper = null; // failed when protected and public
public function __construct(&$_db)
{
parent::__construct('#__mycomponent', 'id', $_db);
// Add Joomla tags
JObserverMapper::addObserverClassToClass('JTableObserverTags', 'MycomponentTableElement', array('typeAlias' => 'com_mycomponent.element'));
//$this->_observers = new JObserverUpdater($this); JObserverMapper::attachAllObservers($this); // failed with or without this line
}
I added the tag field in the edit template, and it worked fine-- but when I save an object I get the following error:
Save failed with the following error: Unknown column 'tagsHelper' in 'field list'
What am I missing? There's no other steps (besides front-end steps!) that are mentioned. It seems like I need to modify the model but that info is not applicable.
Thanks
"This Page Needs Copy Editing" and it's really true!
I also follow initial steps as described in page
Register a 'Content type' for the extension view(s)
Add 'Observer methods' to the extension table class(es)
Add 'Tag fields' to the extension edit forms
But to make field tag works on custom extensions I need to explicit set form field value in view file of backend:
$tagsHelper = new JHelperTags;
$this->form= $this->get('Form');
$this->form->setValue('tags', null, $tagsHelper->getTagIds( $this->item->id, 'com_custom.viewname') );
in this way on edit page all seems to work correctly.. surely exist better and more clean method, but until doc page will not be updated, this can help someone!
1- Add tag field to your xml form file or edit template file
2- Modify #__content_types table file:
function __construct(&$db)
{
parent::__construct('#__ir_products', 'id', $db);
JTableObserverTags::createObserver($this, array('typeAlias' => 'com_itemreview.product'));
}
3- Modify model file getItem function:
public function getItem($pk = null)
{
$item = parent::getItem($pk);
if (!empty($item->id))
{
$item->tags = new JHelperTags;
$item->tags->getTagIds($item->id, 'com_yourcomponent.yourmodel');
}
return $item;
}
I am building a Joomla 2.5 component and have a bit of trouble getting the Delete button to function properly. Here is a sample code from the view.html.php file:
if ($canDo->get('core.delete'))
{
JToolBarHelper::deleteList('You Really Wanna Delete that', mycomponentname.delete, 'JTOOLBAR_DELETE');
When I select an item from a dropdown list and click to delete I get the following pop-up:
You Really Wanna Delete that
The problem with this is when I click the option to verify the deletion from the pop-up I am redirected to a 500 error message and the item is not deleted.
Now when I review the Joomla documentation here:
http://docs.joomla.org/JToolBarHelper
I see that JToolBarHelper is defined in administrator/includes/toolbar.php. So I went for a visit over to review the deleteList info there. I see the following code:
public static function deleteList($msg = '', $task = 'remove', $alt = 'JTOOLBAR_DELETE')
{
$bar = JToolBar::getInstance('toolbar');
// Add a delete button.
if ($msg) {
$bar->appendButton('Confirm', $msg, 'delete', $alt, $task, true);
} else {
$bar->appendButton('Standard', 'delete', $alt, $task, true);
}
}
So I have attempted to adjust my script by changing the second parameter $task = 'remove' to read as remove rather than mycomponentname.delete as follows:
JToolBarHelper::deleteList('You Really Wanna Delete that', 'remove', 'JTOOLBAR_DELETE');
This will eliminate the 500 error, but the item is not removed. What am I missing here? My guess is that it has something to do with improperly configuring the mycomponentname.delete function.
PS- I should add that the 500 error states:
Layout default not found
There is only one problem you have. You don't need to put the component name on to the button task. You need to put controller name instead of component name.
if ($canDo->get('core.delete'))
{
JToolBarHelper::deleteList('You Really Wanna Delete that', 'controllerName.delete', 'JTOOLBAR_DELETE');
}
For example :
JToolBarHelper::deleteList('delete', 'hellos.delete','JTOOLBAR_DELETE');
Hope this helps you.
I am trying a small ajax application whereby I only want to return a hello world string from my controller action.
it is returning the Hello world but along with this, it is also returning my template file..
I tried to disable it the templating using the following code in the action of my controlelr
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender( true );
but this returns me this error
SCREAM: Error suppression ignored for
( ! ) Notice: Undefined property: Survey\Controller\SurveyController::$_helper in C:\wamp\www\zend\module\Survey\src\Survey\Controller\SurveyController.php on line 55
SCREAM: Error suppression ignored for
( ! ) Fatal error: Call to a member function layout() on a non-object in C:\wamp\www\zend\module\Survey\src\Survey\Controller\SurveyController.php on line 55
Call Stack
How do I fix this ?
EDIT
I modifed the controller such that it looks like this
public function registerAction()
{
$result = new JsonModel(array(
'some_parameter' => 'some value',
'success'=>true,
));
return( $result );
}
Added strategies in the module..module.config in module appl directory
'strategies' => array(
'ViewJsonStrategy',
),
Still, in the ajax response I get the template being returned
Here's a solid example:
http://akrabat.com/zend-framework-2/returning-json-from-a-zf2-controller-action/
You should be using JsonMoodels to send back a Json Response.
i use this in my controller:
$view = new ViewModel(array('form'=>$my_form));
//disable layout if request by ajax
$view->setTerminal($request->isXmlHttpRequest());
$view->setTemplate('path/to/phtml');
return $view;
The user wanted to know how to get just the html back, not json as Andrews reply offers.
I also wanted the html returned so i could use it with jquery qtip plugin and this is how i did it.
I also had to make the page degrade gracefully in case javascript failed, e.g. the page output should render properly in the layout template.
/**
* Tourist Summary action
*
* #return ViewModel
*/
public function touristSummaryAction()
{
// Get the Id
$id = $this->params()->fromRoute('id', '');
// Get the data from somewhere
$data = array() ;
// Get the html from the phtml
$view = new ViewModel(
array(
'id' => $id ,
'data' => $data ,
)
);
//disable layout if request by ajax
$view->setTerminal($this->getRequest()->isXmlHttpRequest());
return $view;
}
The most simple way to send ajax requests and handle responses is the zf2 module WasabiLib https://github.com/WasabiLib/wasabilib_zf2_skeleton_application
You only need to add "ajax_element" to the class-attribute to the element which you want to cause the ajax request. It does not matter if it is a form submit or a link or a button. Visit the examples page http://www.wasabilib.org/application/pages/examples
If your application does a lot of ajax I recommend this module.
Take a look at this module. www.wasabilib.org
Seems that you it manages ajax very well.
If you do not have a application you can use the Wasabilib Skeleton https://github.com/WasabiLib/wasabilib_zf2_skeleton_application. It comes with all necessary assets in the right place.
If you already have an application you should clone the module: https://github.com/WasabiLib/wasabilib
Minimal requirements: jQuery, ZF2
Add the module to application.config.php.
Include the wasabilib.min.js after jquery in the head of your layout.phtml
How it works
in your .phtml-file you have a form like this:
<form id="simpleForm" class="ajax_element" action="simpleFormExample" method="POST">
<input type="text" name="written_text">
<input type="submit" value="try it">
</form>
Anywhere else in your phtml you can place an element where the response is shown.
In your Controller the following method:
public function simpleFormExampleAction(){
$postArray = $this->getRequest()->getPost();
$input = $postArray['written_text'];
$response = new Response(new InnerHtml("#element_simple_form","Server Response: ".$input));
return $this->getResponse()->setContent($response);
}
The form has a class "ajax_element" this will say the the library that the request will be done with an xmlhttp-request. It wont work if you do not give an id to the requesting element. So the form has the ID "simpleForm". The action is the "path/to/controller" just like a normal request.
In the controller action a new WasabiLib\Ajax\Response object is instanciated.
The InnerHtml class is for replace, prepend and append html or normal text to a selector.
In this case the selector is an ID "element_simple_form". The first parameter of the InnerHtml class is the selector. Make sure that you write #yourElementId or .yourClassSelector. For IDs an "#" and for class selectors "."
The second parameter is the Text you want to fill in this element.
The response object can handle a lot more responses which you can add with
$response->add($anotherResponseType);
A list of possible response types is here: http://www.wasabilib.org/application/pages/components
The module is build to handle ajax request an responses in a very simple way. Once you have understood the behavior you can handle almost every practical ajax need.
This works for me:
public function ajaxAction(){
$data = array(
'var1' => 'var1Value',
'var2' => 'var2Value',
);
$response = $this->getResponse();
$response->setStatusCode(200);
$response->setContent(json_encode($data));
$headers = $response->getHeaders();
$headers->addHeaderLine('Content-Type', 'application/json');
return $response;
}
Output:
{"var1":"var1Value","var2":"var2Value"}
I have my general validation messages in application/messages/validation.php and I need a custom message when I'm validating the 'password' field for my User model. This is my initial code:
try
{
ORM::factory('user', Auth::instance()->get_user())->update_user($values);
}
catch (ORM_Validation_Exception $e)
{
$errors = Arr::merge($errors, $e->errors(TRUE));
if (Arr::get($errors, '_external'))
{
$errors = Arr::merge($errors, Arr::get($errors, '_external'));
unset($errors['_external']);
}
}
And I tried: $e->errors(''), $e->errors(), copying application/messages/validation.php to application/messages/user.php, putting 'password' => array('regex' => 'message') inside of those files, I tried mixing many possibilities of all this. I read the source code for the exception class, but I can't understand what's wrong. According to this post, it can be done, but didn't worked for me that way.
I appreciate help. Thanks!
I think there is a bug in ORM_Validation_Exception->generate_errors(). What you are trying to do should be as simple as calling $e->errors('validation'), and messages would come from application/validation/user.php (it appends the ORM model alias).
I haven't reported it yet, but I think this bug report touches on it anyways. Hopefully it gets fixed.
In modules/orm/classes/kohana/orm/validation/exception.php, change line 153 to $errors[$key] = $this->generate_errors($alias, $object, $directory, $translate);
Hope this helps
If there's a validation function you could try this in APPPATH/messages/validation.php.
return array(
'password' => 'your password text' // this way it will always be replaced
'Model_User::password' => 'your custom password message' // And here just for the Model_User
);
Helllo,
Recently I upgraded to 6.2 GA from 6.1.4 via the upgrade patch.
Even since then I'm unable to create anything that has direct relation with Date & Time, namely, Call Logs, Meetings and Tasks.
When I do the same using a subpanel, the entry simply vanishes and is NEVER created.
When I try from one of the respective modules under Activities, I get a HTTP 500 error upon submission.
The Apache error log reveals the following:
PHP Catchable fatal error: Argument 1 passed to TimeDate::_getUserTZ() must be
an instance of User, boolean given, called in /home/crm/include/TimeDate.php on
line 849 and defined in /home/crm/include/TimeDate.php on line 259, referer:
http://mysite/index.php?module=Leads&offset=1&stamp=1307694072083825200&return_module=Leads&action=DetailView&record=xxxxxxxxxxxx
Unfortunately, this has happened to a production server and I noticed this problem only too late.
How can I fix this? Seeking your help urgently.
Thanks,
m^e
UPDATE 1
I've managed to apply a temporary patch to this and got it working...
Line 849 of TimeDate.php is part of a function that looks like:
function to_display_date_time($date, $meridiem = true, $convert_tz = true, $user = null)
{
return $this->_convert($date,
self::DB_DATETIME_FORMAT, self::$gmtTimezone, $this->get_date_time_format($user),
$convert_tz ? $this->_getUserTZ($user) : self::$gmtTimezone, true);
}
This function is in turn calling another one _getUserTZ() to which it is supposed to pass a variable of the type User. Instead it is passing null.
I used a snippet to check for empty $user and assign a value to it if needed. The code is part of another function named _getUser() found in this same file....
protected function _getUser(User $user = null)
{
if (empty($user)) {
$user = $this->user;
}
if (empty($user)) {
$user = $GLOBALS['current_user'];
}
return $user;
}
I borrowed the code from this function and pasted it inside to_display_date_time(), making it look like:
function to_display_date_time($date, $meridiem = true, $convert_tz = true, $user = null)
{
if (empty($user)) {
$user = $this->user;
}
if (empty($user)) {
$user = $GLOBALS['current_user'];
}
return $this->_convert($date,
self::DB_DATETIME_FORMAT, self::$gmtTimezone, $this->get_date_time_format($user),
$convert_tz ? $this->_getUserTZ($user) : self::$gmtTimezone, true);
}
Now Calls / Meetings are working again.. but I still wonder what's the actual fix to this issue. My way should prove to be a quick fix for anyone who needs to rectify this in a hurry.
If anyone can get to the root of the problem and a more elegant fix, I'm willing to offer a bounty.
Cheers,
m^e